1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

Userland+AK: Stop using getopt() for ArgsParser

This commit moves the implementation of getopt into AK, and converts its
API to understand and use StringView instead of char*.
Everything else is caught in the crossfire of making
Option::accept_value() take a StringView instead of a char const*.

With this, we must now pass a Span<StringView> to ArgsParser::parse(),
applications using LibMain are unaffected, but anything not using that
or taking its own argc/argv has to construct a Vector<StringView> for
this method.
This commit is contained in:
Ali Mohammad Pur 2023-02-21 15:14:41 +03:30 committed by Ali Mohammad Pur
parent b2b851b361
commit db886fe18b
43 changed files with 673 additions and 584 deletions

View file

@ -169,19 +169,19 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (selected_options_count == 0) {
warnln("cut: you must specify a list of bytes, or fields");
args_parser.print_usage(stderr, arguments.strings[0].characters_without_null_termination());
args_parser.print_usage(stderr, arguments.strings[0]);
return 1;
}
if (selected_options_count > 1) {
warnln("cut: you must specify only one of bytes, or fields");
args_parser.print_usage(stderr, arguments.strings[0].characters_without_null_termination());
args_parser.print_usage(stderr, arguments.strings[0]);
return 1;
}
if (delimiter.length() != 1) {
warnln("cut: the delimiter must be a single character");
args_parser.print_usage(stderr, arguments.strings[0].characters_without_null_termination());
args_parser.print_usage(stderr, arguments.strings[0]);
return 1;
}
@ -200,7 +200,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto expansion_successful = expand_list(ranges_list, ranges_vector);
if (!expansion_successful) {
args_parser.print_usage(stderr, arguments.strings[0].characters_without_null_termination());
args_parser.print_usage(stderr, arguments.strings[0]);
return 1;
}