@oclif/core 1.3.4 → 1.4.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.
- package/CHANGELOG.md +21 -0
- package/lib/command.d.ts +4 -2
- package/lib/command.js +16 -7
- package/lib/parser/parse.js +1 -5
- package/lib/parser/validate.js +3 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.4.0](https://github.com/oclif/core/compare/v1.3.6...v1.4.0) (2022-03-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* make global flags settable ([#385](https://github.com/oclif/core/issues/385)) ([e14061c](https://github.com/oclif/core/commit/e14061ca7e6a4c288eb50e0e9954b38e042682df))
|
|
11
|
+
|
|
12
|
+
### [1.3.6](https://github.com/oclif/core/compare/v1.3.5...v1.3.6) (2022-02-28)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* parsing the default is wrong types ([ba08723](https://github.com/oclif/core/commit/ba087237773e6f4b3649d03dc88f693a22681de9))
|
|
18
|
+
|
|
19
|
+
### [1.3.5](https://github.com/oclif/core/compare/v1.3.4...v1.3.5) (2022-02-25)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* print valid flag values in error message when using `exactlyOne` ([#349](https://github.com/oclif/core/issues/349)) ([ddcaeb2](https://github.com/oclif/core/commit/ddcaeb2f9b690d9b92dd0ac4937b6399f606adfa))
|
|
25
|
+
|
|
5
26
|
### [1.3.4](https://github.com/oclif/core/compare/v1.3.3...v1.3.4) (2022-02-11)
|
|
6
27
|
|
|
7
28
|
|
package/lib/command.d.ts
CHANGED
|
@@ -63,9 +63,11 @@ export default abstract class Command {
|
|
|
63
63
|
* @param {Interfaces.LoadOptions} opts options
|
|
64
64
|
*/
|
|
65
65
|
static run: Interfaces.Command.Class['run'];
|
|
66
|
-
|
|
66
|
+
protected static _globalFlags: Interfaces.FlagInput<any>;
|
|
67
|
+
static get globalFlags(): Interfaces.FlagInput<any>;
|
|
68
|
+
static set globalFlags(flags: Interfaces.FlagInput<any>);
|
|
67
69
|
/** A hash of flags for the command */
|
|
68
|
-
|
|
70
|
+
protected static _flags: Interfaces.FlagInput<any>;
|
|
69
71
|
static get flags(): Interfaces.FlagInput<any>;
|
|
70
72
|
static set flags(flags: Interfaces.FlagInput<any>);
|
|
71
73
|
id: string | undefined;
|
package/lib/command.js
CHANGED
|
@@ -17,6 +17,12 @@ process.stdout.on('error', (err) => {
|
|
|
17
17
|
return;
|
|
18
18
|
throw err;
|
|
19
19
|
});
|
|
20
|
+
const jsonFlag = {
|
|
21
|
+
json: Flags.boolean({
|
|
22
|
+
description: 'Format output as json.',
|
|
23
|
+
helpGroup: 'GLOBAL',
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
20
26
|
/**
|
|
21
27
|
* An abstract class which acts as the base for each command
|
|
22
28
|
* in your project.
|
|
@@ -33,11 +39,20 @@ class Command {
|
|
|
33
39
|
this.debug = () => { };
|
|
34
40
|
}
|
|
35
41
|
}
|
|
42
|
+
static get globalFlags() {
|
|
43
|
+
return this._globalFlags;
|
|
44
|
+
}
|
|
45
|
+
static set globalFlags(flags) {
|
|
46
|
+
this._globalFlags = this.enableJsonFlag ?
|
|
47
|
+
Object.assign({}, jsonFlag, this.globalFlags, flags) :
|
|
48
|
+
Object.assign({}, this.globalFlags, flags);
|
|
49
|
+
}
|
|
36
50
|
static get flags() {
|
|
37
51
|
return this._flags;
|
|
38
52
|
}
|
|
39
53
|
static set flags(flags) {
|
|
40
|
-
this.
|
|
54
|
+
this.globalFlags = {};
|
|
55
|
+
this._flags = Object.assign({}, this.globalFlags, flags);
|
|
41
56
|
}
|
|
42
57
|
get ctor() {
|
|
43
58
|
return this.constructor;
|
|
@@ -169,9 +184,3 @@ Command.run = async function (argv, opts) {
|
|
|
169
184
|
const cmd = new this(argv, config);
|
|
170
185
|
return cmd._run(argv);
|
|
171
186
|
};
|
|
172
|
-
Command.globalFlags = {
|
|
173
|
-
json: Flags.boolean({
|
|
174
|
-
description: 'Format output as json.',
|
|
175
|
-
helpGroup: 'GLOBAL',
|
|
176
|
-
}),
|
|
177
|
-
};
|
package/lib/parser/parse.js
CHANGED
|
@@ -181,11 +181,7 @@ class Parser {
|
|
|
181
181
|
this.metaData.flags[k] = { setFromDefault: true };
|
|
182
182
|
// eslint-disable-next-line no-await-in-loop
|
|
183
183
|
const defaultValue = (typeof flag.default === 'function' ? await flag.default({ options: flag, flags, ...this.context }) : flag.default);
|
|
184
|
-
|
|
185
|
-
// eslint-disable-next-line no-await-in-loop
|
|
186
|
-
await flag.parse(defaultValue, this.context) :
|
|
187
|
-
defaultValue;
|
|
188
|
-
flags[k] = parsedValue;
|
|
184
|
+
flags[k] = defaultValue;
|
|
189
185
|
}
|
|
190
186
|
}
|
|
191
187
|
return flags;
|
package/lib/parser/validate.js
CHANGED
|
@@ -30,6 +30,7 @@ function validate(parse) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
function validateAcrossFlags(flag) {
|
|
33
|
+
var _a;
|
|
33
34
|
const intersection = Object.entries(parse.input.flags)
|
|
34
35
|
.map(entry => entry[0]) // array of flag names
|
|
35
36
|
.filter(flagName => parse.output.flags[flagName] !== undefined) // with values
|
|
@@ -37,8 +38,8 @@ function validate(parse) {
|
|
|
37
38
|
if (intersection.length === 0) {
|
|
38
39
|
// the command's exactlyOne may or may not include itself, so we'll use Set to add + de-dupe
|
|
39
40
|
throw new errors_1.CLIError(`Exactly one of the following must be provided: ${[
|
|
40
|
-
...new Set(
|
|
41
|
-
].join(',')}`);
|
|
41
|
+
...new Set((_a = flag.exactlyOne) === null || _a === void 0 ? void 0 : _a.map(flag => `--${flag}`)),
|
|
42
|
+
].join(', ')}`);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
function validateFlags() {
|