mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:14:58 +00:00
LibCore: Add ArgsParser::add_option for setting enum values from a flag
Previously, argument-less options could only set a boolean to true. This lets them also set an enum variable to a specific value, as is currently done by the `ls` utility.
This commit is contained in:
parent
4d2af7c3d6
commit
f71d74ed65
1 changed files with 14 additions and 0 deletions
|
@ -87,6 +87,20 @@ public:
|
|||
void add_option(Option&&);
|
||||
void add_ignored(char const* long_name, char short_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||
void add_option(bool& value, char const* help_string, char const* long_name, char short_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||
/// If the option is present, set the enum to have the given `new_value`.
|
||||
template<Enum T>
|
||||
void add_option(T& value, T new_value, char const* help_string, char const* long_name, char short_name, OptionHideMode hide_mode = OptionHideMode::None)
|
||||
{
|
||||
add_option({ .argument_mode = Core::ArgsParser::OptionArgumentMode::None,
|
||||
.help_string = help_string,
|
||||
.long_name = long_name,
|
||||
.short_name = short_name,
|
||||
.accept_value = [&](StringView) {
|
||||
value = new_value;
|
||||
return true;
|
||||
},
|
||||
.hide_mode = hide_mode });
|
||||
}
|
||||
void add_option(DeprecatedString& 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue