From ed8f2d449bac2f22735f55a3c6633d6cd1dc2865 Mon Sep 17 00:00:00 2001 From: Ollrogge Date: Sun, 14 Jan 2024 18:30:41 +0100 Subject: [PATCH] save work --- Userland/Libraries/LibCore/ArgsParser.cpp | 30 +++++++++++++++++++++-- Userland/Libraries/LibCore/ArgsParser.h | 7 +++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp index a9abf0bc17cee7..349e859f179a2f 100644 --- a/Userland/Libraries/LibCore/ArgsParser.cpp +++ b/Userland/Libraries/LibCore/ArgsParser.cpp @@ -569,6 +569,32 @@ void ArgsParser::add_option(Optional& value, char const* help_string, ch add_option(move(option)); } +void ArgsParser::add_option(Vector& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator, OptionHideMode hide_mode) +{ + Option option { + OptionArgumentMode::Required, + help_string, + long_name, + short_name, + value_name, + [&values, separator](StringView s) -> ErrorOr { + bool parsed_all_values = true; + + s.for_each_split_view(separator, SplitBehavior::Nothing, [&](auto value) { + if (auto maybe_value = AK::StringUtils::convert_to_uint(value); maybe_value.has_value()) + values.append(*maybe_value); + else + parsed_all_values = false; + }); + + return parsed_all_values; + }, + hide_mode + }; + + add_option(move(option)); +} + void ArgsParser::add_option(Optional& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode) { Option option { @@ -586,7 +612,7 @@ void ArgsParser::add_option(Optional& value, char const* help_string, c add_option(move(option)); } -void ArgsParser::add_option(Vector& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator, OptionHideMode hide_mode) +void ArgsParser::add_option(Vector& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator, OptionHideMode hide_mode) { Option option { OptionArgumentMode::Required, @@ -598,7 +624,7 @@ void ArgsParser::add_option(Vector& values, char const* help_string, cha bool parsed_all_values = true; s.for_each_split_view(separator, SplitBehavior::Nothing, [&](auto value) { - if (auto maybe_value = AK::StringUtils::convert_to_uint(value); maybe_value.has_value()) + if (auto maybe_value = AK::StringUtils::convert_to_int(value); maybe_value.has_value()) values.append(*maybe_value); else parsed_all_values = false; diff --git a/Userland/Libraries/LibCore/ArgsParser.h b/Userland/Libraries/LibCore/ArgsParser.h index 085e08e8f845c0..898bbe089f56a8 100644 --- a/Userland/Libraries/LibCore/ArgsParser.h +++ b/Userland/Libraries/LibCore/ArgsParser.h @@ -109,10 +109,11 @@ class ArgsParser { void add_option(double& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); void add_option(Optional& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); void add_option(Optional& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); - void add_option(Optional& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); void add_option(Vector& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator = ',', OptionHideMode hide_mode = OptionHideMode::None); - // Note: This option is being used when we expect the user to use the same option - // multiple times (e.g. "program --option=example --option=anotherexample ..."). + void add_option(Optional& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); + void add_option(Vector& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator = ',', OptionHideMode hide_mode = OptionHideMode::None); + // Note: This option is being used when we expect the user to use the same option + // multiple times (e.g. "program --option=example --option=anotherexample ..."). void add_option(Vector& values, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); void add_positional_argument(Arg&&);