forked from tj/commander.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pizza
executable file
·27 lines (22 loc) · 869 Bytes
/
pizza
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env node
// const { Command } = require('commander'); // (normal include)
const { Command } = require('../'); // include commander in git clone of commander repo
const program = new Command();
program
.description('An application for pizza ordering')
.option('-p, --peppers', 'Add peppers')
.option('-c, --cheese <type>', 'Add the specified type of cheese', 'marble')
.option('-C, --no-cheese', 'You do not want any cheese');
program.parse();
const options = program.opts();
console.log('you ordered a pizza with:');
if (options.peppers) console.log(' - peppers');
const cheese = !options.cheese ? 'no' : options.cheese;
console.log(' - %s cheese', cheese);
// Try the following on macOS or Linux:
// ./pizza --help
//
// Try the following:
// ./pizza --help
// node pizza --peppers --cheese=blue
// node pizza --no-cheese