Skip to content

Commit

Permalink
Don't show a global-options section if all options were hidden.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed Aug 9, 2024
1 parent cc4c9c9 commit 8a4bf1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/help-generator_.toit
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,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
Expand Down Expand Up @@ -340,6 +337,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

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/help_test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,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,
Expand Down

0 comments on commit 8a4bf1f

Please sign in to comment.