From 5c7443192447471290ccd9a5d205d1c361c5b998 Mon Sep 17 00:00:00 2001 From: Antoine Moreaux Date: Mon, 7 Aug 2017 06:14:29 +0200 Subject: [PATCH] fix bug when description is add after command with options (#662) --- index.js | 5 +++- package-lock.json | 47 ++++++++++++++++++++++++++++++++----- test/test.command.nohelp.js | 12 +++++++--- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index aacce61d5..4ca2829b6 100644 --- a/index.js +++ b/index.js @@ -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()); @@ -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); diff --git a/package-lock.json b/package-lock.json index 5924df1a3..f2459508d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7 +1,8 @@ { "name": "commander", - "version": "2.10.0", + "version": "2.11.0", "lockfileVersion": 1, + "requires": true, "dependencies": { "diff": { "version": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz", @@ -11,7 +12,10 @@ "formatio": { "version": "https://registry.npmjs.org/formatio/-/formatio-1.2.0.tgz", "integrity": "sha1-87IWfZBoxGmKjVH092CjmlTYGOs=", - "dev": true + "dev": true, + "requires": { + "samsam": "https://registry.npmjs.org/samsam/-/samsam-1.2.1.tgz" + } }, "isarray": { "version": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", @@ -31,7 +35,10 @@ "path-to-regexp": { "version": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz", "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=", - "dev": true + "dev": true, + "requires": { + "isarray": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz" + } }, "samsam": { "version": "https://registry.npmjs.org/samsam/-/samsam-1.2.1.tgz", @@ -43,18 +50,32 @@ "resolved": "https://registry.npmjs.org/should/-/should-11.2.1.tgz", "integrity": "sha1-kPVRRVUtAc/CAGZuToGKHJZw7aI=", "dev": true, + "requires": { + "should-equal": "1.0.1", + "should-format": "3.0.3", + "should-type": "1.4.0", + "should-type-adaptors": "1.0.1", + "should-util": "1.0.0" + }, "dependencies": { "should-equal": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/should-equal/-/should-equal-1.0.1.tgz", "integrity": "sha1-C26VFvJgGp+wuy3MNpr6HH4gCvc=", - "dev": true + "dev": true, + "requires": { + "should-type": "1.4.0" + } }, "should-format": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/should-format/-/should-format-3.0.3.tgz", "integrity": "sha1-m/yPdPo5IFxT04w01xcwPidxJPE=", - "dev": true + "dev": true, + "requires": { + "should-type": "1.4.0", + "should-type-adaptors": "1.0.1" + } }, "should-type": { "version": "1.4.0", @@ -69,6 +90,10 @@ "resolved": "https://registry.npmjs.org/should-type-adaptors/-/should-type-adaptors-1.0.1.tgz", "integrity": "sha1-7+VVPN9oz/ZuXF9RtxLcNRx3vqo=", "dev": true, + "requires": { + "should-type": "1.4.0", + "should-util": "1.0.0" + }, "dependencies": { "should-type": { "version": "1.4.0", @@ -88,7 +113,17 @@ "version": "2.3.5", "resolved": "https://registry.npmjs.org/sinon/-/sinon-2.3.5.tgz", "integrity": "sha1-mi/A/41SbacW8wlTqixl1RiRf2w=", - "dev": true + "dev": true, + "requires": { + "diff": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz", + "formatio": "https://registry.npmjs.org/formatio/-/formatio-1.2.0.tgz", + "lolex": "https://registry.npmjs.org/lolex/-/lolex-1.6.0.tgz", + "native-promise-only": "https://registry.npmjs.org/native-promise-only/-/native-promise-only-0.8.1.tgz", + "path-to-regexp": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz", + "samsam": "https://registry.npmjs.org/samsam/-/samsam-1.2.1.tgz", + "text-encoding": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz", + "type-detect": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.0.tgz" + } }, "text-encoding": { "version": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz", diff --git a/test/test.command.nohelp.js b/test/test.command.nohelp.js index e8f3d27d4..247d6756e 100644 --- a/test/test.command.nohelp.js +++ b/test/test.command.nohelp.js @@ -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');