Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Cmdln.prototype.bashCompletionSpec = function bashCompletionSpec(opts) {
var self = this;
if (!opts) {
opts = {};
}
assert.object(opts, 'opts');
assert.optionalString(opts.context, 'opts.context');
assert.optionalBool(opts.includeHidden, 'opts.includeHidden');
var spec = [];
var context = opts.context || '';
var includeHidden = (opts.includeHidden === undefined
? false : opts.includeHidden);
// Top-level.
spec.push(dashdash.bashCompletionSpecFromOptions({
options: self.options,
context: context,
includeHidden: includeHidden
}));
var aliases = [];
var allAliases = [];
Object.keys(this._nameFromAlias).sort().forEach(function (alias) {
if (alias === '?') {
// '?' as a Bash completion is painful. Also, '?' as a default
// alias for 'help' should die.
return;
}
var name = self._nameFromAlias[alias];
var handler = self._handlerFromName[name];
var handler = self._handlerFromName[name];
if (typeof (handler.bashCompletionSpec) === 'function') {
// This is a `Cmdln` subclass, i.e. a sub-CLI.
var subspec = handler.bashCompletionSpec({context: context_});
if (subspec) {
spec.push(subspec);
}
} else {
if (handler.completionArgtypes) {
assert.arrayOfString(handler.completionArgtypes,
'do_' + name + '.completionArgtypes');
spec.push(format('local cmd%s_argtypes="%s"',
context_, handler.completionArgtypes.join(' ')));
}
spec.push(dashdash.bashCompletionSpecFromOptions({
options: handler.options || [],
context: context_,
includeHidden: includeHidden
}));
}
});