function bashCompletionSpecFromOptions(args) {
    assert.object(args, 'args');
    assert.object(args.options, 'args.options');
    assert.optionalString(args.context, 'args.context');
    assert.optionalBool(args.includeHidden, 'args.includeHidden');
    assert.optionalArrayOfString(args.argtypes, 'args.argtypes');

    var context = args.context || '';
    var includeHidden = (args.includeHidden === undefined
        ? false : args.includeHidden);

    var spec = [];
    var shortopts = [];
    var longopts = [];
    var optargs = [];
    (args.options || []).forEach(function (o) {
        if (o.group !== undefined && o.group !== null) {
            // Skip group headers.
            return;
        }

        var optNames = o.names || [o.name];
        var optType = getOptionType(o.type);
        if (optType.takesArg) {
            var completionType = o.completionType ||
                optType.completionType || o.type;
            optNames.forEach(function (optName) {
                if (optName.length === 1) {
                    if (includeHidden || !o.hidden) {
                        shortopts.push('-' + optName);
                    }
                    // Include even hidden options in `optargs` so that bash
                    // completion of its arg still works.
                    optargs.push('-' + optName + '=' + completionType);
                } else {
                    if (includeHidden || !o.hidden) {
                        longopts.push('--' + optName);
                    }
                    optargs.push('--' + optName + '=' + completionType);
                }
            });
        } else {
            optNames.forEach(function (optName) {
                if (includeHidden || !o.hidden) {
                    if (optName.length === 1) {
                        shortopts.push('-' + optName);
                    } else {
                        longopts.push('--' + optName);
                    }
                }
            });
        }
    });

    spec.push(format('local cmd%s_shortopts="%s"',
        context, shortopts.sort().join(' ')));
    spec.push(format('local cmd%s_longopts="%s"',
        context, longopts.sort().join(' ')));
    spec.push(format('local cmd%s_optargs="%s"',
        context, optargs.sort().join(' ')));
    if (args.argtypes) {
        spec.push(format('local cmd%s_argtypes="%s"',
            context, args.argtypes.join(' ')));
    }
    return spec.join('\n');
}
Return the Bash completion "spec" (the string value for the "{{spec}}"
var in the "dashdash.bash_completion.in" template) for this tool.

The "spec" is Bash code that defines the CLI options and subcmds for
the template's completion code. It looks something like this:

     local cmd_shortopts="-J ..."
     local cmd_longopts="--help ..."
     local cmd_optargs="-p=tritonprofile ..."

@param args.options {Array} The array of dashdash option specs.
@param args.context {String} Optional. A context string for the "local cmd*"
     vars in the spec. By default it is the empty string. When used to
     scope for completion on a *sub-command* (e.g. for "git log" on a "git"
     tool), then it would have a value (e.g. "__log"). See
     <http://github.com/trentm/node-cmdln> Bash completion for details.
@param opts.includeHidden {Boolean} Optional. Default false. By default
     hidden options and subcmds are "excluded". Here excluded means they
     won't be offered as a completion, but if used, their argument type
     will be completed. "Hidden" options and subcmds are ones with the
     `hidden: true` attribute to exclude them from default help output.
@param args.argtypes {Array} Optional. Array of completion types for
     positional args (i.e. non-options). E.g.
         argtypes = ['fruit', 'veggie', 'file']
     will result in completion of fruits for the first arg, veggies for the
     second, and filenames for the third and subsequent positional args.
     If not given, positional args will use Bash's 'default' completion.
     See `specExtra` for providing Bash `complete_TYPE` functions, e.g.
     `complete_fruit` and `complete_veggie` in this example.