diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2023-02-21 15:14:41 +0330 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2023-02-28 15:52:24 +0330 |
commit | db886fe18bad881c1e1064780937c75e92e52b5f (patch) | |
tree | 40c8bdaed6f64580483ecc7d7b09bc29db6d7366 /Userland/Utilities/test-unveil.cpp | |
parent | b2b851b3615c1dbd8e344c8f7bcee7a833c67bee (diff) | |
download | serenity-db886fe18bad881c1e1064780937c75e92e52b5f.zip |
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.
Diffstat (limited to 'Userland/Utilities/test-unveil.cpp')
-rw-r--r-- | Userland/Utilities/test-unveil.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Userland/Utilities/test-unveil.cpp b/Userland/Utilities/test-unveil.cpp index 104faf47ff..77ac7796ea 100644 --- a/Userland/Utilities/test-unveil.cpp +++ b/Userland/Utilities/test-unveil.cpp @@ -25,8 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) .long_name = "unveil", .short_name = 'u', .value_name = "path", - .accept_value = [&](auto* s) { - StringView path { s, strlen(s) }; + .accept_value = [&](StringView path) { if (path.is_empty()) return false; auto maybe_error = Core::System::unveil(path, permissions); @@ -41,7 +40,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) .help_string = "Lock the veil", .long_name = "lock", .short_name = 'l', - .accept_value = [&](auto*) { + .accept_value = [&](StringView) { auto maybe_error = Core::System::unveil(nullptr, nullptr); if (maybe_error.is_error()) { warnln("unveil(nullptr, nullptr): {}", maybe_error.error()); @@ -54,8 +53,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) .name = "path", .min_values = 0, .max_values = INT_MAX, - .accept_value = [&](auto* s) { - auto maybe_error = Core::System::access({ s, strlen(s) }, X_OK); + .accept_value = [&](StringView s) { + auto maybe_error = Core::System::access(s, X_OK); if (maybe_error.is_error()) warnln("'{}' - fail: {}", s, maybe_error.error()); else |