Skip to content

Add CommandGroup for commands with both subcommands and a default fallback#98

Merged
floitsch merged 3 commits intomainfrom
floitsch/toit-completion
Apr 9, 2026
Merged

Add CommandGroup for commands with both subcommands and a default fallback#98
floitsch merged 3 commits intomainfrom
floitsch/toit-completion

Conversation

@floitsch
Copy link
Copy Markdown
Member

@floitsch floitsch commented Apr 9, 2026

CommandGroup holds two sibling Command objects: a default (with --run) and a commands (with subcommands). When arguments match a named subcommand, dispatch goes there; otherwise the default command handles them. Each command has independent options — no inheritance between them.

This enables CLIs like toit to accept both toit run foo.toit (explicit subcommand) and toit foo.toit (default fallback) with separate options for each path.

Also adds --completion-as-flag parameter to Command.run for explicit control over whether completion uses a subcommand or flag.

…lback

CommandGroup holds two sibling Command objects: a default (with --run)
and a commands (with subcommands). When arguments match a named
subcommand, dispatch goes there; otherwise the default command handles
them. Each command has independent options — no inheritance between them.

This enables CLIs like `toit` to accept both `toit run foo.toit`
(explicit subcommand) and `toit foo.toit` (default fallback) with
separate options for each path.

Also adds --completion-as-flag parameter to Command.run for explicit
control over whether completion uses a subcommand or flag.
@floitsch floitsch requested a review from kasperl April 9, 2026 20:52
@floitsch
Copy link
Copy Markdown
Member Author

floitsch commented Apr 9, 2026

TBR.

@floitsch floitsch merged commit 478978d into main Apr 9, 2026
7 checks passed
@floitsch floitsch deleted the floitsch/toit-completion branch April 9, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant