mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 05:54:58 +00:00
LibCore: Implement handler for Vector<String>
positional arguments
This commit is contained in:
parent
da8a3f9ff2
commit
ab2d8c092e
2 changed files with 16 additions and 0 deletions
|
@ -743,6 +743,21 @@ void ArgsParser::add_positional_argument(Vector<StringView>& values, char const*
|
|||
add_positional_argument(move(arg));
|
||||
}
|
||||
|
||||
void ArgsParser::add_positional_argument(Vector<String>& values, char const* help_string, char const* name, Required required)
|
||||
{
|
||||
Arg arg {
|
||||
help_string,
|
||||
name,
|
||||
required == Required::Yes ? 1 : 0,
|
||||
INT_MAX,
|
||||
[&values](StringView s) -> ErrorOr<bool> {
|
||||
TRY_OR_ERROR_IF_NOT_OOM(values.try_append(TRY(String::from_utf8(s))), s);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
add_positional_argument(move(arg));
|
||||
}
|
||||
|
||||
void ArgsParser::autocomplete(FILE* file, StringView program_name, ReadonlySpan<StringView> remaining_arguments)
|
||||
{
|
||||
// We expect the full invocation of the program to be available as positional args,
|
||||
|
|
|
@ -123,6 +123,7 @@ public:
|
|||
void add_positional_argument(double& value, char const* help_string, char const* name, Required required = Required::Yes);
|
||||
void add_positional_argument(Vector<DeprecatedString>& value, char const* help_string, char const* name, Required required = Required::Yes);
|
||||
void add_positional_argument(Vector<StringView>& value, char const* help_string, char const* name, Required required = Required::Yes);
|
||||
void add_positional_argument(Vector<String>& value, char const* help_string, char const* name, Required required = Required::Yes);
|
||||
|
||||
private:
|
||||
void autocomplete(FILE*, StringView program_name, ReadonlySpan<StringView> remaining_arguments);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue