Skip to content

Instantly share code, notes, and snippets.

@ahmadawais
Last active January 19, 2018 09:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadawais/da08521a51d9093edec46eeedc2065ac to your computer and use it in GitHub Desktop.
Save ahmadawais/da08521a51d9093edec46eeedc2065ac to your computer and use it in GitHub Desktop.
commander.js : Customize Version Argument for `commander.js` ⚡️

Customize Version Argument for commander.js

You can support for -v instead of -V to get the --version to be consistent with Node and npm.

It's just a customization:

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

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

const commander = require( 'commander' );
const packageJson = require( './package.json' );
const program = new commander.Command( packageJson.name )
.version( packageJson.version, '-v, --version' )
.parse( process.argv );
@mojavelinux
Copy link

I've since learned that commander.js was not allowing the name of the long option to be changed (e.g., --revision). I've submitted a patch to support this.

@ahmadawais
Copy link
Author

@mojavelinux why would you like to change that? But I can see I never tested that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment