From 2109bd687d4084f41a47a8eea61aacd7ce44f4f0 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Sun, 15 May 2022 20:53:46 -0400 Subject: [PATCH] refactor: make isDefaulted private (#2188) Co-authored-by: Landon Yarrington <33426811+jly36963@users.noreply.github.com> --- lib/command.ts | 25 +++++++++++++++++++++++-- lib/yargs-factory.ts | 24 ------------------------ 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/lib/command.ts b/lib/command.ts index 2d4f462d7..42c0e570b 100644 --- a/lib/command.ts +++ b/lib/command.ts @@ -603,8 +603,8 @@ export class CommandInstance { // and no default or config values were set for that key, // and if at least one is an array: don't overwrite, combine. if ( - !yargs.isInConfigs(key) && - !yargs.isDefaulted(key) && + !this.isInConfigs(yargs, key) && + !this.isDefaulted(yargs, key) && Object.prototype.hasOwnProperty.call(argv, key) && Object.prototype.hasOwnProperty.call(parsed.argv, key) && (Array.isArray(argv[key]) || Array.isArray(parsed.argv[key])) @@ -617,6 +617,27 @@ export class CommandInstance { }); } } + // Check defaults for key (and camel case version of key) + isDefaulted(yargs: YargsInstance, key: string): boolean { + const {default: defaults} = yargs.getOptions(); + return ( + Object.prototype.hasOwnProperty.call(defaults, key) || + Object.prototype.hasOwnProperty.call( + defaults, + this.shim.Parser.camelCase(key) + ) + ); + } + // Check each config for key (and camel case version of key) + isInConfigs(yargs: YargsInstance, key: string): boolean { + const {configObjects} = yargs.getOptions(); + return ( + configObjects.some(c => Object.prototype.hasOwnProperty.call(c, key)) || + configObjects.some(c => + Object.prototype.hasOwnProperty.call(c, this.shim.Parser.camelCase(key)) + ) + ); + } runDefaultBuilderOn(yargs: YargsInstance): unknown | Promise { if (!this.defaultCommand) return; if (this.shouldUpdateUsage(yargs)) { diff --git a/lib/yargs-factory.ts b/lib/yargs-factory.ts index 077a44e3a..c3f88348f 100644 --- a/lib/yargs-factory.ts +++ b/lib/yargs-factory.ts @@ -869,30 +869,6 @@ export class YargsInstance { this.#validation.implies(key, value); return this; } - // Check defaults for key (and camel case version of key) - isDefaulted(key: string): boolean { - const {default: defaults} = this.getOptions(); - return ( - Object.prototype.hasOwnProperty.call(defaults, key) || - Object.prototype.hasOwnProperty.call( - defaults, - this.#shim.Parser.camelCase(key) - ) - ); - } - // Check each config for key (and camel case version of key) - isInConfigs(key: string): boolean { - const {configObjects} = this.getOptions(); - return ( - configObjects.some(c => Object.prototype.hasOwnProperty.call(c, key)) || - configObjects.some(c => - Object.prototype.hasOwnProperty.call( - c, - this.#shim.Parser.camelCase(key) - ) - ) - ); - } locale(locale?: string): YargsInstance | string { argsert('[string]', [locale], arguments.length); if (locale === undefined) {