diff --git a/src/help-generator_.toit b/src/help-generator_.toit index 76d94da..b39ee05 100644 --- a/src/help-generator_.toit +++ b/src/help-generator_.toit @@ -270,9 +270,6 @@ class HelpGenerator: build-options_ --title/string options/List --add-help/bool=false --rest/bool=false -> none: if options.is-empty and not add-help: return - ensure-vertical-space_ - writeln_ "$title:" - if add-help: has-help-flag := false has-short-help-flag := false @@ -329,6 +326,12 @@ class HelpGenerator: options-type-defaults-and-help.add [option-str, help-str] + if options-type-defaults-and-help.is-empty: + // All options were hidden. + return + + ensure-vertical-space_ + writeln_ "$title:" write-table_ options-type-defaults-and-help --indentation=2 /** diff --git a/tests/help_test.toit b/tests/help_test.toit index a0d7977..0213d43 100644 --- a/tests/help_test.toit +++ b/tests/help_test.toit @@ -585,6 +585,22 @@ test-options: expect-equals sub-local-expected sub-local-actual expect-equals sub-global-expected sub-global-actual + // When the global options are hidden, they are not shown. + cmd = cli.Command "root" + --options=[ + cli.OptionInt "option1" --help="Option 1." --default=42 --hidden, + ] + + sub = cli.Command "sub" + --options=[ + cli.OptionInt "option_sub1" --help="Option 1." --default=42, + ] + --run=:: unreachable + cmd.add sub + + sub-global-actual = build-global-options.call [cmd, sub] + expect-equals "" sub-global-actual + cmd = cli.Command "root" --options=[ cli.OptionInt "option1" --short-name="h" --help="Option 1." --default=42,