-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Short version: support POSIX style parsing mode which only reads optional value with embedded forms --optional=VALUE and -oVALUE.
Say: program.optionOptionalValuesEmbedded()
(Shorter meaningful name suggestions welcome!)
Long version
Commander supports an option which may be used as a boolean option but may optionally take an option-argument (declared with square brackets like -o, --opt [value]). This can lead to parsing ambiguities due to the space-separated VALUE being confused with non-option arguments.
These are all the optional variations:
foo --optional
foo -o
foo --optional VALUE
foo -o VALUE
foo --optional=VALUE
foo -oVALUE
POSIX takes a stricter approach, which avoids the parsing ambiguity. The option-argument has to be embedded with the option.
If the SYNOPSIS shows an optional option-argument (as with
[ -f[option_argument]]in the example), a conforming application shall place any option-argument for that option directly adjacent to the option in the same argument string, without intervening characters. If the utility receives an argument containing only the option, it shall behave as specified in its description for an omitted option-argument; it shall not treat the next argument (if any) as the option-argument for that option.
So the POSIX approach only allows:
foo --optional
foo -o
foo --optional=VALUE
foo -oVALUE
Reference: