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
added an example using inquirer prompting #2114
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @chrisdugne, left a few recommendations.
docs/examples.md
Outdated
}; | ||
|
||
const argv = yargs(process.argv.splice(2)) | ||
.command('ask', 'use inquirer to prompt for your name') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than using a switch statement, you could do this:
.command('ask', 'use inquirer to prompt for your name', () => {}, async () => {
await askName();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, it's working without the async/await
though
.command('ask', 'use inquirer to prompt for your name', () => {}, askName)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the advantage of async await is that you could await
the top level yargs.argv
and it shouln't return until you've filled in the prompted messages ... neat right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I've first tested with your suggestion, and it was not working as expected, not sure why;
@chrisdugne thank you for the contribution. |
you're welcome, and I thank you for yargs : ) |
I've been looking for how to use inquirer with yargs,
and found this issue: #1476
So here is how I use an async command to prompt things with inquirer
cheers