Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/cli.toit
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ class Command:

If no $cli is given, the arguments are parsed for `--verbose`, `--verbosity-level` and
`--output-format` to create the appropriate UI object. If a $cli object is given,
then these arguments are ignored.
then these arguments do not change its UI.

The $add-ui-help flag is used to determine whether to include help for `--verbose`, ...
The $add-ui-help flag determines whether these UI options are accepted and included
in the help output. By default it is active if no $cli is provided.

The $completion-as-flag parameter controls whether shell completion is exposed as a
Expand Down Expand Up @@ -439,9 +439,8 @@ class Command:
if not cli:
ui := create-ui-from-args_ arguments
log.set-default (ui.logger --name=name)
if add-ui-help:
add-ui-options_
cli = Cli_ name --ui=ui --cache=null --config=null
if add-ui-help: add-ui-options_
parser := Parser_ --invoked-command=invoked-command
parser.parse this arguments: | path/Path parameters/Parameters |
invocation := Invocation.private_ cli path.commands parameters
Expand Down
20 changes: 20 additions & 0 deletions tests/command_group_options_test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ When a subcommand is found on a CommandGroup, the parser goes directly
main:
test-commands-option-accessible-from-subcommand
test-commands-option-accessible-with-value
test-ui-option-with-custom-cli

test-commands-option-accessible-from-subcommand:
sub-invoked := false
Expand Down Expand Up @@ -67,3 +68,22 @@ test-commands-option-accessible-with-value:

root.run ["--sdk-dir", "/my/sdk", "run"]
expect-equals "/my/sdk" captured-value

test-ui-option-with-custom-cli:
captured-format := null
commands-cmd := cli.Command "commands"
commands-cmd.add
cli.Command "run"
--run=:: | invocation/cli.Invocation |
captured-format = invocation["output-format"]

root := cli.CommandGroup "app"
--default=(cli.Command "default"
--rest=[cli.Option "source" --required]
--run=:: unreachable)
--commands=commands-cmd

root.run ["--output-format", "json", "run"]
--cli=(cli.Cli "app" --ui=(cli.Ui.human --level=cli.Ui.SILENT-LEVEL))
--add-ui-help
expect-equals "json" captured-format
Loading