diff options
author | DexesTTP <dexes.ttp@gmail.com> | 2021-04-17 20:39:32 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-18 22:42:10 +0200 |
commit | b30f5dc8b5c156c8913b397a94cebc283f5b3750 (patch) | |
tree | a60c77f1f9e315d26d3d5082c439e301316ad1c4 /Userland/Libraries/LibCore | |
parent | 8e44a0bd469cba6d9cba9ea45ee3eb85c7cbb381 (diff) | |
download | serenity-b30f5dc8b5c156c8913b397a94cebc283f5b3750.zip |
LibCore: Add ArgsParser::add_option(String&)
The API existed for add_positional_argument, but not for named arguments.
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r-- | Userland/Libraries/LibCore/ArgsParser.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibCore/ArgsParser.h | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp index c42a6d9579..cbc0eeee20 100644 --- a/Userland/Libraries/LibCore/ArgsParser.cpp +++ b/Userland/Libraries/LibCore/ArgsParser.cpp @@ -288,6 +288,22 @@ void ArgsParser::add_option(const char*& value, const char* help_string, const c add_option(move(option)); } +void ArgsParser::add_option(String& value, const char* help_string, const char* long_name, char short_name, const char* value_name) +{ + Option option { + true, + help_string, + long_name, + short_name, + value_name, + [&value](const char* s) { + value = s; + return true; + } + }; + add_option(move(option)); +} + void ArgsParser::add_option(int& value, const char* help_string, const char* long_name, char short_name, const char* value_name) { Option option { diff --git a/Userland/Libraries/LibCore/ArgsParser.h b/Userland/Libraries/LibCore/ArgsParser.h index 9b49fff538..143a23a533 100644 --- a/Userland/Libraries/LibCore/ArgsParser.h +++ b/Userland/Libraries/LibCore/ArgsParser.h @@ -74,6 +74,7 @@ public: void add_option(Option&&); void add_option(bool& value, const char* help_string, const char* long_name, char short_name); void add_option(const char*& value, const char* help_string, const char* long_name, char short_name, const char* value_name); + void add_option(String& value, const char* help_string, const char* long_name, char short_name, const char* value_name); void add_option(int& value, const char* help_string, const char* long_name, char short_name, const char* value_name); void add_option(double& value, const char* help_string, const char* long_name, char short_name, const char* value_name); |