-
-
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 Argument choices, and missing types and tests for default and argParse * Only make arguments visible if some description, not just default or choices * Improve format for partial argument descriptions * Add argument choices to README * Add test for edge case in argumentDescription
- Loading branch information
1 parent
d282f20
commit 708527e
Showing
12 changed files
with
213 additions
and
11 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,23 @@ | ||
#!/usr/bin/env node | ||
|
||
// This is used as an example in the README for extra argument features. | ||
|
||
// const commander = require('commander'); // (normal include) | ||
const commander = require('../'); // include commander in git clone of commander repo | ||
const program = new commander.Command(); | ||
|
||
program | ||
.addArgument(new commander.Argument('<drink-size>', 'drink cup size').choices(['small', 'medium', 'large'])) | ||
.addArgument(new commander.Argument('[timeout]', 'timeout in seconds').default(60, 'one minute')) | ||
.action((drinkSize, timeout) => { | ||
console.log(`Drink size: ${drinkSize}`); | ||
console.log(`Timeout (s): ${timeout}`); | ||
}); | ||
|
||
program.parse(); | ||
|
||
// Try the following: | ||
// node arguments-extra.js --help | ||
// node arguments-extra.js huge | ||
// node arguments-extra.js small | ||
// node arguments-extra.js medium 30 |
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,21 @@ | ||
const { Argument } = require('../'); | ||
|
||
describe('Argument methods that should return this for chaining', () => { | ||
test('when call .default() then returns this', () => { | ||
const argument = new Argument('<value>'); | ||
const result = argument.default(3); | ||
expect(result).toBe(argument); | ||
}); | ||
|
||
test('when call .argParser() then returns this', () => { | ||
const argument = new Argument('<value>'); | ||
const result = argument.argParser(() => { }); | ||
expect(result).toBe(argument); | ||
}); | ||
|
||
test('when call .choices() then returns this', () => { | ||
const argument = new Argument('<value>'); | ||
const result = argument.choices(['a']); | ||
expect(result).toBe(argument); | ||
}); | ||
}); |
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
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