A :multi spec key for repeated options #5

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@jedahu
jedahu commented Nov 22, 2011

Uses update-in and conj to update a vector value.

(first (cli ["-x" "1" "-x" "2"] ["-x" :multi true])) ; => {:x ["1" "2"]}

Contributor

Hey,

The easiest way to do this currently with cli is something like:

(cli ["-x" "1,2"]
     ["-x" :parse-fn #(clojure.string/split % #",") :default []])

=> [{:x ["1" "2"]} ... ]

Is there a specific reason why that is not convenient and you would want to introduce an extra :multi flag? If you have a multi flag are you assuming it is always going to be a vector?

As a side note, Clojure does not accept pull requests on github -- you need to create a ticket in JIRA and attach a patch to the ticket. You also need to have signed a contributor agreement before you can do that:

http://dev.clojure.org/jira
http://clojure.org/contributing

jedahu commented Nov 23, 2011

Yeah, I thought about comma separated values, but they don't work well with tab completion of file names. Repeated flags are not uncommon for commandline tools.

Not sure what you mean about assuming it will be a vector. The code ensures that by passing an empty vector to conj the first time a :multi flag is encountered.

I'll get on with signing a contributor agreement.

Contributor

Not sure what you mean about assuming it will be a vector. The code ensures that by passing an empty vector to conj the > first time a :multi flag is encountered.

Sorry wasn't too clear there, 'assuming' is the wrong word -- I just meant are you effectively stating "I intend this to be a vector value" when you give the :multi option, which clearly you are based on the implementation.

I'm not opposed to this change, it would probably need a test to go along with it and I think it would probably also need to update the generated banner somehow to indicate it can be specified multiple times, as well as updates to the README file. If you want to do those too that's cool, otherwise I can take care of them after your CA comes through.

I'll leave the pull request open and if you can let me know when your CA is accepted and the JIRA ticket is created I'll close it.

Thanks!

jedahu commented Nov 23, 2011

Great :-). I'll get mailin'.

You might want to take a look at #6. A contributor proposed a different way of doing this that I think is more general.

jedahu commented May 9, 2012

Looks good. Thanks for keeping me updated! I did get my CA accepted but in the intervening time this pull request has slipped way down my list of priorities.

Contributor

Closing as you have not got back re: signing your CA. Please re-create in JIRA if this is a big deal for you.

@gar3thjon3s gar3thjon3s closed this Aug 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment