mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
LibCore: Add StringView overloads for Core::ArgsParser
These allow you to get StringView wrappers around on-stack string arguments, which seems pretty nice. :^)
This commit is contained in:
parent
dd9b8ee7ef
commit
313e53dca0
2 changed files with 33 additions and 0 deletions
|
@ -285,6 +285,22 @@ void ArgsParser::add_option(String& value, const char* help_string, const char*
|
||||||
add_option(move(option));
|
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)
|
||||||
|
{
|
||||||
|
Option option {
|
||||||
|
true,
|
||||||
|
help_string,
|
||||||
|
long_name,
|
||||||
|
short_name,
|
||||||
|
value_name,
|
||||||
|
[&value](const char* s) {
|
||||||
|
value = s;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
add_option(move(option));
|
||||||
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(int& value, const char* help_string, const char* long_name, char short_name, const char* value_name)
|
void ArgsParser::add_option(int& value, const char* help_string, const char* long_name, char short_name, const char* value_name)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
|
@ -354,6 +370,21 @@ void ArgsParser::add_positional_argument(String& value, const char* help_string,
|
||||||
add_positional_argument(move(arg));
|
add_positional_argument(move(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ArgsParser::add_positional_argument(StringView& value, char const* help_string, char const* name, Required required)
|
||||||
|
{
|
||||||
|
Arg arg {
|
||||||
|
help_string,
|
||||||
|
name,
|
||||||
|
required == Required::Yes ? 1 : 0,
|
||||||
|
1,
|
||||||
|
[&value](const char* s) {
|
||||||
|
value = s;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
add_positional_argument(move(arg));
|
||||||
|
}
|
||||||
|
|
||||||
void ArgsParser::add_positional_argument(int& value, const char* help_string, const char* name, Required required)
|
void ArgsParser::add_positional_argument(int& value, const char* help_string, const char* name, Required required)
|
||||||
{
|
{
|
||||||
Arg arg {
|
Arg arg {
|
||||||
|
|
|
@ -55,12 +55,14 @@ public:
|
||||||
void add_option(bool& value, const char* help_string, const char* long_name, char short_name);
|
void add_option(bool& value, const char* help_string, const char* long_name, char short_name);
|
||||||
void add_option(const char*& value, const char* help_string, const char* long_name, char short_name, const char* value_name);
|
void add_option(const char*& value, const char* help_string, const char* long_name, char short_name, const char* value_name);
|
||||||
void add_option(String& value, const char* help_string, const char* long_name, char short_name, const char* value_name);
|
void add_option(String& value, const char* help_string, const char* long_name, char short_name, const char* value_name);
|
||||||
|
void add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name);
|
||||||
void add_option(int& value, const char* help_string, const char* long_name, char short_name, const char* value_name);
|
void add_option(int& 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(double& 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(Arg&&);
|
||||||
void add_positional_argument(const char*& value, const char* help_string, const char* name, Required required = Required::Yes);
|
void add_positional_argument(const char*& value, const char* help_string, const char* name, Required required = Required::Yes);
|
||||||
void add_positional_argument(String& value, const char* help_string, const char* name, Required required = Required::Yes);
|
void add_positional_argument(String& value, const char* help_string, const char* name, Required required = Required::Yes);
|
||||||
|
void add_positional_argument(StringView& value, char const* help_string, char const* name, Required required = Required::Yes);
|
||||||
void add_positional_argument(int& value, const char* help_string, const char* name, Required required = Required::Yes);
|
void add_positional_argument(int& value, const char* help_string, const char* name, Required required = Required::Yes);
|
||||||
void add_positional_argument(double& value, const char* help_string, const char* name, Required required = Required::Yes);
|
void add_positional_argument(double& value, const char* help_string, const char* name, Required required = Required::Yes);
|
||||||
void add_positional_argument(Vector<const char*>& value, const char* help_string, const char* name, Required required = Required::Yes);
|
void add_positional_argument(Vector<const char*>& value, const char* help_string, const char* name, Required required = Required::Yes);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue