Files
bower/lib/commands/info.js
Mickael Daniel b544425667 completion - generic method to complete command options
at command level, attach the `shorthand` Hash to the completion
function. The completion command will then try to complete shorthands
and longer flag based on user input.

completing after just one `-` will complete the list of short flags.

completing after just two `--` will complete the list of longer flags.
2012-12-25 16:03:21 +01:00

50 lines
1.3 KiB
JavaScript

// ==========================================
// BOWER: Lookup API
// ==========================================
// Copyright 2012 Twitter, Inc
// Licensed under The MIT License
// http://opensource.org/licenses/MIT
// ==========================================
var Emitter = require('events').EventEmitter;
var nopt = require('nopt');
var template = require('../util/template');
var source = require('../core/source');
var install = require('./install');
var help = require('./help');
var optionTypes = { help: Boolean };
var shorthand = { 'h': ['--help'] };
module.exports = function (name) {
var emitter = new Emitter;
if (name) {
source.info(name, function (err, result) {
if (err) return emitter.emit('error', err);
emitter.emit('end', result);
});
}
return emitter;
};
module.exports.line = function (argv) {
var emitter = new Emitter;
var options = nopt(optionTypes, shorthand, argv);
var names = options.argv.remain.slice(1);
if (options.help || !names.length) return help('info');
module.exports(names[0])
.on('error', emitter.emit.bind(emitter, 'error'))
.on('end', function (data) {
template('info', data).on('data', emitter.emit.bind(emitter, 'end'));
});
return emitter;
};
module.exports.completion = install.completion;
module.exports.completion.options = shorthand;