dargs
Reverse minimist
. Convert an object of options into an array of command-line arguments.
Useful when spawning command-line tools.
Install
$ npm install --save dargs
Usage
const dargs = require('dargs');
const input = {
_: ['some', 'option'],
foo: 'bar',
hello: true,
cake: false,
camelCase: 5,
multiple: ['value', 'value2'],
pieKind: 'cherry',
sad: ':('
};
const excludes = ['sad', /.*Kind$/];
const includes = ['camelCase', 'multiple', 'sad', /^pie.*/];
const aliases = {file: 'f'};
console.log(dargs(input, {excludes: excludes}));
console.log(dargs(input, {
excludes: excludes,
includes: includes
}));
console.log(dargs(input, {includes: includes}));
console.log(dargs({
foo: 'bar',
hello: true,
file: 'baz'
}, {
aliases: aliases
}));
API
dargs(input, [options])
input
Type: object
Object to convert to command-line arguments.
options
Type: object
excludes
Type: array
Keys or regex of keys to exclude. Takes precedence over includes
.
includes
Type: array
Keys or regex of keys to include.
aliases
Type: object
Maps keys in input
to an aliased name. Matching keys are converted to options with a single dash ("-") in front of the aliased name and a space separating the aliased name from the value. Keys are still affected by includes
and excludes
.
useEquals
Type: boolean
Default: true
Setting to false
switches the separator in generated commands from an equals sign =
to a single space
. For example:
console.log(dargs({foo: 'bar'}, {useEquals: false}));
ignoreFalse
Type: boolean
Default: false
Don't include false
values. This is mostly useful when dealing with strict argument parsers that would throw on unknown arguments like --no-foo
.
License
MIT © Sindre Sorhus