From 1e293c7dbafa98ee2b0df5136ab5d4d4c4084707 Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 16 Sep 2023 16:27:48 -0400 Subject: [PATCH] argparse update a "janky" solution has been added to the argparse module of BLT. The new update allows for the creation of "help disablers" which are basically akin to how git operates with git submodule git commit etc the primary command "git" can have flags (in the case of the tests, --no-color) while having multiple help disabling sub commands (currently graphics and blt) everything before the sub command arg will be processed as a primary command flag everything after the sub command arg will be processed by the sub command arg_parse this allows for effective namespacing of command modules TODO: - Make this as an action? - cleanup the code - use a name that makes more sense than "help disabler" --- include/blt/parse/argparse.h | 1 - libraries/parallel-hashmap | 2 +- src/blt/parse/argparse.cpp | 13 +++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/blt/parse/argparse.h b/include/blt/parse/argparse.h index bf582f4..79a56db 100755 --- a/include/blt/parse/argparse.h +++ b/include/blt/parse/argparse.h @@ -420,7 +420,6 @@ namespace blt inline void setHelpExtras(std::string str) { - addArgument(blt::arg_builder(str).setAction(blt::arg_action_t::STORE_TRUE).build()); help_inclusion = std::move(str); } diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap index 93201da..77cab81 160000 --- a/libraries/parallel-hashmap +++ b/libraries/parallel-hashmap @@ -1 +1 @@ -Subproject commit 93201da2ba5a6aba0a6e57ada64973555629b3e3 +Subproject commit 77cab8192a879e5d27188f97e8f2080dd7e36ca8 diff --git a/src/blt/parse/argparse.cpp b/src/blt/parse/argparse.cpp index 70dec5f..96db923 100755 --- a/src/blt/parse/argparse.cpp +++ b/src/blt/parse/argparse.cpp @@ -406,9 +406,22 @@ namespace blt loaded_args.program_name = tokenizer.get(); tokenizer.advance(); + if (!help_inclusion.empty()) + { + // advance the tokenizer to post grouped args allowing for flags + while (tokenizer.hasCurrent() && tokenizer.get() != help_inclusion) + tokenizer.advance(); + tokenizer.advance(); + } + size_t last_positional = 0; while (tokenizer.hasCurrent()) { + // if we find an arg which disables help (basically a grouping flag) then we should stop processing args + // TODO: rename this to be more descriptive + if (help_disabled) + break; + if (tokenizer.isFlag()) handleFlagArgument(tokenizer); else