Last active
July 19, 2020 02:06
-
-
Save alobato/14f1fbde303faebeca9489cafb8192dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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