Improve support for multivalued options

Description

Currently, options can have at most one argument:

$ my-program --port 80

my current use case, which I believe is very common for command line tools, is to process multiple files which can be specified with a shell glob expression:

$ my-program --import *.csv

which gets expanded by the shell before the arguments are passed to my program:

Ideally, I could specify a :multivalued flag to the argument spec in order to consume more than one token from the arguments, i.e. until another option is provided or when the -- terminator is found:

Environment

None

Activity

Show:
Sean Corfield
February 27, 2021, 11:54 PM

Release 1.0.206

Sean Corfield
May 15, 2020, 2:58 AM

Fixed on master. Added :multi true as a modifier for :update-fn to process multiple options together.

Sean Corfield
February 20, 2020, 3:37 PM

I’ve looked into this and I think that programs in the wild fall into two categories regarding this:

  • They either accept an option multiple times, producing a list of the values passed

  • They simply accept multiple files as their “arguments” with any preceding option being a flag to indicate what to do with them

Translated to your example, those would be equivalent to:

and then:

Or this usage:

with:

Both of these are possible today, but the assoc / update usage could be made easier when processing multiple operations.

I will think about whether adding :multi? true is worthwhile to improve that usage, so you’d say this instead:

 

Fixed

Assignee

Sean Corfield

Reporter

Carlo Sciolla