commando icon indicating copy to clipboard operation
commando copied to clipboard

Option repetition (mostly for verbosity 'levels') ?

Open kevinquinnyo opened this issue 10 years ago • 6 comments

Is there a clean way to implement this using the existing code? Or would it need to be a new feature?

Think ssh -v[vvvvvv...] (incrementing levels of verbosity if the option is repeated)

Note that with ssh, it functions the same with: ssh -v -v -v -v example.com and ssh -vvvv example.com

I don't recall ever seeing this type of "option repetition" used with anything other than verbosity levels, and I'm not sure if that's even a GNU utility psuedo-standard, or if it's just specific to ssh and a few other oddball utilities, but it is handy. I'd actually like to use that for a project I'm building, using your Commando library that wraps around ssh, and would like to provide the same -v[vvv...] functionality if possible. Ideas?

I love your work on this by the way -- great library.

kevinquinnyo avatar Sep 17 '14 00:09 kevinquinnyo

Just wanted to clarify how I imagined this might look like:

$options->option('v')
        ->describedAs(Verbosity.  Add more for additional verbosity - ie:  -vvv')
        ->repeatable();

I'm thinking all it would have to do is set a count of how many v's were supplied. Then the user of your library can do whatever they need to, given that count? I haven't dug through the code too much yet, so I'm not sure if it would require a lot of refactor to implement something like this or not.

kevinquinnyo avatar Sep 17 '14 03:09 kevinquinnyo

I agree, that's a useful feature I've desired as well. I've seen it used in other libs, I believe maybe mongo or some other popular cli that escapes me at the moment.

stratease avatar Sep 17 '14 05:09 stratease

No easy support for it currently, but agree it is a worth while feature. Labeling as such.

nategood avatar Sep 22 '14 18:09 nategood

Cool! Hey I was inspired and bored, so I made my own (more of a rough draft) heavily inspired by your library.

https://github.com/kevinquinnyo/Optopus

In fact I downright stole your method chaining slickness. This one is missing a lot of cool things you have, but it does have the framework in place for the repeats() method as well as the -- end-of-options support that I think is also lacking in yours. Maybe it will inspire you? I'm thinking I might be better off just cloning yours and making a pull request for some feature branches since I don't want to re-invent the wheel here.

kevinquinnyo avatar Sep 23 '14 01:09 kevinquinnyo

This was implemented in GetOptionKit. FYI: https://github.com/c9s/GetOptionKit/wiki/Defining-Options#incremental-flag

c9s avatar Apr 24 '15 08:04 c9s

PR #63 Closes this @nategood

NeoVance avatar Nov 10 '16 06:11 NeoVance