-
-
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.
Fix sub-command help flags, add documentation on help flags
Sub-commands now inherit the help flags of their parent. These can be overriden by calling ".help" on the sub-commands. Added a test to cover these cases. Updated the example to also demonstrate this feature. Improved documentation on help and outputHelp functions for both JS and TypeScript.
- Loading branch information
Showing
4 changed files
with
104 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var program = require('../'), | ||
sinon = require('sinon').sandbox.create(), | ||
should = require('should'); | ||
|
||
sinon.stub(process, 'exit'); | ||
sinon.stub(process.stdout, 'write'); | ||
|
||
// Test that subcommands inherit the help flags | ||
// but can also override help flags | ||
program | ||
.help('-i, --ihelp', 'foo foo'); | ||
|
||
program | ||
.command('child') | ||
.option('--gender', 'specific gender of child') | ||
.action((cmd) => { | ||
console.log('Childsubcommand...'); | ||
}); | ||
|
||
program | ||
.command('family') | ||
.help('-h, --help') | ||
.action((cmd) => { | ||
console.log('Familysubcommand...'); | ||
}); | ||
|
||
// Test arguments | ||
var expectedCommandHelpInformation = [ | ||
'Usage: child [options]', | ||
'', | ||
'Options:', | ||
' --gender specific gender of child', | ||
' -i, --ihelp foo foo', | ||
'' | ||
].join('\n'); | ||
|
||
program.parse(['node', 'test', 'child', '-i']); | ||
|
||
process.stdout.write.called.should.equal(true); | ||
|
||
var output = process.stdout.write.args[0]; | ||
output[0].should.equal(expectedCommandHelpInformation); | ||
|
||
// Test other command | ||
sinon.restore(); | ||
|
||
sinon.stub(process, 'exit'); | ||
sinon.stub(process.stdout, 'write'); | ||
|
||
var expectedFamilyCommandHelpInformation = [ | ||
'Usage: family [options]', | ||
'', | ||
'Options:', | ||
' -h, --help foo foo', | ||
'' | ||
].join('\n'); | ||
|
||
program.parse(['node', 'test', 'family', '-h']); | ||
|
||
process.stdout.write.called.should.equal(true); | ||
|
||
var output2 = process.stdout.write.args[0]; | ||
output2[0].should.equal(expectedFamilyCommandHelpInformation); | ||
|
||
sinon.restore(); |
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