Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make isDefaulted private #2188

Merged
merged 2 commits into from May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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