|
1 | 1 | #!/usr/bin/env node
|
2 | 2 |
|
3 |
| -// This example shows specifying the arguments using argument() function. |
| 3 | +// This example shows specifying the command arguments using argument() function. |
4 | 4 |
|
5 | 5 | // const { Command } = require('commander'); // (normal include)
|
6 | 6 | const { Command } = require('../'); // include commander in git clone of commander repo
|
7 | 7 | const program = new Command();
|
8 | 8 |
|
9 | 9 | program
|
10 |
| - .version('0.1.0') |
11 |
| - .argument('<username>', 'user to login') |
12 |
| - .argument('[password]', 'password for user, if required', 'no password given') |
13 |
| - .description('example program for argument') |
14 |
| - .action((username, password) => { |
15 |
| - console.log('username:', username); |
16 |
| - console.log('password:', password); |
| 10 | + .name('connect') |
| 11 | + .argument('<server>', 'connect to the specified server') |
| 12 | + .argument('[user]', 'user account for connection', 'guest') |
| 13 | + .description('Example program with argument descriptions') |
| 14 | + .action((server, user) => { |
| 15 | + console.log('server:', server); |
| 16 | + console.log('user:', user); |
17 | 17 | });
|
18 | 18 |
|
19 | 19 | program.parse();
|
20 | 20 |
|
21 | 21 | // Try the following:
|
22 |
| -// node arguments.js --help |
23 |
| -// node arguments.js user |
24 |
| -// node arguments.js user secret |
| 22 | +// node argument.js --help |
| 23 | +// node argument.js main.remote.site |
| 24 | +// node argument.js main.remote.site admin |
0 commit comments