forked from tj/commander.js
/
test.command.nohelp.js
56 lines (42 loc) · 1.7 KB
/
test.command.nohelp.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
var program = require('../')
, sinon = require('sinon').sandbox.create()
, should = require('should');
sinon.stub(process, 'exit');
sinon.stub(process.stdout, 'write');
program.command('mycommand [options]', 'this is my command');
program
.command('anothercommand [options]')
.action(function() { return; });
program.command('hiddencommand [options]', 'you won\'t see me', { noHelp: true });
program
.command('hideagain [options]', null, { noHelp: true })
.action(function() { return; });
program.command('hiddencommandwithoutdescription [options]', { noHelp: true });
program.parse(['node', 'test']);
program.name.should.be.a.Function();
program.name().should.equal('test');
program.commands[0].name().should.equal('mycommand');
program.commands[0]._noHelp.should.be.false();
program.commands[1].name().should.equal('anothercommand');
program.commands[1]._noHelp.should.be.false();
program.commands[2].name().should.equal('hiddencommand');
program.commands[2]._noHelp.should.be.true();
program.commands[3].name().should.equal('hideagain');
program.commands[3]._noHelp.should.be.true();
program.commands[4].name().should.equal('hiddencommandwithoutdescription');
program.commands[4]._noHelp.should.be.true();
program.commands[5].name().should.equal('help');
sinon.restore();
sinon.stub(process.stdout, 'write');
program.outputHelp();
process.stdout.write.calledOnce.should.be.true();
process.stdout.write.args.length.should.equal(1);
var output = process.stdout.write.args[0];
var expect = [
' Commands:',
'',
' mycommand [options] this is my command',
' anothercommand [options]',
' help [cmd] display help for [cmd]'
].join('\n');
output[0].indexOf(expect).should.not.be.equal(-1);