Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Unexpected arguments not parsed correctly? #23

Open
cowboy opened this issue Sep 11, 2013 · 3 comments
Open

[BUG] Unexpected arguments not parsed correctly? #23

cowboy opened this issue Sep 11, 2013 · 3 comments
Labels
Bug thing that needs fixing

Comments

@cowboy
Copy link

cowboy commented Sep 11, 2013

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' ] } }
@michaelficarra
Copy link
Contributor

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.

@cowboy
Copy link
Author

cowboy commented Sep 11, 2013

I'm just happy to know either way what the intention is, and to see some documentation around how unexpected arguments are handled.

@isaacs
Copy link
Contributor

isaacs commented Sep 12, 2013

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 :)

@darcyclarke darcyclarke changed the title Unexpected arguments not parsed correctly? [BUG] Unexpected arguments not parsed correctly? Jul 28, 2022
@darcyclarke darcyclarke added the Bug thing that needs fixing label Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing
Projects
None yet
Development

No branches or pull requests

4 participants