-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
storeOptionsAsProperties-problem.js
36 lines (30 loc) · 1.06 KB
/
storeOptionsAsProperties-problem.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
28
29
30
31
32
33
34
35
36
#!/usr/bin/env node
// The original and default behaviour is that the option values are stored
// as properties on the program (Command). The action handler is passed a
// command object (Command) with the options values also stored as properties.
// This is very convenient to code, but the downside is possible clashes with
// existing properties of Command.
//
// Example output, note the issues in the first call:
//
// $ node storeOptionsAsProperties-problem.js show
// [Function]
// [Function]
//
// $ node storeOptionsAsProperties-problem.js --name foo show --action jump
// jump
// foo
// const commander = require('commander'); // (normal include)
const commander = require('../'); // include commander in git clone of commander repo
const program = new commander.Command();
program
.name('my-program-name')
.option('-n,--name <name>'); // Oops, clash with .name()
program
.command('show')
.option('-a,--action <action>') // Oops, clash with .action()
.action((cmd) => {
console.log(cmd.action);
});
program.parse(process.argv);
console.log(program.name);