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 just started to try out the new 4.0.0 alpha build, the new argument group feature comes in very handy for me. I came across the following issue, though:
Minimal code sample:
public class ArgGroupsTest {
public static void main(String[] args) {
CommandLine cmd = new CommandLine(new TestCommand());
cmd.parseWithHandler(new CommandLine.RunAll(), args);
}
@Command(subcommands = { TestSubCommand.class, CommandLine.HelpCommand.class }, name = "ArgGroupsTest", mixinStandardHelpOptions = true, version = "0.xx")
static class TestCommand implements Runnable {
@ArgGroup(exclusive = true, multiplicity = "1")
DataSource datasource;
static class DataSource {
@Option(names = "-a", required = true)
static boolean isA;
@Option(names = "-b", required = true)
static File dataFile;
}
@Override
public void run() {
// nothing to do here
}
}
@Command(name = "test", showDefaultValues = true)
static class TestSubCommand implements Runnable {
@Override
public void run() {
System.out.println("Subcommand called!");
}
}
}
Now, when requesting help:
$ ArgGroupsTest --help
the following message is presented on stderr:
Error: Missing required argument (specify one of these): -a, -b=<dataFile>
Usage: ArgGroupsTest (-a | -b=<dataFile>) [-hV] [COMMAND]
-a
-b=<dataFile>
-h, --help Show this help message and exit.
-V, --version Print version information and exit.
Commands:
test
help Displays help information about the specified command
Once help is requested, usage instructions should be given on stdout, I don't expect any error due to a missing required mutually exclusive option here.
The text was updated successfully, but these errors were encountered:
I found the cause. Basically, all validation should be skipped if any help is requested. Currently only some validation is skipped but not all. The validation for the arg groups is among the ones that are not skipped.
This should fix it:
Index: src/main/java/picocli/CommandLine.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/picocli/CommandLine.java (date 1554265596285)
+++ src/main/java/picocli/CommandLine.java (date 1554265596285)
@@ -8852,11 +8852,13 @@
}
} while (!argumentStack.isEmpty() && continueOnError);
- validateConstraints(argumentStack, required, initialized);
+ if (!isAnyHelpRequested()) {
+ validateConstraints(argumentStack, required, initialized);
+ }
}
private void validateConstraints(Stack<String> argumentStack, List<ArgSpec> required, Set<ArgSpec> matched) {
- if (!isAnyHelpRequested() && !required.isEmpty()) {
+ if (!required.isEmpty()) {
for (ArgSpec missing : required) {
Assert.assertTrue(missing.group() == null, "Arguments in a group are not necessarily required for the command");
if (missing.isOption()) {
I just started to try out the new 4.0.0 alpha build, the new argument group feature comes in very handy for me. I came across the following issue, though:
Minimal code sample:
Now, when requesting help:
the following message is presented on stderr:
Once help is requested, usage instructions should be given on stdout, I don't expect any error due to a missing required mutually exclusive option here.
The text was updated successfully, but these errors were encountered: