1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 03:08:13 +00:00

LibCore/ArgsParser: Learn how to stop on first non-option

We need this for utilities like `env`, that do not gain anything by
parsing the options passed to the command they are supposed to
execute.
This commit is contained in:
Jelle Raaijmakers 2021-06-07 21:20:35 +02:00 committed by Andreas Kling
parent 0b0bce78f6
commit d7126fbbc2
3 changed files with 181 additions and 0 deletions

View file

@ -42,6 +42,9 @@ bool ArgsParser::parse(int argc, char* const* argv, FailureBehavior failure_beha
Vector<option> long_options;
StringBuilder short_options_builder;
if (m_stop_on_first_non_option)
short_options_builder.append('+');
int index_of_found_long_option = -1;
// Tell getopt() to reset its internal state, and start scanning from optind = 1.