[BUG] Unexpected arguments not parsed correctly?
I've noticed a behavior change from [email protected] -> [email protected] with the parsing of unexpected arguments.
- In [email protected] '-a a' and '-a=a' (as well as with
--) were equivalent. - In [email protected] '-a a' and '-a=a' (as well as with
--) behave differently. Basically,-a aworks like-a(setting propatotrue) but adds"a"the theremainarray. Shouldn't both set propato string"a"?
$ npm install nopt@~1.0.10
npm WARN package.json [email protected] No README.md file found!
npm http GET https://registry.npmjs.org/nopt
npm http 304 https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/abbrev
npm http 304 https://registry.npmjs.org/abbrev
[email protected] node_modules/nopt
└── [email protected]
$ node -pe "require('nopt')({}, {}, ['-a', 'a', '-b=b', '--c', 'c', '--d=d'], 0)"
{ a: 'a',
b: 'b',
c: 'c',
d: 'd',
argv:
{ remain: [],
cooked: [ '-a', 'a', '-b', 'b', '--c', 'c', '--d', 'd' ],
original: [ '-a', 'a', '-b=b', '--c', 'c', '--d=d' ],
toString: [Function] } }
$ npm install nopt@latest
npm WARN package.json [email protected] No README.md file found!
npm http GET https://registry.npmjs.org/nopt
npm http 304 https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/abbrev
npm http 304 https://registry.npmjs.org/abbrev
[email protected] node_modules/nopt
└── [email protected]
$ node -pe "require('nopt')({}, {}, ['-a', 'a', '-b=b', '--c', 'c', '--d=d'], 0)"
{ a: true,
b: 'b',
c: true,
d: 'd',
argv:
{ remain: [ 'a', 'c' ],
cooked: [ '-a', 'a', '-b', 'b', '--c', 'c', '--d', 'd' ],
original: [ '-a', 'a', '-b=b', '--c', 'c', '--d=d' ] } }
FWIW, I think the new default behaviour is better; an unknown option should be assumed to be a flag (edit: unless they are in the form -a=b of course). But if major-version back compat is desired (which would be very surprising), then yes, this is a bug.
I'm just happy to know either way what the intention is, and to see some documentation around how unexpected arguments are handled.
Yes, this is an intentional change, and the reason for bumping the version to 2.x from 1.x.
Docs would be lovely. First one to send a pull request with docs gets the honor of closing this issue :)