How to use the dashdash.addOptionType 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 misterfifths / jutil / cmdline.js View on Github external
names: ['help', 'h'],
        type: 'bool',
        help: 'Show this help.'
    }
];

const fileOpts = [
    {
        names: ['file', 'f'],
        helpArg: 'FILE',
        help: 'Load data from the given file instead of reading from stdin.',
        type: 'string'
    }
];

dashdash.addOptionType({
    name: 'colorOptions',
    takesArg: true,
    helpArg: 'OPTION',
    parseArg(option, optStr, arg) {
        const validOptions = ['off', 'force', 'auto', 'auto+pager'];
        if(validOptions.indexOf(arg) == -1) {
            throw new Error('argument for ' + optStr + ' is not valid');
        }
        return arg;
    }
});

const objectOutputOpts = [
    {
        names: ['pretty-print', 'p'],
        type: 'bool',

dashdash

A light, featureful and explicit option parsing library.

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis