Files
bower/lib/commands/help.js
2012-12-14 10:59:46 +00:00

45 lines
1.2 KiB
JavaScript

// ==========================================
// BOWER: Help API
// ==========================================
// Copyright 2012 Twitter, Inc
// Licensed under The MIT License
// http://opensource.org/licenses/MIT
// ==========================================
var events = require('events');
var nopt = require('nopt');
var _ = require('lodash');
var template = require('../util/template');
var config = require('../core/config');
module.exports = function (name) {
var context = {};
var emitter = new events.EventEmitter;
var commands = require('../commands');
// Aliases
// At the moment we just have the ls, but we might have more
switch (name) {
case 'ls':
name = 'list';
break;
}
var validCommand = !!(name && commands[name]);
var templateName = validCommand ? 'help-' + name : 'help';
if (!validCommand) context = { commands: Object.keys(commands).join(', ') };
_.extend(context, config);
template(templateName, context)
.on('data', emitter.emit.bind(emitter, 'end'));
return emitter;
};
module.exports.line = function (argv) {
var options = nopt({}, {}, argv);
var paths = options.argv.remain.slice(1);
return module.exports(paths[0]);
};