-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mention of .alias() to README. (#1833)
- Loading branch information
1 parent
5a201ec
commit 91bfa8d
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env node | ||
|
||
// This example shows giving alternative names for a command. | ||
|
||
// const { Command } = require('commander'); // (normal include) | ||
const { Command } = require('../'); // include commander in git clone of commander repo | ||
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 |