From 7fd93dcf7ef4b5f7075bdd5c92b4e11630a9bb4d Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 17 Jul 2020 15:22:50 +0530 Subject: [PATCH] fix: assignment of negate property --- index.js | 2 +- tests/options.opts.test.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 987b79f0d..5dedbb388 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ class Option { this.required = flags.indexOf('<') >= 0; // A value must be supplied when the option is specified. this.optional = flags.indexOf('[') >= 0; // A value is optional when the option is specified. this.mandatory = false; // The option must have a value after parsing, which usually means it must be specified on command line. - this.negate = flags.indexOf('-no-') !== -1; + this.negate = flags.indexOf('--no-') !== -1; const flagParts = flags.split(/[ ,|]+/); if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1])) this.short = flagParts.shift(); this.long = flagParts.shift(); diff --git a/tests/options.opts.test.js b/tests/options.opts.test.js index 337a909e2..4e2617ffe 100644 --- a/tests/options.opts.test.js +++ b/tests/options.opts.test.js @@ -70,4 +70,13 @@ describe.each([true, false])('storeOptionsAsProperties is %s', (storeOptionsAsPr program.parse(['node', 'test']); expect(program.opts()).toEqual({ pepper: pepperDefault }); }); + + test('when option with name including no- is specified then it should not have default value as true', () => { + const program = new commander.Command(); + program.storeOptionsAsProperties(storeOptionsAsProperties); + program + .option('--module-no-parse ', 'test description'); + program.parse(['node', 'test']); + expect(program.opts()).toEqual({}); + }); });