-
Notifications
You must be signed in to change notification settings - Fork 425
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
AsciiDoc generator doesn't output any options if all options are in ArgGroups #1886
Labels
Milestone
Comments
For reference, the following implementation of static void genOptions(PrintWriter pw, CommandSpec spec) {
List<OptionSpec> options = new ArrayList<OptionSpec>(spec.options()); // options are stored in order of declaration
// remove hidden options
for (Iterator<OptionSpec> iter = options.iterator(); iter.hasNext();) {
if (iter.next().hidden()) { iter.remove(); }
}
IOptionRenderer optionRenderer = spec.commandLine().getHelp().createDefaultOptionRenderer();
IParamLabelRenderer paramLabelRenderer = spec.commandLine().getHelp().createDefaultParamLabelRenderer();
IParameterRenderer parameterRenderer = spec.commandLine().getHelp().createDefaultParameterRenderer();
List<ArgGroupSpec> groups = optionListGroups(spec);
for (ArgGroupSpec group : groups) { options.removeAll(group.allOptionsNested()); }
Comparator<OptionSpec> optionSort = spec.usageMessage().sortOptions()
? new SortByShortestOptionNameAlphabetically()
: createOrderComparatorIfNecessary(spec.options());
pw.printf("// tag::picocli-generated-man-section-options[]%n");
if (!options.isEmpty()) {
pw.printf("== Options%n");
if (optionSort != null) {
Collections.sort(options, optionSort); // default: sort options ABC
}
for (OptionSpec option : options) {
writeOption(pw, optionRenderer, paramLabelRenderer, option);
}
if (spec.usageMessage().showEndOfOptionsDelimiterInUsageHelp()) {
CommandLine cmd = new CommandLine(spec).setColorScheme(COLOR_SCHEME);
CommandLine.Help help = cmd.getHelp();
writeEndOfOptions(pw, optionRenderer, paramLabelRenderer, help.END_OF_OPTIONS_OPTION);
}
}
// now create a custom option section for each arg group that has a heading
Collections.sort(groups, new SortByOrder<ArgGroupSpec>());
for (ArgGroupSpec group : groups) {
pw.println();
String heading = makeHeading(group.heading(), "Options Group");
pw.printf("== %s%n", COLOR_SCHEME.text(heading));
for (PositionalParamSpec positional : group.allPositionalParametersNested()) {
if (!positional.hidden()) {
writePositional(pw, positional, parameterRenderer, paramLabelRenderer);
}
}
List<OptionSpec> groupOptions = new ArrayList<OptionSpec>(group.allOptionsNested());
if (optionSort != null) {
Collections.sort(groupOptions, optionSort);
}
for (OptionSpec option : groupOptions) {
writeOption(pw, optionRenderer, paramLabelRenderer, option);
}
}
pw.println();
pw.printf("// end::picocli-generated-man-section-options[]%n");
pw.println();
} |
Thank you for letting me know! |
remkop
added
type: bug 🐛
theme: codegen
An issue or change related to the picocli-codegen module
labels
Dec 16, 2022
That looks good at first glance. @rsenden thanks for the analysis and solution! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
The AsciiDoc generator doesn't output any options for commands that have all their options defined in ArgGroups. Culprit is this piece of code:
If all options are contained in ArgGroups, then
options
will be empty, and due to thereturn
statement in the code above, the code to output ArgGroup options is skipped:I'll look at submitting a PR, but any suggestions on how to best fix this are welcome.
The text was updated successfully, but these errors were encountered: