@oclif/core
Advanced tools
Comparing version 4.0.37 to 4.1.0
@@ -170,2 +170,6 @@ import { Command } from '../command'; | ||
noCacheDefault?: boolean; | ||
/** | ||
* At least one of these flags must be provided. | ||
*/ | ||
atLeastOne?: string[]; | ||
}; | ||
@@ -172,0 +176,0 @@ export type ArgProps = { |
@@ -67,4 +67,7 @@ "use strict"; | ||
if (flag.exactlyOne && flag.exactlyOne.length > 0) { | ||
return [validateAcrossFlags(flag)]; | ||
return [validateExactlyOneAcrossFlags(flag)]; | ||
} | ||
if (flag.atLeastOne && flag.atLeastOne.length > 0) { | ||
return [validateAtLeastOneAcrossFlags(flag)]; | ||
} | ||
return []; | ||
@@ -95,4 +98,4 @@ }); | ||
const getPresentFlags = (flags) => Object.keys(flags).filter((key) => key !== undefined); | ||
function validateAcrossFlags(flag) { | ||
const base = { name: flag.name, validationFn: 'validateAcrossFlags' }; | ||
function validateExactlyOneAcrossFlags(flag) { | ||
const base = { name: flag.name, validationFn: 'validateExactlyOneAcrossFlags' }; | ||
const intersection = Object.entries(parse.input.flags) | ||
@@ -110,2 +113,16 @@ .map((entry) => entry[0]) // array of flag names | ||
} | ||
function validateAtLeastOneAcrossFlags(flag) { | ||
const base = { name: flag.name, validationFn: 'validateAtLeastOneAcrossFlags' }; | ||
const intersection = Object.entries(parse.input.flags) | ||
.map((entry) => entry[0]) // array of flag names | ||
.filter((flagName) => parse.output.flags[flagName] !== undefined) // with values | ||
.filter((flagName) => flag.atLeastOne && flag.atLeastOne.includes(flagName)); // and in the atLeastOne list | ||
if (intersection.length === 0) { | ||
// the command's atLeastOne may or may not include itself, so we'll use Set to add + de-dupe | ||
const deduped = (0, util_1.uniq)(flag.atLeastOne?.map((flag) => `--${flag}`) ?? []).join(', '); | ||
const reason = `At least one of the following must be provided: ${deduped}`; | ||
return { ...base, reason, status: 'failed' }; | ||
} | ||
return { ...base, status: 'success' }; | ||
} | ||
async function validateExclusive(name, flags) { | ||
@@ -112,0 +129,0 @@ const base = { name, validationFn: 'validateExclusive' }; |
{ | ||
"name": "@oclif/core", | ||
"description": "base library for oclif CLIs", | ||
"version": "4.0.37", | ||
"version": "4.1.0", | ||
"author": "Salesforce", | ||
@@ -54,3 +54,3 @@ "bugs": "https://github.com/oclif/core/issues", | ||
"eslint-config-oclif": "^5.2.2", | ||
"eslint-config-oclif-typescript": "^3.1.12", | ||
"eslint-config-oclif-typescript": "^3.1.13", | ||
"eslint-config-prettier": "^9.1.0", | ||
@@ -57,0 +57,0 @@ "husky": "^9.1.7", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
405895
10208