Skip to content
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

Update option rendering (fixes #1886) #1896

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -501,30 +501,27 @@ static void genOptions(PrintWriter pw, CommandSpec spec) {

List<ArgGroupSpec> groups = optionListGroups(spec);
for (ArgGroupSpec group : groups) { options.removeAll(group.allOptionsNested()); }

if (options.isEmpty() && !spec.usageMessage().showEndOfOptionsDelimiterInUsageHelp()) {
pw.printf("// tag::picocli-generated-man-section-options[]%n");
pw.printf("// end::picocli-generated-man-section-options[]%n");
pw.println();
return;
}
pw.printf("// tag::picocli-generated-man-section-options[]%n");
pw.printf("== Options%n");


Comparator<OptionSpec> optionSort = spec.usageMessage().sortOptions()
? new SortByShortestOptionNameAlphabetically()
: createOrderComparatorIfNecessary(spec.options());
if (optionSort != null) {
Collections.sort(options, optionSort); // default: sort options ABC
}
for (OptionSpec option : options) {
writeOption(pw, optionRenderer, paramLabelRenderer, option);
}

pw.printf("// tag::picocli-generated-man-section-options[]%n");
if (!options.isEmpty()) {
pw.printf("== Options%n");

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);
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
Expand Down Expand Up @@ -552,6 +549,7 @@ static void genOptions(PrintWriter pw, CommandSpec spec) {
pw.println();
}


/** Returns the list of {@code ArgGroupSpec}s with a non-{@code null} heading. */
private static List<ArgGroupSpec> optionListGroups(CommandSpec commandSpec) {
List<ArgGroupSpec> result = new ArrayList<ArgGroupSpec>();
Expand Down