Skip to content

Commit

Permalink
Fix to emit the action even without command (#778)
Browse files Browse the repository at this point in the history
* Fix to emit the action even without command

* Fix to emit the action even without command
  • Loading branch information
abetomo authored and roman-vanesyan committed Jul 17, 2018
1 parent 2d49ddf commit 28ff02a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Expand Up @@ -660,6 +660,9 @@ Command.prototype.parseArgs = function(args, unknown) {
if (unknown.length > 0) {
this.unknownOption(unknown[0]);
}
if (this._args.filter(a => a.required).length === 0) {
this.emit('command:*');
}
}

return this;
Expand Down
13 changes: 13 additions & 0 deletions test/test.noCommand.action.js
@@ -0,0 +1,13 @@
var program = require('../')
, should = require('should');

var val = false;
program
.option('-C, --no-color', 'turn off color output')
.action(function () {
val = this.color;
});

program.parse(['node', 'test']);

program.color.should.equal(val);

0 comments on commit 28ff02a

Please sign in to comment.