summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore/ArgsParser.cpp
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2022-03-25 22:11:05 +0100
committerTim Flynn <trflynn89@pm.me>2022-03-27 08:33:24 -0400
commit23a87a41ff16e0197b77ba1f80a75dec48addd19 (patch)
treebfc9fe8800ee96a54455ae14a18b7a4196e30cb4 /Userland/Libraries/LibCore/ArgsParser.cpp
parent269f9c68638d9ccd3c5dc41575ba093290c989ac (diff)
downloadserenity-23a87a41ff16e0197b77ba1f80a75dec48addd19.zip
LibCore: Add Vector<size_t> variant of add_option()
This adds a Vector<size_t> variant of add_option(). The signature includes a separator parameter which defaults to ','.
Diffstat (limited to 'Userland/Libraries/LibCore/ArgsParser.cpp')
-rw-r--r--Userland/Libraries/LibCore/ArgsParser.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp
index a41ae6cda2..e351cf46b4 100644
--- a/Userland/Libraries/LibCore/ArgsParser.cpp
+++ b/Userland/Libraries/LibCore/ArgsParser.cpp
@@ -520,6 +520,32 @@ void ArgsParser::add_option(Optional<size_t>& value, const char* help_string, co
add_option(move(option));
}
+void ArgsParser::add_option(Vector<size_t>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator, bool hidden)
+{
+ Option option {
+ true,
+ help_string,
+ long_name,
+ short_name,
+ value_name,
+ [&values, separator](char const* s) {
+ bool parsed_all_values = true;
+
+ StringView { s }.for_each_split_view(separator, false, [&](auto value) {
+ if (auto maybe_value = AK::StringUtils::convert_to_uint<size_t>(value); maybe_value.has_value())
+ values.append(*maybe_value);
+ else
+ parsed_all_values = false;
+ });
+
+ return parsed_all_values;
+ },
+ hidden
+ };
+
+ add_option(move(option));
+}
+
void ArgsParser::add_positional_argument(Arg&& arg)
{
m_positional_args.append(move(arg));