-
-
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 .requiredOption() for mandatory options (#1071)
* Add declaration of requiredOption and mandatory property * Add initial implementation for error detection for mandatory options * Add unit tests for mandatory options * Add detailed test for exitOverride intercept for missing mandatory option * Add .requiredOption to README * Reword mandatory description. * Lookup option value using attributeName, not name * Expand tests - option name different than property name - both of option/requiredOption for negated option - add exitOverride to allow Jest to catch unexpected errors * Add .requiredOption calls to TypeScript dummy program * Tweak requiredOption example file
- Loading branch information
1 parent
57e9d98
commit 7f9edba
Showing
7 changed files
with
416 additions
and
49 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,19 @@ | ||
#!/usr/bin/env node | ||
|
||
// This is used as an example in the README for: | ||
// Required option | ||
// You may specify a required (mandatory) option using `.requiredOption`. | ||
// The option must be specified on the command line, or by having a default value. | ||
// | ||
// Example output pretending command called pizza (or try directly with `node options-required.js`) | ||
// | ||
// $ pizza | ||
// error: required option '-c, --cheese <type>' not specified | ||
|
||
const commander = require('..'); // For running direct from git clone of commander repo | ||
const program = new commander.Command(); | ||
|
||
program | ||
.requiredOption('-c, --cheese <type>', 'pizza must have cheese'); | ||
|
||
program.parse(process.argv); |
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.