Skip to content

Instantly share code, notes, and snippets.

@alobato
Last active July 19, 2020 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alobato/14f1fbde303faebeca9489cafb8192dd to your computer and use it in GitHub Desktop.
Save alobato/14f1fbde303faebeca9489cafb8192dd to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const { program } = require('commander');
const inquirer = require('inquirer');
program
.option('-d, --debug', 'output extra debugging')
.option('-s, --small', 'small pizza size')
.option('-p, --pizza-type <type>', 'flavour of pizza');
program.parse(process.argv);
inquirer.prompt([{
name: 'name',
type: 'input',
message: 'What\'s your name?',
}, {
name: 'iceCream',
type: 'list',
message: 'Which is your favorite of the following ice cream flavors?',
choices: ['green tea', 'poppyseed jam', 'chile', 'vanilla'],
default: 3,
}]).then((answers) => {
console.log(`\nHi ${answers.name}. I like ${answers.iceCream} ice cream too! 😋\n`);
});
if (program.debug) console.log(program.opts());
console.log('pizza details:');
if (program.small) console.log('- small pizza size');
if (program.pizzaType) console.log(`- ${program.pizzaType}`);
{
"name": "test",
"version": "1.0.0",
"description": "test",
"bin": "./index.js",
"dependencies": {
"commander": "5.1.0",
"inquirer": "7.3.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment