Skip to content

Commit

Permalink
Remove member
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Feb 8, 2024
1 parent 8a33945 commit bd59d8d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions include/sharg/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<detail::format_parse>(format))
std::exit(EXIT_SUCCESS);
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -748,7 +747,7 @@ class parser
//!\brief List of option/flag identifiers that are already used.
std::set<std::string> 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<std::string> cmd_arguments{};

//!\brief The original command line arguments.
Expand Down Expand Up @@ -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<parser> -> 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};

Expand Down

0 comments on commit bd59d8d

Please sign in to comment.