mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +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
Notes:
sideshowbarker
2024-07-16 19:57:55 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/f71d74ed65 Pull-request: https://github.com/SerenityOS/serenity/pull/21216 Reviewed-by: https://github.com/gmta ✅
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…
Reference in a new issue