Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add createOption (like createCommand and createHelp) * Add tests * Add TypeScript * option description is optional
- Loading branch information
1 parent
033e6d9
commit b1d984b
Showing
4 changed files
with
77 additions
and
8 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,42 @@ | ||
const commander = require('../'); | ||
|
||
class MyOption extends commander.Option { | ||
constructor(flags, description) { | ||
super(flags, description); | ||
this.myProperty = 'MyOption'; | ||
}; | ||
} | ||
|
||
class MyCommand extends commander.Command { | ||
createOption(flags, description) { | ||
return new MyOption(flags, description); | ||
}; | ||
} | ||
|
||
test('when override createOption then used for option()', () => { | ||
const program = new MyCommand(); | ||
program.option('-a, --alpha'); | ||
expect(program.options.length).toEqual(1); | ||
expect(program.options[0].myProperty).toEqual('MyOption'); | ||
}); | ||
|
||
test('when override createOption then used for requiredOption()', () => { | ||
const program = new MyCommand(); | ||
program.requiredOption('-a, --alpha'); | ||
expect(program.options.length).toEqual(1); | ||
expect(program.options[0].myProperty).toEqual('MyOption'); | ||
}); | ||
|
||
test('when override createOption then used for version()', () => { | ||
const program = new MyCommand(); | ||
program.version('1.2.3'); | ||
expect(program.options.length).toEqual(1); | ||
expect(program.options[0].myProperty).toEqual('MyOption'); | ||
}); | ||
|
||
test('when override createOption then used for help option in visibleOptions', () => { | ||
const program = new MyCommand(); | ||
const visibleOptions = program.createHelp().visibleOptions(program); | ||
expect(visibleOptions.length).toEqual(1); | ||
expect(visibleOptions[0].myProperty).toEqual('MyOption'); | ||
}); |
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