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"
v1
Brett 2023-09-16 16:27:48 -04:00
parent 04cef480bd
commit 1e293c7dba
3 changed files with 14 additions and 2 deletions

View File

@ -420,7 +420,6 @@ namespace blt
inline void setHelpExtras(std::string str) inline void setHelpExtras(std::string str)
{ {
addArgument(blt::arg_builder(str).setAction(blt::arg_action_t::STORE_TRUE).build());
help_inclusion = std::move(str); help_inclusion = std::move(str);
} }

@ -1 +1 @@
Subproject commit 93201da2ba5a6aba0a6e57ada64973555629b3e3 Subproject commit 77cab8192a879e5d27188f97e8f2080dd7e36ca8

View File

@ -406,9 +406,22 @@ namespace blt
loaded_args.program_name = tokenizer.get(); loaded_args.program_name = tokenizer.get();
tokenizer.advance(); 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; size_t last_positional = 0;
while (tokenizer.hasCurrent()) 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()) if (tokenizer.isFlag())
handleFlagArgument(tokenizer); handleFlagArgument(tokenizer);
else else