Skip to content

[BUG] Unexpected arguments not parsed correctly? #23

@cowboy

Description

@cowboy

I've noticed a behavior change from nopt@1.0.10 -> nopt@2.1.2 with the parsing of unexpected arguments.

  • In nopt@1.0.10 '-a a' and '-a=a' (as well as with --) were equivalent.
  • In nopt@2.1.2 '-a a' and '-a=a' (as well as with --) behave differently. Basically, -a a works like -a (setting prop a to true) but adds "a" the the remain array. Shouldn't both set prop a to string "a"?
$ npm install nopt@~1.0.10
npm WARN package.json foo@0.0.0 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
nopt@1.0.10 node_modules/nopt
└── abbrev@1.0.4

$ 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 foo@0.0.0 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
nopt@2.1.2 node_modules/nopt
└── abbrev@1.0.4

$ 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' ] } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions