-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
alias.js
36 lines (30 loc) · 859 Bytes
/
alias.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
// This example shows giving alternative names for a command.
const { Command } = require('commander');
const program = new Command();
program
.command('exec')
.argument('<script>')
.alias('ex')
.action((script) => {
console.log(`execute: ${script}`);
});
program
.command('print')
.argument('<file>')
// Multiple aliases is unusual but supported! You can call alias multiple times,
// and/or add multiple aliases at once. Only the first alias is displayed in the help.
.alias('p')
.alias('pr')
.aliases(['display', 'show'])
.action((file) => {
console.log(`print: ${file}`);
});
program.parse();
// Try the following:
// node alias.js --help
// node alias.js exec script
// node alias.js ex script
// node alias.js print file
// node alias.js pr file
// node alias.js show file