From 4e1467447e154b6c22efeb8215015f68b7c0667a Mon Sep 17 00:00:00 2001 From: Brian Demers Date: Wed, 27 May 2020 20:05:08 -0400 Subject: [PATCH] Moving option filtering logic above header tag in ManPageGen --- .../docgen/manpage/ManPageGenerator.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/picocli-codegen/src/main/java/picocli/codegen/docgen/manpage/ManPageGenerator.java b/picocli-codegen/src/main/java/picocli/codegen/docgen/manpage/ManPageGenerator.java index 1ada3481d..9c3d68f2f 100644 --- a/picocli-codegen/src/main/java/picocli/codegen/docgen/manpage/ManPageGenerator.java +++ b/picocli-codegen/src/main/java/picocli/codegen/docgen/manpage/ManPageGenerator.java @@ -373,28 +373,26 @@ private static String headerDescriptionString(CommandSpec spec) { } static void genOptions(PrintWriter pw, CommandSpec spec) { - if (spec.options().isEmpty()) { - return; - } - pw.printf("// tag::picocli-generated-man-section-options[]%n"); - pw.printf("== Options%n"); - - IOptionRenderer optionRenderer = spec.commandLine().getHelp().createDefaultOptionRenderer(); - IParamLabelRenderer paramLabelRenderer = spec.commandLine().getHelp().createDefaultParamLabelRenderer(); - IParameterRenderer parameterRenderer = spec.commandLine().getHelp().createDefaultParameterRenderer(); - List options = new ArrayList(spec.options()); // options are stored in order of declaration // remove hidden options for (Iterator iter = options.iterator(); iter.hasNext();) { - if (iter.next().hidden()) { - iter.remove(); - } + 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 groups = optionListGroups(spec); for (ArgGroupSpec group : groups) { options.removeAll(group.options()); } + if (spec.options().isEmpty()) { + return; + } + pw.printf("// tag::picocli-generated-man-section-options[]%n"); + pw.printf("== Options%n"); + Comparator optionSort = spec.usageMessage().sortOptions() ? new SortByShortestOptionNameAlphabetically() : createOrderComparatorIfNecessary(spec.options());