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

[v17] Error with async builder #1917

Closed
danthegoodman opened this issue Apr 20, 2021 · 2 comments · Fixed by #1925
Closed

[v17] Error with async builder #1917

danthegoodman opened this issue Apr 20, 2021 · 2 comments · Fixed by #1925
Labels

Comments

@danthegoodman
Copy link

Problem

Using an async builder used to work but is now producing erroneous results.

Example

Given this minimal script:

const yargs = require('yargs/yargs');
yargs(process.argv.slice(2))
    .strict()
    .command({
      command: 'alpha',
      describe: 'A',
      builder: async (yargs) =>
        yargs
          .command({
            command: 'beta',
            describe: 'B',
            handler: ()=> console.log("It works!"),
          })
          .demandCommand(1),
      handler: ()=>null,
    })
    .demandCommand(1)
    .parse()

The following commands produce this output:

$ npm install yargs@next
$ node script.js alpha beta
script.js alpha

A

Commands:
  script.js alpha alpha  A

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

Unknown argument: beta
$ node script.js alpha alpha beta
It works!
$ npm install yargs@17.0.0-candidate.7
$ node script.js alpha beta
script.js alpha

A

Commands:
  script.js alpha alpha  A

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

Unknown argument: beta
$ npm install yargs@17.0.0-candidate.6
$ node script.js alpha beta
It works!
@bcoe
Copy link
Member

bcoe commented Apr 26, 2021

@danthegoodman good catch, turned out to be a fairly major bug.

Could you try yargs@17.0.0-candidate.13 and let me know if it works for your use cases?

@danthegoodman
Copy link
Author

@bcoe It works! Thank you :)

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

Successfully merging a pull request may close this issue.

2 participants