Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to override help and version help message #963
Minor edits from John Gee to typings added during squash.
- Loading branch information
1 parent
1c1ffca
commit c61d724
Showing
8 changed files
with
248 additions
and
17 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,21 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var program = require('../'); | ||
|
||
program | ||
.helpOption('-c, --HELP', 'custom help message') | ||
.option('-s, --sessions', 'add session support') | ||
.option('-t, --template <engine>', 'specify template engine (jade|ejs) [jade]', 'jade'); | ||
|
||
program | ||
.command('child') | ||
.option('--gender', 'specific gender of child') | ||
.action((cmd) => { | ||
console.log('Childsubcommand...'); | ||
}); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var program = require('../'); | ||
|
||
program | ||
.version('0.0.1', '-v, --VERSION', 'new version message') | ||
.option('-s, --sessions', 'add session support') | ||
.option('-t, --template <engine>', 'specify template engine (jade|ejs) [jade]', 'jade') | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var program = require('../') | ||
, sinon = require('sinon').sandbox.create() | ||
, should = require('should'); | ||
|
||
sinon.stub(process, 'exit'); | ||
sinon.stub(process.stdout, 'write'); | ||
|
||
program.helpOption('-c, --HELP', 'custom help output'); | ||
program.command('somecommand'); | ||
program.command('anothercommand [options]'); | ||
|
||
var expectedHelpInformation = [ | ||
'Usage: [options] [command]', | ||
'', | ||
'Options:', | ||
' -c, --HELP custom help output', | ||
'', | ||
'Commands:', | ||
' somecommand', | ||
' anothercommand [options]', | ||
'' | ||
].join('\n'); | ||
|
||
program.helpInformation().should.equal(expectedHelpInformation); | ||
|
||
// Test arguments | ||
var expectedCommandHelpInformation = [ | ||
'Usage: test [options] [command]', | ||
'', | ||
'Options:', | ||
' -c, --HELP custom help output', | ||
'', | ||
'Commands:', | ||
' somecommand', | ||
' anothercommand [options]', | ||
'' | ||
].join('\n'); | ||
|
||
program.parse(['node', 'test', '--HELP']); | ||
|
||
process.stdout.write.called.should.equal(true); | ||
|
||
var output = process.stdout.write.args[0]; | ||
output[0].should.equal(expectedCommandHelpInformation); | ||
|
||
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
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 | ||
.helpOption('-i, --ihelp', 'foo foo'); | ||
|
||
program | ||
.command('child') | ||
.option('--gender', 'specific gender of child') | ||
.action((cmd) => { | ||
console.log('Childsubcommand...'); | ||
}); | ||
|
||
program | ||
.command('family') | ||
.helpOption('-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var program = require('../') | ||
, sinon = require('sinon').sandbox.create() | ||
, should = require('should'); | ||
|
||
program.version('1.0.0', undefined, 'custom version output'); | ||
program.command('somecommand'); | ||
program.command('anothercommand [options]'); | ||
|
||
var expectedHelpInformation = [ | ||
'Usage: [options] [command]', | ||
'', | ||
'Options:', | ||
' -V, --version custom version output', | ||
' -h, --help output usage information', | ||
'', | ||
'Commands:', | ||
' somecommand', | ||
' anothercommand [options]', | ||
'' | ||
].join('\n'); | ||
|
||
program.helpInformation().should.equal(expectedHelpInformation); |
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