diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a1cae53..6c52c4f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1027,8 +1027,9 @@ functionality for tricky parsing situations. - Added `app.parse_order()` with original parse order ([#13](https://github.com/CLIUtils/CLI11/issues/13), [#16](https://github.com/CLIUtils/CLI11/pull/16)) -- Added `prefix_command()`, which is like `allow_extras` but instantly stops and - returns. ([#8](https://github.com/CLIUtils/CLI11/issues/8), +- Added `prefix_command()`, which is like `allow_extras` but ceases processing + and puts all remaining args in the remaining_args structure. + [#8](https://github.com/CLIUtils/CLI11/issues/8), [#17](https://github.com/CLIUtils/CLI11/pull/17)) - Removed Windows warning ([#10](https://github.com/CLIUtils/CLI11/issues/10), [#20](https://github.com/CLIUtils/CLI11/pull/20)) diff --git a/README.md b/README.md index cf142026..73c4ff34 100644 --- a/README.md +++ b/README.md @@ -1010,8 +1010,9 @@ option_groups. These are: - `.allow_extras()`: Do not throw an error if extra arguments are left over. - `.positionals_at_end()`: Specify that positional arguments occur as the last arguments and throw an error if an unexpected positional is encountered. -- `.prefix_command()`: Like `allow_extras`, but stop immediately on the first - unrecognized item. It is ideal for allowing your app or subcommand to be a +- `.prefix_command()`: Like `allow_extras`, but stop processing immediately on + the first unrecognized item. All subsequent arguments are placed in the + remaining_arg list. It is ideal for allowing your app or subcommand to be a "prefix" to calling another app. - `.usage(message)`: 🆕 Replace text to appear at the start of the help string after description. diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index e3fcbd52..892bd1f2 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -110,7 +110,7 @@ class App { /// if error error on an extra argument, and if capture feed it to the app config_extras_mode allow_config_extras_{config_extras_mode::ignore}; - /// If true, return immediately on an unrecognized option (implies allow_extras) INHERITABLE + /// If true, cease processing on an unrecognized option (implies allow_extras) INHERITABLE bool prefix_command_{false}; /// If set to true the name was automatically generated from the command line vs a user set name @@ -442,9 +442,10 @@ class App { return this; } - /// Do not parse anything after the first unrecognized option and return - App *prefix_command(bool allow = true) { - prefix_command_ = allow; + /// Do not parse anything after the first unrecognized option (if true) all remaining arguments are stored in + /// remaining args + App *prefix_command(bool is_prefix = true) { + prefix_command_ = is_prefix; return this; } diff --git a/include/CLI/impl/Config_inl.hpp b/include/CLI/impl/Config_inl.hpp index 24df7a75..0d372327 100644 --- a/include/CLI/impl/Config_inl.hpp +++ b/include/CLI/impl/Config_inl.hpp @@ -583,7 +583,7 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description, std::string subname = subcom->get_name(); clean_name_string(subname, keyChars); - if(subcom->get_configurable() && app->got_subcommand(subcom)) { + if(subcom->get_configurable() && (default_also || app->got_subcommand(subcom))) { if(!prefix.empty() || app->get_parent() == nullptr) { out << '[' << prefix << subname << "]\n";