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

added an example using inquirer prompting #2114

Merged
merged 3 commits into from Jan 13, 2022
Merged

added an example using inquirer prompting #2114

merged 3 commits into from Jan 13, 2022

Conversation

chrisdugne
Copy link
Contributor

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

Copy link
Member

@bcoe bcoe left a 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')
Copy link
Member

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();
}

Copy link
Contributor Author

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

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?

Copy link
Contributor Author

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;

docs/examples.md Outdated Show resolved Hide resolved
@chrisdugne chrisdugne requested a review from bcoe January 13, 2022 13:07
chrisdugne added a commit to uralys/fox that referenced this pull request Jan 13, 2022
@bcoe bcoe merged commit c066164 into yargs:main Jan 13, 2022
@bcoe
Copy link
Member

bcoe commented Jan 13, 2022

@chrisdugne thank you for the contribution.

@chrisdugne
Copy link
Contributor Author

you're welcome, and I thank you for yargs : )

@chrisdugne chrisdugne deleted the adding-inquirer-example branch January 14, 2022 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants