A wrapper around commander.js
npm install commander-extrashell
$ [sudo] npm i commander-extra --save
`
Usage
Create a file that will be the entry point of your command:
`javascript
var path = require('path');
var commander = require('commander-extra');
var pkg = require(path.join(__dirname, 'package.json'));
var program = commander({
name: 'my-tool',
version: pkg.version,
commandsDir: path.join(__dirname, 'commands'),
beforeHelp: function() {
// This will be called before displaying help so you can add anything
},
// If this is true then a config file will be created in ~/.my-tool/config
hasConfig: true
});
`
Then, to create your first command, create a folder commands and add a javascript file:
`javascript
module.exports = function makeEvent(program) {
'use strict';
program
.command('hello [optional]')
.description('Command description')
.action(function(mandatory, optional, command) {
program.log.i('Normal output');
program.log.e('Error');
program.log.w('Warning');
// This is only shown if the option -h or --help is used
program.log.d('Debug info');
// These need the hasConfig option to be true
program.config.get('some.config');
program.config.set('some.config', 'Some value');
program.config.has('some.config');
});
};
`
You can then test your command by doing:
`shell
$ node my-tool.js hello john smith
``