mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +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:
parent
b2b851b361
commit
db886fe18b
43 changed files with 673 additions and 584 deletions
|
@ -296,9 +296,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
.long_name = "link",
|
||||
.short_name = 'l',
|
||||
.value_name = "file",
|
||||
.accept_value = [&](char const* str) {
|
||||
if (auto v = StringView { str, strlen(str) }; !v.is_empty()) {
|
||||
modules_to_link_in.append(v);
|
||||
.accept_value = [&](StringView str) {
|
||||
if (!str.is_empty()) {
|
||||
modules_to_link_in.append(str);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -310,8 +310,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
.long_name = "arg",
|
||||
.short_name = 0,
|
||||
.value_name = "u64",
|
||||
.accept_value = [&](char const* str) -> bool {
|
||||
if (auto v = StringView { str, strlen(str) }.to_uint<u64>(); v.has_value()) {
|
||||
.accept_value = [&](StringView str) -> bool {
|
||||
if (auto v = str.to_uint<u64>(); v.has_value()) {
|
||||
values_to_push.append(v.value());
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue