-
Hi, With an interactive shell where I have @command methods, is there something built-in to get the number of parameters actually passed in? Manually, I can check each param for non-null and add to a counter, but this seems like something picocli could take care of. For example,
I need it to not affect how the method is called i.e. adding another parameter. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You may be able to get a class MyClass {
@Spec CommandSpec spec;
@Command(name = "subcommand", description = "Subcommand")
public void subcommand(
@Parameters(arity = "1", description = "Parameter 1") String parameter1,
@Parameters(arity = "0..1", description = "Optional parameter 2") String parameter2,
@Parameters(arity = "0..1", description = "Optional parameter 3") String parameter3,
@Parameters(arity = "0..1", description = "Optional parameter 4") String parameter4) {
ParseResult pr = spec.subcommands().get("subcommand").getParseResult();
int parameterCount = pr.expandedArgs().size();
if (parameterCount > 3) {
// do something
}
} |
Beta Was this translation helpful? Give feedback.
You may be able to get a
ParseResult
instance like this: