@oclif/core 4.0.36 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -167,6 +167,10 @@ export type FlagProps = {
167
167
  * This is helpful if the default value contains sensitive data that shouldn't be published to npm.
168
168
  */
169
169
  noCacheDefault?: boolean;
170
+ /**
171
+ * At least one of these flags must be provided.
172
+ */
173
+ atLeastOne?: string[];
170
174
  };
171
175
  export type ArgProps = {
172
176
  name: string;
@@ -64,7 +64,10 @@ async function validate(parse) {
64
64
  return [{ name, reason: `Missing required flag ${name}`, status: 'failed', validationFn: 'required' }];
65
65
  }
66
66
  if (flag.exactlyOne && flag.exactlyOne.length > 0) {
67
- return [validateAcrossFlags(flag)];
67
+ return [validateExactlyOneAcrossFlags(flag)];
68
+ }
69
+ if (flag.atLeastOne && flag.atLeastOne.length > 0) {
70
+ return [validateAtLeastOneAcrossFlags(flag)];
68
71
  }
69
72
  return [];
70
73
  });
@@ -91,8 +94,8 @@ async function validate(parse) {
91
94
  return cachedResolvedFlags;
92
95
  }
93
96
  const getPresentFlags = (flags) => Object.keys(flags).filter((key) => key !== undefined);
94
- function validateAcrossFlags(flag) {
95
- const base = { name: flag.name, validationFn: 'validateAcrossFlags' };
97
+ function validateExactlyOneAcrossFlags(flag) {
98
+ const base = { name: flag.name, validationFn: 'validateExactlyOneAcrossFlags' };
96
99
  const intersection = Object.entries(parse.input.flags)
97
100
  .map((entry) => entry[0]) // array of flag names
98
101
  .filter((flagName) => parse.output.flags[flagName] !== undefined) // with values
@@ -105,6 +108,20 @@ async function validate(parse) {
105
108
  }
106
109
  return { ...base, status: 'success' };
107
110
  }
111
+ function validateAtLeastOneAcrossFlags(flag) {
112
+ const base = { name: flag.name, validationFn: 'validateAtLeastOneAcrossFlags' };
113
+ const intersection = Object.entries(parse.input.flags)
114
+ .map((entry) => entry[0]) // array of flag names
115
+ .filter((flagName) => parse.output.flags[flagName] !== undefined) // with values
116
+ .filter((flagName) => flag.atLeastOne && flag.atLeastOne.includes(flagName)); // and in the atLeastOne list
117
+ if (intersection.length === 0) {
118
+ // the command's atLeastOne may or may not include itself, so we'll use Set to add + de-dupe
119
+ const deduped = (0, util_1.uniq)(flag.atLeastOne?.map((flag) => `--${flag}`) ?? []).join(', ');
120
+ const reason = `At least one of the following must be provided: ${deduped}`;
121
+ return { ...base, reason, status: 'failed' };
122
+ }
123
+ return { ...base, status: 'success' };
124
+ }
108
125
  async function validateExclusive(name, flags) {
109
126
  const base = { name, validationFn: 'validateExclusive' };
110
127
  const resolved = await resolveFlags(flags);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "4.0.36",
4
+ "version": "4.1.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -51,7 +51,7 @@
51
51
  "cross-env": "^7.0.3",
52
52
  "eslint": "^8.57.1",
53
53
  "eslint-config-oclif": "^5.2.2",
54
- "eslint-config-oclif-typescript": "^3.1.12",
54
+ "eslint-config-oclif-typescript": "^3.1.13",
55
55
  "eslint-config-prettier": "^9.1.0",
56
56
  "husky": "^9.1.7",
57
57
  "lint-staged": "^15",