Skip to content

How to customized PropertySource on some subcommand #20

Description

@tchiotludo

I've an application with subcommands like that :

@Command(name = "topcmd", subcommands = {SubCmd1.class, SubCmd2.class}) 
class TopCommand implements Callable<Object> { 

    public static void main(String[] args) {
        PicocliRunner.execute(TopCommand.class, args); 
    }
    //...
}

I want to be able to add some PropertySource (custom configuration) for only 1 subcommands (for example SubCmd2.class will add a configuration "myapp.myconfig": "foo" only when running te command from SubCmd2).

I don't think it's possible for now ?

The only solution I see is to used this signature when init Picocli :

public static <C extends Callable<T>, T> T call(Class<C> cls, ApplicationContext ctx, String... args) {

instead of simple on PicocliRunner.call(App.class, args); in order to provide some configuration directly in ApplicationContext but this will need to parse the String[] args to determine the current command, that is not really easy and can be buggy since it's not parse by picocli.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions