pkgjs / parseargs

Polyfill of `util.parseArgs()`
Apache License 2.0
121 stars 10 forks source link

withValue requires '=' for value to be set. #54

Closed bcoe closed 2 years ago

bcoe commented 2 years ago
    const parse = parser(['--pow', 'xixxle'], {
      withValue: ['pow']
    })

Parses as:

{
  flags: { pow: true },
  values: { pow: undefined },
  positionals: [ 'xixxle' ]
}

I believe this should be:

{
  flags: { },
  values: { pow: 'xixxle' },
  positionals: [  ]
}
shadowspawn commented 2 years ago

Speculation: I will try reproducing later, but my first guess is that your shim is not passing through withValue successfully and you are getting zero-config behaviour.

shadowspawn commented 2 years ago

I am unable to reproduce the problem as described. I see this behaviour:

const { parseArgs } = require('@pkgjs/parseargs');

const parsed = parseArgs(['--pow', 'xixxle'], {
    withValue: ['pow']
  })

console.log(parsed);
% node index.js 
{ flags: { pow: true }, values: { pow: 'xixxle' }, positionals: [] }

(Wondering why there is there an entry for pow in flags? See #38: the README and naming and code are not all in sync! The code is still using existence conventions. Looking forward to making a decision and getting things consistent.)

bcoe commented 2 years ago

@shadowspawn let me test again against the latest main, I wonder if it's a bug we merged a fix for.

bcoe commented 2 years ago

I was being silly and not passing the options to the parser.