Skip to content

Commit

Permalink
Rename defValue to default
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jan 4, 2020
1 parent 0d250ad commit 1e0db9c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ module.exports = class Command {
createOptionValues(values) {
const storage = Object.create(null);

for (const { name, normalize, defValue } of this.getOptions()) {
if (typeof defValue !== 'undefined') {
storage[name] = normalize(defValue);
for (const { name, normalize, default: value } of this.getOptions()) {
if (typeof value !== 'undefined') {
storage[name] = normalize(value);
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const self = value => value;
module.exports = class Option {
static normalizeOptions(opt1, opt2) {
const raw = typeof opt1 === 'function'
? { normalize: opt1, value: opt2 }
? { normalize: opt1, default: opt2 }
: opt1 && typeof opt1 === 'object'
? opt1
: { value: opt1 };
: { default: opt1 };

return {
defValue: !ensureFunction(raw.action) ? raw.value : undefined,
default: !ensureFunction(raw.action) ? raw.default : undefined,
normalize: ensureFunction(raw.normalize, self),
shortcut: ensureFunction(raw.shortcut),
action: ensureFunction(raw.action),
Expand Down Expand Up @@ -58,7 +58,7 @@ module.exports = class Option {

// ignore defValue from config for boolean options
if (typeof defValue === 'boolean' && !this.action) {
this.defValue = defValue;
this.default = defValue;
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/parse-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function consumeOptionParams(option, rawOptions, argv, index, suggestPoint) {

value = option.params.maxCount === 1 ? tokens[0] : tokens;
} else {
value = !option.defValue;
value = !option.default;
}

rawOptions.push({
Expand Down Expand Up @@ -115,7 +115,7 @@ module.exports = function parseArgv(command, argv, context, suggestMode) {

rawOptions.push({
option,
value: !option.defValue
value: !option.default
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/command-createOptionValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('createOptionValues()', function() {
const command = cli.command()
.option('--foo <value>', '', Number)
.option('--bar [value]')
.option('--with-default [x]', '', { value: 'default' })
.option('--with-default [x]', '', { default: 'default' })
.option('--bool');

assert.deepStrictEqual(
Expand Down

0 comments on commit 1e0db9c

Please sign in to comment.