Subcommand fallthrough (#1073)

Add modifier for subcommands to restrict subcommands falling through to
parent.
This will resolve #1022

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Philip Top
2024-10-09 04:46:45 -07:00
committed by GitHub
parent 79b1430019
commit ca66827263
8 changed files with 74 additions and 24 deletions

View File

@@ -132,7 +132,21 @@ gitbook:code $ ./my_program my_model_1 --model_flag --shared_flag
```
Here, `--shared_flag` was set on the main app, and on the command line it "falls
through" `my_model_1` to match on the main app.
through" `my_model_1` to match on the main app. This is set through
`->fallthrough()` on a subcommand.
#### Subcommand fallthrough
Subcommand fallthrough allows additional subcommands to be triggered after the
first subcommand. By default subcommand fallthrough is enabled, but it can be
turned off through `->subcommand_fallthrough(false)` on a subcommand. This will
prevent additional subcommands at the same inheritance level from triggering,
the strings would then be treated as positional values. As a technical note if
fallthrough is enabled but subcommand fallthrough disabled (this is not the
default in both cases), then subcommands on grandparents can still be triggered
from the grandchild subcommand, unless subcommand fallthrough is also disabled
on the parent. This is an unusual circumstance but may arise in some very
particular situations.
### Prefix command