mirror of
https://github.com/bower/bower.git
synced 2026-04-24 03:00:19 -04:00
Initial take on the commands + renderers + cli.
This commit is contained in:
41
lib/util/cli.js
Normal file
41
lib/util/cli.js
Normal file
@@ -0,0 +1,41 @@
|
||||
var mout = require('mout');
|
||||
var nopt = require('nopt');
|
||||
var renderers = require('../renderers');
|
||||
|
||||
function readOptions(argv, options) {
|
||||
var types;
|
||||
var shorthands = {};
|
||||
|
||||
// Configure options that are common to all commands
|
||||
options.help = { type: Boolean, shorthand: 'h' };
|
||||
options.color = { type: Boolean };
|
||||
options.silent = { type: Boolean, shorthand: 's' };
|
||||
options.json = { type: Boolean };
|
||||
options['log-levels'] = { type: String };
|
||||
|
||||
types = mout.object.map(options, function (option) {
|
||||
return option.type;
|
||||
});
|
||||
mout.object.forOwn(options, function (option, name) {
|
||||
shorthands[option.shorthand] = '--' + name;
|
||||
});
|
||||
|
||||
return nopt(types, shorthands, argv);
|
||||
}
|
||||
|
||||
function getRenderer(options) {
|
||||
if (options.silent) {
|
||||
return renderers.mute;
|
||||
}
|
||||
|
||||
if (options.json) {
|
||||
return renderers.json;
|
||||
}
|
||||
|
||||
return options.color === false ?
|
||||
renderers.cli.colorless :
|
||||
renderers.cli.colorful;
|
||||
}
|
||||
|
||||
module.exports.readOptions = readOptions;
|
||||
module.exports.createRenderer = getRenderer;
|
||||
Reference in New Issue
Block a user