Skip to content

Commit

Permalink
fix bug when description is add after command with options (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
AMoreaux authored and abetomo committed Aug 7, 2017
1 parent df3b529 commit 5c74431
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -155,6 +155,10 @@ Command.prototype.__proto__ = EventEmitter.prototype;
*/

Command.prototype.command = function(name, desc, opts) {
if(typeof desc === 'object' && desc !== null){
opts = desc;
desc = null;
}
opts = opts || {};
var args = name.split(/ +/);
var cmd = new Command(args.shift());
Expand All @@ -165,7 +169,6 @@ Command.prototype.command = function(name, desc, opts) {
this._execs[cmd._name] = true;
if (opts.isDefault) this.defaultExecutable = cmd._name;
}

cmd._noHelp = !!opts.noHelp;
this.commands.push(cmd);
cmd.parseExpectedArgs(args);
Expand Down
47 changes: 41 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions test/test.command.nohelp.js
Expand Up @@ -17,19 +17,25 @@ 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.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[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('help');
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');
Expand Down

0 comments on commit 5c74431

Please sign in to comment.