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

Inconsistent behavior of boolean and option in strict mode #1694

Closed
jhiode opened this issue Jul 17, 2020 · 2 comments
Closed

Inconsistent behavior of boolean and option in strict mode #1694

jhiode opened this issue Jul 17, 2020 · 2 comments
Assignees
Labels

Comments

@jhiode
Copy link

jhiode commented Jul 17, 2020

I found an inconsistent behavior of .boolean(key) and .option(key, { boolean: true }).

Here is an example:

const yargs = require('yargs'); // v15.4.1

yargs
  .command({
    command: 'test',
    builder: (argv) => {
      return argv.boolean('b1').option('b2', { boolean: true });
    },
    handler: console.log,
  })
  .strict()
  .parse();

As far as I understand the documentation, these two APIs should work the same, but only option b2 is actually working, option b1 is simply ignored:

$ node index.js test --help
index.js test

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --b2                                                                 [boolean]

Using it results in an error:

$ node index.js test --b1
index.js test

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --b2                                                                 [boolean]

Unknown argument: b1

But it works in non-strict mode though:

$ node index.js test --b1
{ _: [ 'test' ], b1: true, '$0': 'index.js' }

It seems that the call to self.describe is the reason for the different behavior.

yargs/lib/yargs.ts

Lines 843 to 844 in 0b519a4

const desc = opt.describe || opt.description || opt.desc
self.describe(key, desc)

@jly36963
Copy link
Contributor

jly36963 commented Jan 3, 2022

@jhiode
I believe my fix has been released with 17.3.1 -- can you confirm that it solves the issue you reported?

@shadowspawn
Copy link
Member

Thanks for the report. This was likely fixed by #1996 by @jly36963.

This issue has not had any activity in over six months. It isn't likely to get acted on due to this report.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants