-
-
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 getOptionValue and setOptionValue (#1521)
* Simplify typings by removing default export of program * Switch any to unknown per lint suggestion * Add typings change to deprecated.md * Make getOptionValue and setOptionValue public * Fix comment change lost in merge * Tweak wording
- Loading branch information
1 parent
ad3f947
commit 6c06528
Showing
6 changed files
with
71 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const commander = require('../'); | ||
|
||
describe.each([true, false])('storeOptionsAsProperties is %s', (storeOptionsAsProperties) => { | ||
test('when option specified on CLI then value returned by getOptionValue', () => { | ||
const program = new commander.Command(); | ||
program | ||
.storeOptionsAsProperties(storeOptionsAsProperties) | ||
.option('--cheese [type]', 'cheese type'); | ||
const cheeseType = 'blue'; | ||
program.parse(['node', 'test', '--cheese', cheeseType]); | ||
expect(program.getOptionValue('cheese')).toBe(cheeseType); | ||
}); | ||
|
||
test('when setOptionValue then value returned by opts', () => { | ||
const program = new commander.Command(); | ||
const cheeseType = 'blue'; | ||
// Note: opts() only returns declared options when options stored as properties | ||
program | ||
.storeOptionsAsProperties(storeOptionsAsProperties) | ||
.option('--cheese [type]', 'cheese type') | ||
.setOptionValue('cheese', cheeseType); | ||
expect(program.opts().cheese).toBe(cheeseType); | ||
}); | ||
}); |
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