From f63d70305b7e15f11e33e2ac1b291e870f830bbc Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Mon, 12 Nov 2018 22:45:56 +0100 Subject: [PATCH] git subrepo pull packages/CLI11 subrepo: subdir: "packages/CLI11" merged: "b683f4ed9" upstream: origin: "git@github.com:CLIUtils/CLI11.git" branch: "master" commit: "b683f4ed9" git-subrepo: version: "0.4.0" origin: "git@github.com:ingydotnet/git-subrepo.git" commit: "5d6aba9" --- packages/CLI11/.gitrepo | 7 ++++--- packages/CLI11/examples/CMakeLists.txt | 4 ++++ packages/CLI11/examples/subcom_help.cpp | 14 ++++++++++++++ packages/CLI11/extern/json | 2 +- packages/CLI11/include/CLI/App.hpp | 20 +++++++++++++++++++- 5 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 packages/CLI11/examples/subcom_help.cpp diff --git a/packages/CLI11/.gitrepo b/packages/CLI11/.gitrepo index 96c408126..529dab075 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 ef17d2c2f..56a58e87c 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 000000000..0d8997d9d --- /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 d2dd27dc3..f1768a540 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 eebab3bfa..99bc97742 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; -- GitLab