Below is the out I get from the code that is also below.
Question
input
and i
are both true, as expected, but why isn't project
and p
?
They are defined that exact same way as input
and i
.
$ bin/test --input -p
{ _: [],
update: false,
u: false,
input: true,
i: true,
p: '',
project: '' }
And the code is
'use strict'
var minimist = require('minimist')
module.exports = () => {
var argv = minimist(process.argv.slice(2), {
string: 'input',
string: 'project',
boolean: ['help'],
boolean: ['update'],
alias: { i: 'input', h: 'help', p: 'project', u: 'update' },
unknown: function () { console.log('Unkown argument') }
})
if (argv.input || argv.i) {
console.log(argv)
}
if (argv.project || argv.p) {
console.log(argv)
console.log('p')
}
You cannot have duplicate property names in an object (unfortunately they are allowed , not throwing exceptions any more).
Your current code is equivalent to
var argv = minimist(process.argv.slice(2), {
string: 'project',
boolean: ['update'],
alias: { i: 'input', h: 'help', p: 'project', u: 'update' },
unknown: function () { console.log('Unkown argument') }
})
where input
is not defined as a string parameter but project
is.
What you want to write is
var argv = minimist(process.argv.slice(2), {
string: ['input', 'project'],
boolean: ['help', 'update'],
alias: { i: 'input', h: 'help', p: 'project', u: 'update' },
unknown: function () { console.log('Unkown argument') }
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.