forked from tj/commander.js
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options-common.js
executable file
·27 lines (21 loc) · 903 Bytes
/
options-common.js
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
// This is used as an example in the README for:
// Common option types, boolean and value
// const commander = require('commander'); // (normal include)
const commander = require('../'); // include commander in git clone of commander repo
const program = new commander.Command();
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);
const options = program.opts();
if (options.debug) console.log(options);
console.log('pizza details:');
if (options.small) console.log('- small pizza size');
if (options.pizzaType) console.log(`- ${options.pizzaType}`);
// Try the following:
// node options-common.js -d
// node options-common.js -p
// node options-common.js -ds -p vegetarian
// node options-common.js --pizza-type=cheese