alecthomas / kingpin

CONTRIBUTIONS ONLY: A Go (golang) command line and flag parser
MIT License
3.5k stars 273 forks source link

Allow multi-item values #276

Closed ghost closed 5 years ago

ghost commented 5 years ago

In python argparse, we can implement this: command (--flag_a FIRST_ITEM SECOND_ITEM) (--flag_a FIRST_ITEM SECOND_ITEM) --flag_b -- some free args. (through the nargs setting)

This is different from repeating the same flag n times. Here a flag can have a list of values rather than a single value AND also be repeatable.

alecthomas commented 5 years ago

How does it differentiate between --flag_a <flag-value> <flag-value> and --flag_a <flag-value> <positional-arg-value> unambiguously?

ghost commented 5 years ago

It doesn't, unfortunately. If you pass --flag_a VALUE POSITIONAL it will treat POSITIONAL as the second VALUE. It will only detect the error if you pass --flag_a VALUE -- POSITIONAL or --flag_a VALUE --other_flag

alecthomas commented 5 years ago

Ok, yeah that's why I didn't implement this in the first place. I'd prefer determinism over ambiguity, though I realise it's slightly more annoying.