-
Notifications
You must be signed in to change notification settings - Fork 384
Closed
Description
Strongly related to #9, how to handle list values.
In #9, I assumed they would be contiguous values on the CLI with a separator, e.g. inv mytask --listarg list;val;here.
However, a common pattern for existing arg parsing libs is to give a flag >1 time and have the results tallied into a list, e.g. inv mytask -l list -l val -l here. E.g. this is how argparse/optparse do it, IIRC.
Pros of that latter approach:
- No need to deal with overridden meaning for shell meta-characters (many candidate delimiters have shell meaning.)
- Counterpoint: commas work pretty good...
- No need to deal with escaping (always a PITA.)
- Minority use case: aping/wrapping pre-existing tools which work this way (e.g. using Invoke as a lightweight argument preprocessor before calling a Java process.)
Cons:
- Harder to implement, requires the parser to be more complicated :(
- Some parsers treat multiple values for the same flag as overrides, so in the above example we'd get
-l here"winning" as a string, not list, value. Some users may expect or desire this behavior, e.g. when stitching together args from various "levels" of an invoking program. - When you are intending to give a list in a single invocation, typing out
mytask --listarg a;b;cis much faster thanmytask -l a -l b -l c.
Either way:
- Do we perform sub-list transformation, i.e. do we turn
mytask --listarg 1,2,3into a list of ints automatically? Which again ties back into CLI arg typecasting #9.