From 1d50ee1d318bd2d8f12ff2d1ce359898513b71ce 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 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/sharg/parser.hpp b/include/sharg/parser.hpp index 151795c1..14f0fad2 100644 --- a/include/sharg/parser.hpp +++ b/include/sharg/parser.hpp @@ -698,9 +698,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 +745,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 +785,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};