forked from tj/commander.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.command.helpSubCommand.customFlags.js
65 lines (50 loc) · 1.41 KB
/
test.command.helpSubCommand.customFlags.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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();