How to use the dashdash.bashCompletionSpecFromOptions function in dashdash

To help you get started, we’ve selected a few dashdash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joyent / smartos-live / src / fw / node_modules / cmdln / index.js View on Github external
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];
github joyent / smartos-live / src / fw / node_modules / cmdln / index.js View on Github external
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
            }));
        }
    });

dashdash

A light, featureful and explicit option parsing library.

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis