kotlin-argparser icon indicating copy to clipboard operation
kotlin-argparser copied to clipboard

Cannot create non-greedy option arguments, like `--color` option of GNU ls

Open xenomachina opened this issue 7 years ago • 1 comments

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.

xenomachina avatar Feb 28 '17 19:02 xenomachina

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.

xenomachina avatar Apr 21 '17 19:04 xenomachina