Skip to content

Commit

Permalink
Update option rendering (fixes #1886)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden authored and remkop committed Dec 20, 2022
1 parent fa994b2 commit fc8aa03
Showing 1 changed file with 18 additions and 20 deletions.
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

0 comments on commit fc8aa03

Please sign in to comment.