kotlin-argparser
kotlin-argparser copied to clipboard
Cannot create non-greedy option arguments, like `--color` option of GNU ls
The --help
for GNU ls
looks like:
--color[=WHEN] colorize the output; WHEN can be 'always' (default
if omitted), 'auto', or 'never'; more info below
You can say:
-
ls --color=never /tmp
← color has argument "never" -
ls --color /tmp
← color has no argument, defaults to "auto" -
ls --color never /tmp
← color has no argument, defaults to "auto" and "never" is treated as a positional argument
So the --color
option has an optional argument, which it will only consume if it is in the same command-line argument.
With OptionArgumentIterator
there is no way distinguish between --color=never
and --color never
, so it is currently impossible to simulate the behavior of this option.
Suggested fix: add a property to OptionArgumentIterator
to indicate whether the first argument is "mandatory". A "storingWithDefault" convenience method could then be created that would consume an argument iff it is mandatory.
I'm changing this to an enhancement, as there is now a clear path for this to be done unambiguously, even though the feature doesn't yet exist.