Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for -v to get the version #560

Closed
chasenlehara opened this issue Aug 14, 2016 · 15 comments · Fixed by Urigo/tortilla#56
Closed

Add support for -v to get the version #560

chasenlehara opened this issue Aug 14, 2016 · 15 comments · Fixed by Urigo/tortilla#56

Comments

@chasenlehara
Copy link

chasenlehara commented Aug 14, 2016

Please add support for -v instead of -V to get the --version to be consistent with Node and npm (and a lot of other CLIs).

Related to #509

@chasenlehara
Copy link
Author

chasenlehara commented Aug 14, 2016

@tj, why was this change made? I tried to track down why that change was made, but I couldn’t find anything. 😕

@jrylan
Copy link

jrylan commented Aug 24, 2016

I've always been really curious about this as well. I've been using this quick fix near the top of my CLI app to ensure -v works:

var vPos = process.argv.indexOf('-v')
if (vPos > -1) {
  process.argv[vPos] = '-V'
}

@sgen
Copy link

sgen commented Aug 24, 2016

Probably because several tools use -v and --verbose for their verbose output flag and -V and --version for their version flag

@jimbuck
Copy link

jimbuck commented Nov 17, 2016

Thanks @jrylan, that does the trick. But only if you are okay with the auto-generated help not mentioning -v specifically.

@dkern
Copy link

dkern commented May 8, 2017

@sgen But nearly the whole environment around commander ueses -v for the version output. It would be more than usefull to have it the same way.

  • node uses -v
  • npm uses -v
  • gulp uses -v
  • grunt uses -v
  • ...

It should at least be configurable. Maybe directly on the version command, like:

cli.version('1.0.0', '-v, --version');

@theoutlander
Copy link

I prefer -V for verbose. Also, is there an easy way to replace -V with -v? If I add a new option, it will show both. Maybe I'm missing something.

@mojavelinux
Copy link
Contributor

This is already possible. It's just a customization:

.version('1.0.0', '-v, --version')

If the flags aren't specified, they just default to -V, --version.

One pattern I happen to like is to honor the -v when specified as the only argument, but then let it get used as an option when combined with other options and arguments (such as verbose).

@mojavelinux
Copy link
Contributor

I think the API docs need to be updated to reflect the fact that flags can be specified as an override.

@ahmadawais
Copy link

Tried to look for a way to add that doc, couldn't. Thanks @mojavelinux for the tip.

@ahmadawais
Copy link

@mojavelinux
Copy link
Contributor

As it turns out, the flag can be overridden, but the program continues to respond only to a long name that resolves to "version". But this makes the help inaccurate.

I'll submit a patch to respect the name of the option specified in the method.

mojavelinux added a commit to mojavelinux/commander.js that referenced this issue Jan 19, 2018
@mojavelinux
Copy link
Contributor

Patches submitted!

@ahmadawais
Copy link

Seems to work just fine on my end without the patch? What am I missing?

@mojavelinux
Copy link
Contributor

@ahmadawais You are using the default name for the option, which is version. If you wanted to use a different name, like --revision, then it wouldn't work. So this fix doesn't apply to your use case, but important nonetheless.

@ahmadawais
Copy link

Got it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants