ArgsParser: Add support for Optional<size_t>

This commit is contained in:
brapru 2022-02-17 06:05:16 -05:00 committed by Tim Flynn
parent beb29c48cb
commit 24da85d059
Notes: sideshowbarker 2024-07-17 18:38:12 +09:00
2 changed files with 17 additions and 0 deletions

View file

@ -484,6 +484,22 @@ void ArgsParser::add_option(Optional<double>& value, const char* help_string, co
add_option(move(option));
}
void ArgsParser::add_option(Optional<size_t>& value, const char* help_string, const char* long_name, char short_name, const char* value_name)
{
Option option {
true,
help_string,
long_name,
short_name,
value_name,
[&value](const char* s) {
value = AK::StringUtils::convert_to_uint<size_t>(s);
return value.has_value();
}
};
add_option(move(option));
}
void ArgsParser::add_positional_argument(Arg&& arg)
{
m_positional_args.append(move(arg));

View file

@ -78,6 +78,7 @@ public:
void add_option(unsigned& value, const char* help_string, const char* long_name, char short_name, const char* value_name);
void add_option(double& value, const char* help_string, const char* long_name, char short_name, const char* value_name);
void add_option(Optional<double>& value, const char* help_string, const char* long_name, char short_name, const char* value_name);
void add_option(Optional<size_t>& value, const char* help_string, const char* long_name, char short_name, const char* value_name);
void add_positional_argument(Arg&&);
void add_positional_argument(const char*& value, const char* help_string, const char* name, Required required = Required::Yes);