diff --git a/packages/CLI11/.gitrepo b/packages/CLI11/.gitrepo index 96c408126ab71f57466b1bfba721bdb7f67d4bda..529dab07528697a59e5c2dbdd31b500d3742757f 100644 --- a/packages/CLI11/.gitrepo +++ b/packages/CLI11/.gitrepo @@ -6,6 +6,7 @@ [subrepo] remote = git@github.com:CLIUtils/CLI11.git branch = master - commit = da901cca542612a133efcb04e8e78080186991e4 - parent = 4348958e3bface85aedc9e8a5638f38790834cd5 - cmdver = 0.3.1 + commit = b683f4ed96b2da6c4992e63f49482b8c9cd00968 + parent = b9ec061afdb0aefa3489d9beaecf99cd608f3d15 + cmdver = 0.4.0 + method = merge diff --git a/packages/CLI11/examples/CMakeLists.txt b/packages/CLI11/examples/CMakeLists.txt index ef17d2c2f8351f1771161281f503ea7d65c0a1c1..56a58e87c1867193dba7773b517926a6d9db2408 100644 --- a/packages/CLI11/examples/CMakeLists.txt +++ b/packages/CLI11/examples/CMakeLists.txt @@ -128,3 +128,7 @@ set_property(TEST subcom_in_files PROPERTY PASS_REGULAR_EXPRESSION add_cli_exe(formatter formatter.cpp) add_cli_exe(nested nested.cpp) + +add_cli_exe(subcom_help subcom_help.cpp) +add_test(NAME subcom_help_normal COMMAND subcom_help sub --help) +add_test(NAME subcom_help_reversed COMMAND subcom_help --help sub) diff --git a/packages/CLI11/examples/subcom_help.cpp b/packages/CLI11/examples/subcom_help.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d8997d9d4f11eed94e0793de9ee23e1ee54d28d --- /dev/null +++ b/packages/CLI11/examples/subcom_help.cpp @@ -0,0 +1,14 @@ +#include <CLI/CLI.hpp> +#include <iostream> + +int main(int argc, char *argv[]) { + CLI::App cli_global{"Demo app"}; + auto &cli_sub = *cli_global.add_subcommand("sub", "Some subcommand"); + std::string sub_arg; + cli_sub.add_option("sub_arg", sub_arg, "Argument for subcommand")->required(); + CLI11_PARSE(cli_global, argc, argv); + if(cli_sub) { + std::cout << "Got: " << sub_arg << std::endl; + } + return 0; +} diff --git a/packages/CLI11/extern/json b/packages/CLI11/extern/json index d2dd27dc3b8472dbaa7d66f83619b3ebcd9185fe..f1768a540a7b7c5cc30cdcd6be9e9ef91083719b 160000 --- a/packages/CLI11/extern/json +++ b/packages/CLI11/extern/json @@ -1 +1 @@ -Subproject commit d2dd27dc3b8472dbaa7d66f83619b3ebcd9185fe +Subproject commit f1768a540a7b7c5cc30cdcd6be9e9ef91083719b diff --git a/packages/CLI11/include/CLI/App.hpp b/packages/CLI11/include/CLI/App.hpp index eebab3bfa0f6809b85b514799150eb6d77bb726f..99bc977421956edd0d16ce14b91b5f771ede82b6 100644 --- a/packages/CLI11/include/CLI/App.hpp +++ b/packages/CLI11/include/CLI/App.hpp @@ -1341,6 +1341,10 @@ class App { // Verify required options for(const Option_p &opt : options_) { + // Exit if a help flag was passed (requirements not required in that case) + if(_any_help_flag()) + break; + // Required or partially filled if(opt->get_required() || opt->count() != 0) { // Make sure enough -N arguments parsed (+N is already handled in parsing function) @@ -1379,6 +1383,21 @@ class App { } } + /// Return True if a help flag detected (checks all parents) + bool _any_help_flag() const { + bool result = false; + const Option *help_ptr = get_help_ptr(); + const Option *help_all_ptr = get_help_all_ptr(); + if(help_ptr != nullptr && help_ptr->count() > 0) + result = true; + if(help_all_ptr != nullptr && help_all_ptr->count() > 0) + result = true; + if(parent_ != nullptr) + return result || parent_->_any_help_flag(); + else + return result; + } + /// Parse one config param, return false if not found in any subcommand, remove if it is /// /// If this has more than one dot.separated.name, go into the subcommand matching it @@ -1395,7 +1414,6 @@ class App { if(level < item.parents.size()) { App *subcom; try { - std::cout << item.parents.at(level) << std::endl; subcom = get_subcommand(item.parents.at(level)); } catch(const OptionNotFound &) { return false;