mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 09:46:04 -05:00
ArgsParser: Remove boolean trap on add_arg
Rather than requiring a boolean for whether or not the argument is required, add some new methods to make the purpose of the bool explicit.
This commit is contained in:
parent
5cad215919
commit
729507f2bd
Notes:
sideshowbarker
2024-07-19 14:04:39 +09:00
Author: https://github.com/rburchell Commit: https://github.com/SerenityOS/serenity/commit/729507f2bde Pull-request: https://github.com/SerenityOS/serenity/pull/50
3 changed files with 22 additions and 10 deletions
|
@ -115,14 +115,24 @@ bool ArgsParser::check_required_args(const ArgsParserResult& res)
|
|||
return true;
|
||||
}
|
||||
|
||||
void ArgsParser::add_arg(const String& name, const String& description, bool required)
|
||||
void ArgsParser::add_required_arg(const String& name, const String& description)
|
||||
{
|
||||
m_args.set(name, Arg(name, description, required));
|
||||
m_args.set(name, Arg(name, description, true));
|
||||
}
|
||||
|
||||
void ArgsParser::add_arg(const String& name, const String& value_name, const String& description, bool required)
|
||||
void ArgsParser::add_required_arg(const String& name, const String& value_name, const String& description)
|
||||
{
|
||||
m_args.set(name, Arg(name, value_name, description, required));
|
||||
m_args.set(name, Arg(name, value_name, description, true));
|
||||
}
|
||||
|
||||
void ArgsParser::add_arg(const String& name, const String& description)
|
||||
{
|
||||
m_args.set(name, Arg(name, description, false));
|
||||
}
|
||||
|
||||
void ArgsParser::add_arg(const String& name, const String& value_name, const String& description)
|
||||
{
|
||||
m_args.set(name, Arg(name, value_name, description, false));
|
||||
}
|
||||
|
||||
String ArgsParser::get_usage() const
|
||||
|
|
|
@ -34,8 +34,10 @@ public:
|
|||
|
||||
ArgsParserResult parse(const int argc, const char** argv);
|
||||
|
||||
void add_arg(const String& name, const String& description, bool required);
|
||||
void add_arg(const String& name, const String& value_name, const String& description, bool required);
|
||||
void add_required_arg(const String& name, const String& description);
|
||||
void add_required_arg(const String& name, const String& value_name, const String& description);
|
||||
void add_arg(const String& name, const String& description);
|
||||
void add_arg(const String& name, const String& value_name, const String& description);
|
||||
String get_usage() const;
|
||||
void print_usage() const;
|
||||
|
||||
|
|
|
@ -35,10 +35,10 @@ static int pid_of(const String& process_name, bool single_shot, bool omit_pid, p
|
|||
int main(int argc, char** argv)
|
||||
{
|
||||
AK::ArgsParser args_parser("pidof", "-");
|
||||
|
||||
args_parser.add_arg("s", "Single shot - this instructs the program to only return one pid", false);
|
||||
args_parser.add_arg("o", "pid", "Tells pidof to omit processes with that pid. The special pid %PPID can be used to name the parent process of the pidof program.", false);
|
||||
|
||||
|
||||
args_parser.add_arg("s", "Single shot - this instructs the program to only return one pid");
|
||||
args_parser.add_arg("o", "pid", "Tells pidof to omit processes with that pid. The special pid %PPID can be used to name the parent process of the pidof program.");
|
||||
|
||||
AK::ArgsParserResult args = args_parser.parse(argc, (const char**)argv);
|
||||
|
||||
bool s_arg = args.is_present("s");
|
||||
|
|
Loading…
Add table
Reference in a new issue