From bd59d8d87197f03f9beb0f690356063cd5cfd70e Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Thu, 8 Feb 2024 20:43:17 +0100 Subject: [PATCH] Remove member --- include/sharg/parser.hpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/include/sharg/parser.hpp b/include/sharg/parser.hpp index 151795c1..4a6284a0 100644 --- a/include/sharg/parser.hpp +++ b/include/sharg/parser.hpp @@ -439,6 +439,8 @@ class parser format); parse_was_called = true; + std::cout << "executable_name: " << detail::to_string(executable_name) << "\n"; + // Exit after parsing any special format. if (!std::holds_alternative(format)) std::exit(EXIT_SUCCESS); @@ -698,9 +700,6 @@ class parser //!\brief Keeps track of whether the parse function has been called already. bool parse_was_called{false}; - //!\brief Keeps track of whether the init function has been called already. - bool init_was_called{false}; - //!\brief Keeps track of whether the user has added a positional list option to check if this was the very last. bool has_positional_list_option{false}; @@ -748,7 +747,7 @@ class parser //!\brief List of option/flag identifiers that are already used. std::set used_option_ids{"h", "hh", "help", "advanced-help", "export-help", "version", "copyright"}; - //!\brief The command line arguments. + //!\brief The command line arguments that will be passed to the format. std::vector cmd_arguments{}; //!\brief The original command line arguments. @@ -788,15 +787,18 @@ class parser { assert(!original_arguments.empty()); - if (init_was_called) - { - cmd_arguments.clear(); - } - else - { + // If init() is called multiple times (via add_subcommands): + // * We need to clear cmd_arguments. They will be parsed again. + // * We need to handle executable_name: + // * If it is empty: + // * We are in the top level parser, or + // * We are constructing a subparser: make_unique -> constructor -> init + // * If it is not empty, we arrived here through a call to add_subcommands, in which case we already + // appended the subcommand to the executable_name. + cmd_arguments.clear(); + + if (executable_name.empty()) executable_name.emplace_back(original_arguments[0]); - init_was_called = true; - } bool special_format_was_set{false};