-
-
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.
More consistent way of adding command arguments (#1490)
* added addArguments method * fix undefined args * added tests, docs and typings * code review fixes * throw error on bad arg * Parse command-argument details in constructor * Handle argument descriptions separately for legacy and new support * Add text to distinguish test names with .each * Match nameAndArgs into two parts, rather than split on spaces. * Update release date post-release to be more accurate * Fix test naming * Simplify and tidy argument example * Typing and typings test for .argument * Expand argument section to include existing multiple-argument approaches. * Add name method and improve Argument typings and tests * Fix copy-and-paste JSDoc error * Update example to match new method and README * Deprecate old way of adding command argument descriptions * Be lenient about Argument construction to allow lazy building * Call first param to .argument "name", and expand jsdoc * Add low-level check that get same Argument from multiple ways of specifying argument * Minor wording tweaks * Add low-level tests for multiple arg variations * Simplify test. Use .argument now. * Restore simple test, use .argument * Big switch from .arguments to .argument in tests * Expand help to explain argument variations * Keep Argument properties private for now (like Command, unlike Option) * Argument should follow Option for properties, make public again * Generate help for arguments using same methods as for option and subcommand * Simplify Argument .name(), just getter * Expand test coverage for visibleArguments * Rework the multiple ways of specifying command-arguments * Add Argument to esm exports (and createOption) Co-authored-by: Nir Yosef <niryo@wix.com>
- Loading branch information
1 parent
327a3dd
commit b286da9
Showing
33 changed files
with
622 additions
and
189 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import commander from './index.js'; | ||
|
||
// wrapper to provide named exports for ESM. | ||
export const { program, Option, Command, CommanderError, InvalidOptionArgumentError, Help, createCommand } = commander; | ||
export const { program, Option, Command, Argument, CommanderError, InvalidOptionArgumentError, Help, createCommand, createOption } = commander; |
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,24 @@ | ||
#!/usr/bin/env node | ||
|
||
// This example shows specifying the arguments using argument() function. | ||
|
||
// const { Command } = require('commander'); // (normal include) | ||
const { Command } = require('../'); // include commander in git clone of commander repo | ||
const program = new Command(); | ||
|
||
program | ||
.version('0.1.0') | ||
.argument('<username>', 'user to login') | ||
.argument('[password]', 'password for user, if required') | ||
.description('example program for argument') | ||
.action((username, password) => { | ||
console.log('username:', username); | ||
console.log('password:', password || 'no password given'); | ||
}); | ||
|
||
program.parse(); | ||
|
||
// Try the following: | ||
// node arguments.js --help | ||
// node arguments.js user | ||
// node arguments.js user secret |
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
Oops, something went wrong.