@oclif/core 4.0.37 → 4.1.1
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.
- package/lib/interfaces/parser.d.ts +4 -0
- package/lib/parser/validate.js +20 -3
- package/lib/ux/index.d.ts +1 -0
- package/lib/ux/index.js +3 -2
- package/package.json +2 -2
|
@@ -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;
|
package/lib/parser/validate.js
CHANGED
|
@@ -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 [
|
|
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
|
|
95
|
-
const base = { name: flag.name, validationFn: '
|
|
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/lib/ux/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { warn } from '../errors/warn';
|
|
|
11
11
|
export { default as colorizeJson } from './colorize-json';
|
|
12
12
|
export { colorize } from './theme';
|
|
13
13
|
export { stderr, stdout } from './write';
|
|
14
|
+
export declare const action: Simple | Spinner;
|
|
14
15
|
export declare const ux: {
|
|
15
16
|
action: Simple | Spinner;
|
|
16
17
|
/**
|
package/lib/ux/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ux = exports.stdout = exports.stderr = exports.colorize = exports.colorizeJson = exports.warn = exports.exit = exports.error = void 0;
|
|
6
|
+
exports.ux = exports.action = exports.stdout = exports.stderr = exports.colorize = exports.colorizeJson = exports.warn = exports.exit = exports.error = void 0;
|
|
7
7
|
const error_1 = require("../errors/error");
|
|
8
8
|
const exit_1 = require("../errors/exit");
|
|
9
9
|
const warn_1 = require("../errors/warn");
|
|
@@ -30,8 +30,9 @@ const ACTION_TYPE = (Boolean(process.stderr.isTTY) &&
|
|
|
30
30
|
!['dumb', 'emacs-color'].includes(process.env.TERM) &&
|
|
31
31
|
'spinner') ||
|
|
32
32
|
'simple';
|
|
33
|
+
exports.action = ACTION_TYPE === 'spinner' ? new spinner_1.default() : new simple_1.default();
|
|
33
34
|
exports.ux = {
|
|
34
|
-
action:
|
|
35
|
+
action: exports.action,
|
|
35
36
|
/**
|
|
36
37
|
* Add color to text.
|
|
37
38
|
* @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a standard ansi color (e.g. `red`)
|
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.
|
|
4
|
+
"version": "4.1.1",
|
|
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.
|
|
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",
|