-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make COMMAND subcommand parameter required? #625
Comments
I am using annotations btw. |
A similar request was just raised in #624. I don't object to doing this, but we need to flush out the semantics and annotation syntax. Are we looking for something like this? @Command(subcommands = {A.class, B.class}, subcommandRequired = true)
class App {} Any ideas for a better name? |
In my case, this is what I search for. This name explain it's meaning by itself so it works. |
That sounds good to me too. |
A more generic solution is related to #454 (Repeatable Subcommands): a command could have a This multiplicity indicates how many times the subcommand ca be specified. The default would be If a subcommand can be specified multiple times, it should be defined something like the below:
|
Command multiplicity won't fit our need I think. We need a way to tell picocli that a command require a subcommand and we can't make it with multiplicity.
Here
And here |
Yes, you’re right. Multiplicity is not the answer here. |
I started to work on this. To clarify the requirements: Automatic Error HandlingIf a command defined as TBD TBD Usage Help SynopsisBoth the abbreviated synopsis and the automatic synopsis of a command with subcommands currently show the subcommands as TBD @Command(name = "fs", subcommandRequired = true, synopsisSubcommandLabel = "(list | add | delete)") and @Command(name = "fs", subcommandRequired = false, synopsisSubcommandLabel = "[list | add | delete]") TBD2 @Command(name = "fs", subcommandRequired = false, synopsisSubcommandLabel = "[${SUBCOMMANDS}]") There is still some hard-coding in the above, since there is no way to specify the separator ( Feedback welcome! |
Analysis, revisitedThe above analysis makes me think that the idea of adding a I'm beginning to think we don't really need a The only value it adds is the error handling, which is fairly trivial to implement anyway: @Command(name = "top", subcommands = Sub.class, synopsisSubcommandLabel = "COMMAND")
static class TopCommandWithRequiredSubcommand implements Runnable {
@Spec CommandSpec spec;
public void run() {
throw new ParameterException(spec.commandLine(), "Missing required subcommand");
}
} Thoughts? |
…ation of the subcommands part of the synopsis: by default this is `[COMMAND]`.
@sebthom @AlcaYezz I went ahead and implemented the Can you review and give feedback? |
I like this solution better than the original |
FYI, 4.0.0-beta-2 has been released with support for |
Hi, I have a question regarding this required subcommand. I read your comments but I am afraid I still do not fully understand how to use it :P Let' say I have one main command defined like this: How can I make LoadCommand subcommand required and other subcommands optional? I would appreciate your help :) |
@r2mzes Would you mind raising a separate ticket for this? Sometimes questions result in changes to picocli and then it’s good to have the full history in a single ticket. |
Actually this was exactly the reason why I posted here :D but sure, no problem :P |
Currently when I have a main command with subcommands, the help is rendered like this:
Where the brackets around [COMMAND] signal that the command parameter is optional.
I need it to be required, i.e. the call()/run() method of the main command actually is not used.
Right now I throw an exception inside the call()/run() method and advice the user to specify a command. However I would prefer this to be a declarative setting, also I would like to see the usage help signal the COMMAND parameter as required.
The text was updated successfully, but these errors were encountered: