mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
LibCore: Add StringView overloads for Core::ArgsParser
These allow you to get StringView wrappers around on-stack string arguments, which seems pretty nice. :^)
This commit is contained in:
parent
dd9b8ee7ef
commit
313e53dca0
2 changed files with 33 additions and 0 deletions
|
@ -285,6 +285,22 @@ void ArgsParser::add_option(String& value, const char* help_string, const char*
|
|||
add_option(move(option));
|
||||
}
|
||||
|
||||
void ArgsParser::add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* 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 {
|
||||
|
@ -354,6 +370,21 @@ void ArgsParser::add_positional_argument(String& value, const char* help_string,
|
|||
add_positional_argument(move(arg));
|
||||
}
|
||||
|
||||
void ArgsParser::add_positional_argument(StringView& value, char const* help_string, char const* name, Required required)
|
||||
{
|
||||
Arg arg {
|
||||
help_string,
|
||||
name,
|
||||
required == Required::Yes ? 1 : 0,
|
||||
1,
|
||||
[&value](const char* s) {
|
||||
value = s;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
add_positional_argument(move(arg));
|
||||
}
|
||||
|
||||
void ArgsParser::add_positional_argument(int& value, const char* help_string, const char* name, Required required)
|
||||
{
|
||||
Arg arg {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue