Write options for minimist in a comfortable way. Support string, boolean, number and array options.
$ npm install --save minimist-options
const buildOptions = require('minimist-options');
const minimist = require('minimist');
const options = buildOptions({
name: {
type: 'string',
alias: 'n',
default: 'john'
},
force: {
type: 'boolean',
alias: ['f', 'o'],
default: false
},
score: {
type: 'number',
alias: 's',
default: 0
},
arr: {
type: 'array',
alias: 'a',
default: []
},
published: 'boolean',
// Special option for positional arguments (`_` in minimist)
arguments: 'string'
});
const args = minimist(process.argv.slice(2), options);
instead of:
const minimist = require('minimist');
const options = {
string: ['name', '_'],
number: ['score'],
array: ['arr'],
boolean: ['force', 'published'],
alias: {
n: 'name',
f: 'force',
s: 'score',
a: 'arr'
},
default: {
name: 'john',
f: false,
score: 0,
arr: []
}
};
const args = minimist(process.argv.slice(2), options);
MIT © Vadim Demedes