mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:27:34 +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
|
@ -60,6 +60,11 @@ bool write_block(int fd, int seed, off_t block, AK::ByteBuffer& buffer)
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Vector<StringView> arguments;
|
||||
arguments.ensure_capacity(argc);
|
||||
for (auto i = 0; i < argc; ++i)
|
||||
arguments.append({ argv[i], strlen(argv[i]) });
|
||||
|
||||
char const* target = nullptr;
|
||||
int min_block_offset = 0;
|
||||
int block_length = 2048;
|
||||
|
@ -82,7 +87,7 @@ int main(int argc, char** argv)
|
|||
args_parser.add_option(stop_mode, "Stop after first error", "abort-on-error", 'a');
|
||||
args_parser.add_option(uninitialized_mode, "Don't pre-initialize block range", "uninitialized", 'u');
|
||||
args_parser.add_positional_argument(target, "Target device/file path", "target");
|
||||
args_parser.parse(argc, argv);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto buffer_result = AK::ByteBuffer::create_zeroed(block_size);
|
||||
if (buffer_result.is_error()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue