mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
LibCore: Support Optional<StringView> as an argument to ArgsParser
While StringView does have a null state, we have been moving away from this in our other String classes. To represent a StringView not being given at all on the commandline, use an Optional.
This commit is contained in:
parent
3e61d20b40
commit
abf35f5bd6
2 changed files with 18 additions and 0 deletions
|
@ -490,6 +490,23 @@ void ArgsParser::add_option(StringView& value, char const* help_string, char con
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ArgsParser::add_option(Optional<StringView>& 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) -> ErrorOr<bool> {
|
||||||
|
value = s;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
hide_mode,
|
||||||
|
};
|
||||||
|
add_option(move(option));
|
||||||
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(double& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
void ArgsParser::add_option(double& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
|
|
|
@ -170,6 +170,7 @@ public:
|
||||||
void add_option(ByteString& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
void add_option(ByteString& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(String& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
void add_option(String& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
void add_option(StringView& 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<StringView>& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
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(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<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<double>& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
// Note: This option is being used when we expect the user to use the same option
|
// Note: This option is being used when we expect the user to use the same option
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue