mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:47:44 +00:00
LibCore: Add new String variants to ArgsParser
This commit adds the ability to use the String class with `add_option` and `add_positional_argument`. This should help with the transition away from DeprecatedString.
This commit is contained in:
parent
d165590809
commit
e247da507f
2 changed files with 42 additions and 0 deletions
|
@ -430,6 +430,27 @@ void ArgsParser::add_option(DeprecatedString& value, char const* help_string, ch
|
|||
add_option(move(option));
|
||||
}
|
||||
|
||||
void ArgsParser::add_option(String& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||
{
|
||||
Option option {
|
||||
OptionArgumentMode::Required,
|
||||
help_string,
|
||||
long_name,
|
||||
short_name,
|
||||
value_name,
|
||||
[&value](StringView s) {
|
||||
auto value_or_error = String::from_utf8(s);
|
||||
if (value_or_error.is_error())
|
||||
return false;
|
||||
|
||||
value = value_or_error.release_value();
|
||||
return true;
|
||||
},
|
||||
hide_mode,
|
||||
};
|
||||
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, OptionHideMode hide_mode)
|
||||
{
|
||||
Option option {
|
||||
|
@ -610,6 +631,25 @@ void ArgsParser::add_positional_argument(StringView& value, char const* help_str
|
|||
add_positional_argument(move(arg));
|
||||
}
|
||||
|
||||
void ArgsParser::add_positional_argument(String& value, char const* help_string, char const* name, Required required)
|
||||
{
|
||||
Arg arg {
|
||||
help_string,
|
||||
name,
|
||||
required == Required::Yes ? 1 : 0,
|
||||
1,
|
||||
[&value](StringView s) {
|
||||
auto value_or_error = String::from_utf8(s);
|
||||
if (value_or_error.is_error())
|
||||
return false;
|
||||
|
||||
value = value_or_error.release_value();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
add_positional_argument(move(arg));
|
||||
}
|
||||
|
||||
template<Integral I>
|
||||
void ArgsParser::add_positional_argument(I& value, char const* help_string, char const* name, Required required)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue