Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Gene Gottlieb <[email protected]>
  • Loading branch information
eseiler and SGSSGene authored Mar 1, 2024
1 parent 3b9fee0 commit d89995c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/sharg/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ class parser
verify_option_config(config);

if (config.short_id != '\0')
options.push_back(std::string{"-"} + config.short_id);
options.emplace(std::string{"-"} + config.short_id);

if (config.long_id != "")
options.push_back(std::string{"--"} + config.long_id);
options.emplace(std::string{"--"} + config.long_id);

auto operation = [this, &value, config]()
{
Expand Down Expand Up @@ -760,7 +760,7 @@ class parser
std::vector<std::string> executable_name{};

//!\brief Vector of option identifiers that have been added via `add_option`.
std::vector<std::string> options{};
std::unordered_set<std::string> options{};

//!\brief Vector of functions that stores all calls.
std::vector<std::function<void()>> operations;
Expand All @@ -770,7 +770,7 @@ class parser
* \throws sharg::too_few_arguments if option --version-check was specified without a value
* \throws sharg::validation_error if the value passed to option --export-help was invalid.
* \throws sharg::validation_error if the value passed to option --version-check was invalid.
* \throws sharg::user_input_error if the subcommand was misspelled.
* \throws sharg::user_input_error if the subcommand is unknown.
* \details
*
* This function adds all command line parameters to the format_arguments member variable
Expand Down Expand Up @@ -837,10 +837,10 @@ class parser
{
// Positional options are forbidden by design.
// Flags and options, which both start with '-', are allowed for the top-level parser.
// Otherwise, this is a wrongly spelled subcommand.
// Otherwise, this is a unknown subcommand.
if (!arg.starts_with('-'))
{
std::string message = "You misspelled the subcommand! Please specify "
std::string message = "You specified an unknown subcommand! Please specify "
"which sub-program you want to use: [";
for (std::string const & command : subcommands)
message += command + ", ";
Expand All @@ -857,7 +857,7 @@ class parser
for (; read_next_arg();)
{
// The argument is a known option.
if (std::ranges::find(options, arg) != options.end())
if (options.contains(arg))
{
// No futher checks are needed.
format_arguments.emplace_back(arg);
Expand Down

0 comments on commit d89995c

Please sign in to comment.