mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibCore: Add ArgsParser::add_option for Optional double
This commit is contained in:
parent
a9fb34ca6f
commit
14a267347c
Notes:
sideshowbarker
2024-07-17 20:33:28 +09:00
Author: https://github.com/mjz19910
Commit: 14a267347c
Pull-request: https://github.com/SerenityOS/serenity/pull/11961
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/awesomekling
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));
|
||||
|
|
|
@ -77,6 +77,7 @@ public:
|
|||
void add_option(int& value, const char* help_string, const char* long_name, char short_name, const char* value_name);
|
||||
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_positional_argument(Arg&&);
|
||||
void add_positional_argument(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