Compare commits

..

2 Commits

Author SHA1 Message Date
Brett 7a07f4a729 rename internal fields away from help to subcommand 2023-09-16 17:50:37 -04:00
Brett 45aeb13dd8 fix SUBCOMMAND action type 2023-09-16 17:49:52 -04:00
2 changed files with 11 additions and 11 deletions

View File

@ -307,9 +307,9 @@ namespace blt
} }
} loaded_args; } loaded_args;
bool help_disabled = false; bool subcommand_found = false;
bool use_full_name = false; bool use_full_name = false;
std::string help_inclusion; std::string subcommand_name;
private: private:
static std::string getMetavar(const arg_properties_t* const& arg); static std::string getMetavar(const arg_properties_t* const& arg);
@ -430,7 +430,7 @@ namespace blt
inline void setHelpExtras(std::string str) inline void setHelpExtras(std::string str)
{ {
help_inclusion = std::move(str); subcommand_name = std::move(str);
} }
static std::string filename(const std::string& path); static std::string filename(const std::string& path);

View File

@ -361,7 +361,8 @@ namespace blt
} }
case arg_action_t::SUBCOMMAND: case arg_action_t::SUBCOMMAND:
{ {
help_disabled = true; loaded_args[flag] = true;
subcommand_found = true;
break; break;
} }
case arg_action_t::EXTEND: case arg_action_t::EXTEND:
@ -413,10 +414,10 @@ namespace blt
loaded_args.program_name = tokenizer.get(); loaded_args.program_name = tokenizer.get();
tokenizer.advance(); tokenizer.advance();
if (!help_inclusion.empty()) if (!subcommand_name.empty())
{ {
// advance the tokenizer to post grouped args allowing for flags // advance the tokenizer to post grouped args allowing for flags
while (tokenizer.hasCurrent() && tokenizer.get() != help_inclusion) while (tokenizer.hasCurrent() && tokenizer.get() != subcommand_name)
tokenizer.advance(); tokenizer.advance();
tokenizer.advance(); tokenizer.advance();
} }
@ -425,8 +426,7 @@ namespace blt
while (tokenizer.hasCurrent()) while (tokenizer.hasCurrent())
{ {
// if we find an arg which disables help (basically a grouping flag) then we should stop processing args // 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 (subcommand_found)
if (help_disabled)
break; break;
if (tokenizer.isFlag()) if (tokenizer.isFlag())
@ -498,7 +498,7 @@ namespace blt
void arg_parse::printHelp() const void arg_parse::printHelp() const
{ {
if (help_disabled) if (subcommand_found)
return; return;
if (!user_args.prefix.empty()) if (!user_args.prefix.empty())
{ {
@ -558,9 +558,9 @@ namespace blt
void arg_parse::printUsage() const void arg_parse::printUsage() const
{ {
if (help_disabled) if (subcommand_found)
return; return;
std::string usage = "Usage: " + getProgramName() + " " + help_inclusion + " "; std::string usage = "Usage: " + getProgramName() + " " + subcommand_name + " ";
std::cout << usage; std::cout << usage;
size_t current_line_length = 0; size_t current_line_length = 0;