-
-
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.
Merge branch 'master' into release/10.x
- Loading branch information
Showing
16 changed files
with
840 additions
and
280 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
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 |
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,32 @@ | ||
#!/usr/bin/env node | ||
|
||
// This example shows global options on the program which affect all the subcommands. | ||
// See how to work with global options in the subcommand and display them in the help. | ||
// | ||
// (A different pattern for a "global" option is to add it to the subcommands, rather | ||
// than to the program. See global-options-added.js.) | ||
|
||
// const { Command } = require('commander'); // (normal include) | ||
const { Command } = require('../'); // include commander in git clone of commander repo | ||
|
||
const program = new Command(); | ||
|
||
program | ||
.configureHelp({ showGlobalOptions: true }) | ||
.option('-g, --global'); | ||
|
||
program | ||
.command('sub') | ||
.option('-l, --local') | ||
.action((options, cmd) => { | ||
console.log({ | ||
opts: cmd.opts(), | ||
optsWithGlobals: cmd.optsWithGlobals() | ||
}); | ||
}); | ||
|
||
program.parse(); | ||
|
||
// Try the following: | ||
// node global-options-nested.js --global sub --local | ||
// node global-options-nested.js sub --help |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.