mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +00:00
LibCore: Add ArgsParser::add_option for Optional double
This commit is contained in:
parent
a9fb34ca6f
commit
14a267347c
2 changed files with 18 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Sergey Bugaev <bugaevc@serenityos.org>
|
||||
* Copyright (c) 2022, Matthias Zimmerman <matthias291999@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -467,6 +468,22 @@ void ArgsParser::add_option(double& value, const char* help_string, const char*
|
|||
add_option(move(option));
|
||||
}
|
||||
|
||||
void ArgsParser::add_option(Optional<double>& 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 = convert_to_double(s);
|
||||
return value.has_value();
|
||||
}
|
||||
};
|
||||
add_option(move(option));
|
||||
}
|
||||
|
||||
void ArgsParser::add_positional_argument(Arg&& arg)
|
||||
{
|
||||
m_positional_args.append(move(arg));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue