From 1e0db9c643b239bf046cd1c5a60d89606d90f31d Mon Sep 17 00:00:00 2001 From: Roman Dvornov Date: Sun, 5 Jan 2020 01:01:45 +0300 Subject: [PATCH] Rename defValue to default --- lib/command.js | 6 +++--- lib/option.js | 8 ++++---- lib/parse-argv.js | 4 ++-- test/command-createOptionValues.js | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/command.js b/lib/command.js index fc0cdcc..df917af 100644 --- a/lib/command.js +++ b/lib/command.js @@ -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); } } diff --git a/lib/option.js b/lib/option.js index f46df0d..c06dcf5 100644 --- a/lib/option.js +++ b/lib/option.js @@ -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), @@ -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; } } diff --git a/lib/parse-argv.js b/lib/parse-argv.js index 4f25c29..1816463 100644 --- a/lib/parse-argv.js +++ b/lib/parse-argv.js @@ -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({ @@ -115,7 +115,7 @@ module.exports = function parseArgv(command, argv, context, suggestMode) { rawOptions.push({ option, - value: !option.defValue + value: !option.default }); } } diff --git a/test/command-createOptionValues.js b/test/command-createOptionValues.js index dbef742..d75ea62 100644 --- a/test/command-createOptionValues.js +++ b/test/command-createOptionValues.js @@ -72,7 +72,7 @@ describe('createOptionValues()', function() { const command = cli.command() .option('--foo ', '', Number) .option('--bar [value]') - .option('--with-default [x]', '', { value: 'default' }) + .option('--with-default [x]', '', { default: 'default' }) .option('--bool'); assert.deepStrictEqual(