Skip to content

Commit

Permalink
Move option.hidden logic to writeOption method
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemers committed May 26, 2020
1 parent 2f6de1c commit 245ef7f
Showing 1 changed file with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,6 @@ static void genOptions(PrintWriter pw, CommandSpec spec) {
IParameterRenderer parameterRenderer = spec.commandLine().getHelp().createDefaultParameterRenderer();

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();
}
}

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

Expand Down Expand Up @@ -439,12 +431,14 @@ private static void optionListGroups(List<ArgGroupSpec> groups, List<ArgGroupSpe
}

private static void writeOption(PrintWriter pw, IOptionRenderer optionRenderer, IParamLabelRenderer paramLabelRenderer, OptionSpec option) {
pw.println();
Text[][] rows = optionRenderer.render(option, paramLabelRenderer, COLOR_SCHEME);
pw.printf("%s::%n", join(", ", rows[0][1], rows[0][3]));
pw.printf(" %s%n", rows[0][4]);
for (int i = 1; i < rows.length; i++) {
pw.printf("+%n%s%n", rows[i][4]);
if (!option.hidden()) {
pw.println();
Text[][] rows = optionRenderer.render(option, paramLabelRenderer, COLOR_SCHEME);
pw.printf("%s::%n", join(", ", rows[0][1], rows[0][3]));
pw.printf(" %s%n", rows[0][4]);
for (int i = 1; i < rows.length; i++) {
pw.printf("+%n%s%n", rows[i][4]);
}
}
}

Expand Down Expand Up @@ -492,7 +486,7 @@ static void genPositionalArgs(PrintWriter pw, CommandSpec spec) {

static void genCommands(PrintWriter pw, CommandSpec spec) {

// remove hidden subcommands
// remove hidden subcommands before tags are added
Map<String, CommandLine> subCommands = new LinkedHashMap<String, CommandLine>(spec.subcommands());
for (Iterator<Map.Entry<String, CommandLine>> iter = subCommands.entrySet().iterator(); iter.hasNext();) {
if (iter.next().getValue().getCommandSpec().usageMessage().hidden()) {
Expand Down

0 comments on commit 245ef7f

Please sign in to comment.