Skip to content

Commit

Permalink
refactor: make isDefaulted private (#2188)
Browse files Browse the repository at this point in the history
Co-authored-by: Landon Yarrington <33426811+jly36963@users.noreply.github.com>
  • Loading branch information
bcoe and jly36963 committed May 16, 2022
1 parent b672e70 commit 2109bd6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
25 changes: 23 additions & 2 deletions lib/command.ts
Expand Up @@ -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]))
Expand All @@ -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<unknown> {
if (!this.defaultCommand) return;
if (this.shouldUpdateUsage(yargs)) {
Expand Down
24 changes: 0 additions & 24 deletions lib/yargs-factory.ts
Expand Up @@ -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) {
Expand Down

0 comments on commit 2109bd6

Please sign in to comment.