shared/options: add new helper option_parser_get_arg

option_parser_next_arg() is renamed to option_parser_peek_next_arg()
to match option_parser_consume_next_arg().

A new helper is added option_parser_get_arg(…, n). It is a common pattern
to only need a single arg, and getting an array and extracting a single
item from it is too verbose.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-04-29 15:28:05 +02:00
parent 408d18f4d2
commit ab9acf8c8c
6 changed files with 36 additions and 21 deletions
+1 -1
View File
@@ -1420,7 +1420,7 @@ static int parse_argv(int argc, char *argv[]) {
* the old container user functionality. To maintain backwards compatibility
* with the space-separated form (--user NAME), if the next opts.arg does not look
* like an option, interpret it as a user name. */
const char *t = option_parser_next_arg(&opts);
const char *t = option_parser_peek_next_arg(&opts);
if (t && t[0] != '-') {
opts.arg = option_parser_consume_next_arg(&opts);
log_warning("--user NAME is deprecated, use --uid=NAME instead.");