Skip to content

Commit

Permalink
fix: Recognize falsy values as CLI options defaults (#7071)
Browse files Browse the repository at this point in the history
  • Loading branch information
neverendingqs authored and medikoo committed Dec 13, 2019
1 parent f9b6507 commit 7e0e903
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/classes/PluginManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ class PluginManager {

assignDefaultOptions(command) {
_.forEach(command.options, (value, key) => {
if (value.default && (!this.cliOptions[key] || this.cliOptions[key] === true)) {
if (value.default != null && (!this.cliOptions[key] || this.cliOptions[key] === true)) {
this.cliOptions[key] = value.default;
}
});
Expand Down
20 changes: 20 additions & 0 deletions lib/classes/PluginManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,26 @@ describe('PluginManager', () => {

expect(pluginManager.cliOptions.bar).to.equal(100);
});

[0, '', false].forEach(defaultValue => {
it(`assigns valid falsy default value '${defaultValue} to empty options`, () => {
pluginManager.commands = {
foo: {
options: {
bar: {
required: true,
default: defaultValue,
},
},
},
};

const foo = pluginManager.commands.foo;
pluginManager.assignDefaultOptions(foo);

expect(pluginManager.cliOptions.bar).to.equal(defaultValue);
});
});
});

describe('#validateServerlessConfigDependency()', () => {
Expand Down

0 comments on commit 7e0e903

Please sign in to comment.