Skip to content

Commit 768c810

Browse files
omerrbbulutOmer Bulutpre-commit-ci[bot]
authored
docs: clarify prefix_command overload behavior (#1310)
## Summary Clarify the documentation for `prefix_command` overloads. This updates the README and API comments to make the behavior of `prefix_command(bool)` more explicit and to distinguish it from `prefix_command(CLI::PrefixCommandMode)`. In particular: - documents that `prefix_command(true)` maps to `PrefixCommandMode::On` - documents that `prefix_command(false)` maps to `PrefixCommandMode::Off` - clarifies the `SeparatorOnly` behavior in the README - improves the inline API comments for both overloads Closes #1052 --------- Co-authored-by: Omer Bulut <omer.bulut@asisguard.com.tr> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1946b74 commit 768c810

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,14 +1149,17 @@ option_groups. These are:
11491149
- `.prefix_command()`: Like `allow_extras`, but stop processing immediately on
11501150
the first unrecognized item. All subsequent arguments are placed in the
11511151
remaining_arg list. It is ideal for allowing your app or subcommand to be a
1152-
"prefix" to calling another app. Can be called with a `bool` value to turn on
1153-
or off
1154-
- `.prefix_command(CLI::PrefixCommandMode)`: 🆕 specify the prefix_command mode
1155-
to use. `PrefixCommandMode::on` and `PrefixCommandMode::off` are the same as
1156-
`prefix_command(true)` or `prefix_command(false)`. Calling with
1157-
`PrefixCommandMode::separator_only` will only trigger prefix command mode by
1158-
the use of the subcommand separator `--` other unrecognized arguments would be
1159-
considered an error depending on whether `allow_extras` was set or not.
1152+
"prefix" to calling another app.
1153+
- `.prefix_command(bool)`: Enable or disable prefix command mode.
1154+
`prefix_command(true)` is equivalent to
1155+
`prefix_command(CLI::PrefixCommandMode::On)`, and `prefix_command(false)` is
1156+
equivalent to `prefix_command(CLI::PrefixCommandMode::Off)`.
1157+
- `.prefix_command(CLI::PrefixCommandMode)`: Specify the prefix command mode
1158+
directly. `PrefixCommandMode::On` and `PrefixCommandMode::Off` are the same as
1159+
`prefix_command(true)` and `prefix_command(false)`. Calling with
1160+
`PrefixCommandMode::SeparatorOnly` will only trigger prefix command mode with
1161+
the subcommand separator `--`; other unrecognized arguments are considered an
1162+
error unless `allow_extras` is enabled.
11601163
- `.usage(message)`: Replace text to appear at the start of the help string
11611164
after description.
11621165
- `.usage(std::string())`: Set a callback to generate a string that will appear

include/CLI/App.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,15 +500,15 @@ class App {
500500
return this;
501501
}
502502

503-
/// Do not parse anything after the first unrecognized option (if true) all remaining arguments are stored in
504-
/// remaining args
503+
/// Enable or disable prefix command mode. If enabled, parsing stops at the
504+
/// first unrecognized option and all remaining arguments are stored in
505+
/// remaining args.
505506
App *prefix_command(bool is_prefix = true) {
506507
prefix_command_ = is_prefix ? PrefixCommandMode::On : PrefixCommandMode::Off;
507508
return this;
508509
}
509510

510-
/// Do not parse anything after the first unrecognized option (if true) all remaining arguments are stored in
511-
/// remaining args
511+
/// Set the prefix command mode directly.
512512
App *prefix_command(PrefixCommandMode mode) {
513513
prefix_command_ = mode;
514514
return this;

0 commit comments

Comments
 (0)