From 917e3c68b26fe6f059994e70587ce0d74093a5df Mon Sep 17 00:00:00 2001 From: abetomo Date: Fri, 9 Mar 2018 19:43:38 +0900 Subject: [PATCH 1/2] Fix to emit the action even without command --- index.js | 3 +++ test/test.noCommand.action.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 test/test.noCommand.action.js diff --git a/index.js b/index.js index fb648beec..c890b4478 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/test/test.noCommand.action.js b/test/test.noCommand.action.js new file mode 100644 index 000000000..ae4aecc66 --- /dev/null +++ b/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); From 7209147de82dac781aab85a1bb62e13abb9339b3 Mon Sep 17 00:00:00 2001 From: abetomo Date: Fri, 9 Mar 2018 19:49:35 +0900 Subject: [PATCH 2/2] Fix to emit the action even without command --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index c890b4478..52df38ca2 100644 --- a/index.js +++ b/index.js @@ -660,7 +660,7 @@ Command.prototype.parseArgs = function(args, unknown) { if (unknown.length > 0) { this.unknownOption(unknown[0]); } - if (this._args.filter(a => a.required).length == 0) { + if (this._args.filter(a => a.required).length === 0) { this.emit('command:*'); } }