You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building something that will execute commands dynamically, basically an app launcher that resolves app names during runtime. The command itself also has a set of options.
@Command(name = "run", description = "Run specified application.")
public int runApp(@Parameters(paramLabel = "<app>", index = "0") String app, @Parameters(index = "1..*") String[] args) {
Also, I'd like the "run" subcommand be the default, so when I type "mycmd app arg1 arg2" the above would be triggered from the generic call():
// Default is to run apps
if (params.length > 0 && weHaveApp(params[0])) {
return runApp(params[0], Arrays.copyOfRange(params, 1, params.length));
}
I'd like to use "mycmd -r run app arg1 arg2 --something" to run app with arg1 and arg2 and --something as well as with the fallback value assigned to reader (the logic behind it is "if --reader specified, use it, otherwise trigger UI related to reader selection") Right now "run" is assigned to the reader.
Is something like this possible?
The text was updated successfully, but these errors were encountered:
Thanks for raising this.
Picocli has logic to prevent other options from being assigned to the --reader option, but as of 4.0.4, it does not check for subcommands. I agree that it should check for subcommands as well.
I've pushed a fix for this to master. Can you verify?
I’m still looking at further improvements so that end users can use quoted arguments to prevent the value being interpreted as a subcommand. For example:
# invokes the run subcommand
mycmd -r run app arg1 arg2 --something
# “run” is assigned to reader option
mycmd -r “run” app arg1 arg2 --something
The above works when parser setting trimQuotes == false (the default), but currently not when trimQuotes == true, because the quotes are trimmed before the value is interpreted. I am thinking about changing this, but still considering the impact...
I'm going to leave the quoting logic alone for now.
The reported issue is fixed on master, we can look at further improving options with optional values later.
I'm building something that will execute commands dynamically, basically an app launcher that resolves app names during runtime. The command itself also has a set of options.
I have
and
Also, I'd like the "run" subcommand be the default, so when I type "mycmd app arg1 arg2" the above would be triggered from the generic
call()
:I'd like to use "mycmd -r run app arg1 arg2 --something" to run app with arg1 and arg2 and --something as well as with the fallback value assigned to reader (the logic behind it is "if --reader specified, use it, otherwise trigger UI related to reader selection") Right now "run" is assigned to the reader.
Is something like this possible?
The text was updated successfully, but these errors were encountered: