From 02a1dc1a8ce06359c0fd949ce05d2561025d8bde Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 16 Sep 2023 17:40:35 -0400 Subject: [PATCH] rename help disabler to SUBCOMMAND action type --- include/blt/parse/argparse.h | 12 +++--------- libraries/parallel-hashmap | 2 +- src/blt/parse/argparse.cpp | 16 +++++++++------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/include/blt/parse/argparse.h b/include/blt/parse/argparse.h index 687c42c..a8f7efa 100755 --- a/include/blt/parse/argparse.h +++ b/include/blt/parse/argparse.h @@ -34,7 +34,8 @@ namespace blt COUNT, HELP, VERSION, - EXTEND + EXTEND, + SUBCOMMAND }; class arg_vector_t @@ -129,7 +130,6 @@ namespace blt std::string a_version{}; std::string a_metavar{}; bool a_required = true; - bool a_disable_help = false; }; class arg_builder @@ -182,12 +182,6 @@ namespace blt return *this; } - inline arg_builder& disableHelp() - { - properties.a_disable_help = true; - return *this; - } - inline arg_builder& setHelp(const std::string& help) { properties.a_help = help; @@ -342,7 +336,7 @@ namespace blt void handleFlag(arg_tokenizer& tokenizer, const std::string& flag, const arg_properties_t* properties); - std::string getProgramName() const + [[nodiscard]] std::string getProgramName() const { return use_full_name ? loaded_args.program_name : filename(loaded_args.program_name); } diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap index 77cab81..93201da 160000 --- a/libraries/parallel-hashmap +++ b/libraries/parallel-hashmap @@ -1 +1 @@ -Subproject commit 77cab8192a879e5d27188f97e8f2080dd7e36ca8 +Subproject commit 93201da2ba5a6aba0a6e57ada64973555629b3e3 diff --git a/src/blt/parse/argparse.cpp b/src/blt/parse/argparse.cpp index b93b603..c45415e 100755 --- a/src/blt/parse/argparse.cpp +++ b/src/blt/parse/argparse.cpp @@ -82,7 +82,8 @@ namespace blt return flag; } - std::string arg_vector_t::getArgName() const { + std::string arg_vector_t::getArgName() const + { if (name.empty()) return getFirstFullFlag(); return name; @@ -252,8 +253,6 @@ namespace blt if (!found) { const auto& arg_property = user_args.name_associations[index]; - if (arg_property->a_disable_help) - help_disabled = true; loaded_args.data[arg_property->a_dest] = tokenizer.get(); loaded_args.found_args.insert(arg_property->a_dest); } @@ -320,9 +319,6 @@ namespace blt loaded_args.found_args.insert(dest); - if (properties->a_disable_help) - help_disabled = true; - switch (properties->a_action) { case arg_action_t::HELP: @@ -363,6 +359,11 @@ namespace blt data = get(data) + 1; break; } + case arg_action_t::SUBCOMMAND: + { + help_disabled = true; + break; + } case arg_action_t::EXTEND: { @@ -464,7 +465,7 @@ namespace blt if (takesArgs(named_arg) && !loaded_args.contains(named_arg->a_dest)) { printUsage(); - std::cout << "postional argument '" << named_arg->a_flags.name << "' expected " << named_arg->a_nargs.args << " argument" + std::cout << "positional argument '" << named_arg->a_flags.name << "' expected " << named_arg->a_nargs.args << " argument" << (named_arg->a_nargs.args > 1 ? "s!" : "!") << std::endl; std::exit(0); } @@ -485,6 +486,7 @@ namespace blt case arg_action_t::COUNT: case arg_action_t::HELP: case arg_action_t::VERSION: + case arg_action_t::SUBCOMMAND: return false; case arg_action_t::STORE: case arg_action_t::APPEND: