diff --git a/lib/command.js b/lib/command.js index 590a271dd..bd0bd7cea 100644 --- a/lib/command.js +++ b/lib/command.js @@ -511,14 +511,14 @@ Expecting one of '${allowedValues.join("', '")}'`); const name = option.attributeName(); // store default value - if (option.negate) { + if (option.defaultValue !== undefined || !option.negate) { + this.setOptionValueWithSource(name, option.defaultValue, 'default'); + } else { // --no-foo is special and defaults foo to true, unless a --foo option is already defined const positiveLongFlag = option.long.replace(/^--no-/, '--'); if (!this._findOption(positiveLongFlag)) { - this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, 'default'); + this.setOptionValueWithSource(name, true, 'default'); } - } else if (option.defaultValue !== undefined) { - this.setOptionValueWithSource(name, option.defaultValue, 'default'); } // register the option