-
Notifications
You must be signed in to change notification settings - Fork 418
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
Nested group outside of the section in the help #778
Comments
Hmm, yes, but is there really is a problem? The
Then the resulting usage message looks like this:
I believe this is reasonable. Do you think it should behave differently? |
I see. Actually, this does not fit my use case. What I was trying to achieve was a section in the help to specify parameters to connect to a database (like host, port and so forth) and I have some parameters that are exclusive to indicate the connection mode (ssl, ssl with full cert validation, no ssl) that should appear in the same section. |
What would you like the usage help to look like for your use case? |
Well, actually if I could include an excluded group inside of a section with other parameters that would fit the use case. As an example the output I would expect referred to the initial test of this issue would be:
|
Not sure that I follow... If your actual use case is different it may be more productive to discuss the actual use case instead of an artificial example. Would that be possible? |
I'll prefer to get stuck to artificial example. In order to resemble better my use case I'll try to adapt the example with my use case:
|
Thank you for the clarification. I need some time to think about this. |
I found a way to accomplish this with the current version of picocli: import org.junit.Test;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import static org.junit.Assert.assertEquals;
public class Issue778ArgGroupHelpSections {
@Command(name = "test-with-nested-group",
description = "Picocli section test with nested group.",
abbreviateSynopsis = true,
sortOptions = false)
public static class TestCommand {
@ArgGroup(validate = false, heading = "database%n", order = 1)
private final Database database = new Database();
private static class Database {
@Option(names = {"--host"})
private String host;
@Option(names = {"--port"})
private String port;
@Option(names = {"--database"})
private String db;
@Option(names = {"--user"})
private String user;
@Option(names = {"--password"})
private String pwd;
}
@ArgGroup(exclusive = true, heading = "", order = 2)
private final SslMode sslMode = new SslMode();
private static class SslMode {
@Option(names = {"--no-ssl"})
private boolean noSsl;
@Option(names = {"--use-ssl"})
private boolean useSsl;
@Option(names = {"--use-strict-ssl"})
private boolean useStrictSsl;
}
}
@Test
public void testUsage() {
String expected = String.format("" +
"Usage: test-with-nested-group [OPTIONS]%n" +
"Picocli section test with nested group.%n" +
"database%n" +
" --host=<host>%n" +
" --port=<port>%n" +
" --database=<db>%n" +
" --user=<user>%n" +
" --password=<pwd>%n" +
" --no-ssl%n" +
" --use-ssl%n" +
" --use-strict-ssl%n");
String actual = new CommandLine(new TestCommand())
.getUsageMessage(CommandLine.Help.Ansi.OFF);
assertEquals(expected, actual);
}
} Would that work for you? We should probably improve the documentation in this area. Suggestions or pull requests welcome! |
Looking closer, the javadoc for ArgGroup.order is wrong: it does not matter whether |
The option you mention of using the order inside |
I updated the user manual (this is live already) and the javadoc (for the next release). |
Using version 4.0.1 and 4.0.2-SNAPSHOT when a nested group is present inside another one the nested group's options are printed outside of the section in the help:
Originally posted by @teoincontatto in #776 (comment)
The text was updated successfully, but these errors were encountered: