Skip to content

Commit

Permalink
docs: an example using inquirer prompting (#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdugne committed Jan 13, 2022
1 parent d6e342d commit c066164
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions docs/examples.md
Expand Up @@ -302,7 +302,7 @@ s.on('end', function () {
```

***
$ node line_count.js
$ node line_count.js
Usage: line_count.js <command> [options]

Commands:
Expand All @@ -319,7 +319,7 @@ s.on('end', function () {
copyright 2019

Missing required argument: f

$ node line_count.js count
line_count.js count

Expand All @@ -337,3 +337,32 @@ s.on('end', function () {

$ node line_count.js count -f line_count.js
25

Using inquirer for prompting
---------------------------

```js
const yargs = require('yargs');
const inquirer = require('inquirer');

const sing = () => console.log('🎵 Oy oy oy');

const askName = async () => {
const answers = await inquirer.prompt([
{
message: 'What is your name?',
name: 'name',
type: 'string'
}
]);

console.log(`Hello, ${answers.name}!`);
};

const argv = yargs(process.argv.splice(2))
.command('ask', 'use inquirer to prompt for your name', () => {}, askName)
.command('sing', 'a classic yargs command without prompting', () => {}, sing)
.demandCommand(1, 1, 'choose a command: ask or sing')
.strict()
.help('h').argv;
```

0 comments on commit c066164

Please sign in to comment.