]> git.ipfire.org Git - thirdparty/linux.git/commit
tools subcmd: support optarg as separate argument
authorTomas Glozar <tglozar@redhat.com>
Thu, 28 May 2026 10:32:50 +0000 (12:32 +0200)
committerTomas Glozar <tglozar@redhat.com>
Thu, 28 May 2026 11:02:47 +0000 (13:02 +0200)
commit534d9a93dbff2f964a85aef7a7fbfba82d2277bb
tree4d5f16ea6402aef6941cedeab19ed611a1a9a109
parent48209d763c22354c78f6138f4a83814c2f2a3578
tools subcmd: support optarg as separate argument

In addition to "-ovalue" and "--opt=value" syntax, allow also "-o value"
and "--opt value" for options with optional argument when the newly
added PARSE_OPT_OPTARG_ALLOW_NEXT flag is set.

This behavior is turned off by default since it does not make sense for
tools using non-option command line arguments. Consider the ambiguity
of "cmd -d x", where "-d x" can mean either "-d with argument of x" or
"-d without argument, followed by non-option argument x". This is not an
issue in the case that the tool takes no non-option arguments.

To implement this, a new local variable, force_defval, is created in
get_value(), along with a comment explaining the logic.

Link: https://lore.kernel.org/r/20260528103254.2990068-3-tglozar@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
tools/lib/subcmd/parse-options.c
tools/lib/subcmd/parse-options.h