From 5724753b5d78a7e33cdc678b0f68786c92ea7ed3 Mon Sep 17 00:00:00 2001 From: chrisdugne Date: Thu, 13 Jan 2022 14:15:13 +0100 Subject: [PATCH] using a test for https://github.com/yargs/yargs/pull/2114 --- cli/test-cli.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 cli/test-cli.js diff --git a/cli/test-cli.js b/cli/test-cli.js new file mode 100644 index 0000000..b94877b --- /dev/null +++ b/cli/test-cli.js @@ -0,0 +1,26 @@ +#!/usr/bin/env node +// ----------------------------------------------------------------------------- + +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;