@oclif/core 1.13.11 → 1.14.2
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/flags.d.ts +17 -2
- package/lib/flags.js +4 -3
- package/lib/parser/flags.d.ts +1 -1
- package/lib/parser/flags.js +15 -3
- package/lib/parser/parse.d.ts +1 -0
- package/lib/parser/parse.js +9 -5
- 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.14.2](https://github.com/oclif/core/compare/v1.14.1...v1.14.2) (2022-08-18)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* add overloads to enum flag ([799455b](https://github.com/oclif/core/commit/799455bbb526b221c806bf8feff6b625dcf50a56))
|
|
11
|
+
|
|
12
|
+
### [1.14.1](https://github.com/oclif/core/compare/v1.14.0...v1.14.1) (2022-08-16)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* parser doesn't validate against options parameter if the value is provided through a env var ([#474](https://github.com/oclif/core/issues/474)) ([fe6dfea](https://github.com/oclif/core/commit/fe6dfea0bcc5cae69c91962430996670decf7887))
|
|
18
|
+
|
|
19
|
+
## [1.14.0](https://github.com/oclif/core/compare/v1.13.11...v1.14.0) (2022-08-16)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* all oclif flag types support custom parsers ([ad86faf](https://github.com/oclif/core/commit/ad86faf08f7a6d7984afe356819df458aaf04674))
|
|
25
|
+
|
|
5
26
|
### [1.13.11](https://github.com/oclif/core/compare/v1.13.10...v1.13.11) (2022-08-16)
|
|
6
27
|
|
|
7
28
|
|
package/lib/flags.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OptionFlag, Definition, BooleanFlag, EnumFlagOptions } from './interfaces';
|
|
1
|
+
import { OptionFlag, Definition, BooleanFlag, EnumFlagOptions, Default } from './interfaces';
|
|
2
2
|
export declare function build<T>(defaults: {
|
|
3
3
|
parse: OptionFlag<T>['parse'];
|
|
4
4
|
} & Partial<OptionFlag<T>>): Definition<T>;
|
|
@@ -6,7 +6,22 @@ export declare function build(defaults: Partial<OptionFlag<string>>): Definition
|
|
|
6
6
|
export declare function option<T>(options: {
|
|
7
7
|
parse: OptionFlag<T>['parse'];
|
|
8
8
|
} & Partial<OptionFlag<T>>): OptionFlag<T | undefined>;
|
|
9
|
-
declare
|
|
9
|
+
export declare function _enum<T = string>(opts: EnumFlagOptions<T> & {
|
|
10
|
+
multiple: true;
|
|
11
|
+
} & ({
|
|
12
|
+
required: true;
|
|
13
|
+
} | {
|
|
14
|
+
default: Default<T>;
|
|
15
|
+
})): OptionFlag<T[]>;
|
|
16
|
+
export declare function _enum<T = string>(opts: EnumFlagOptions<T> & {
|
|
17
|
+
multiple: true;
|
|
18
|
+
}): OptionFlag<T[] | undefined>;
|
|
19
|
+
export declare function _enum<T = string>(opts: EnumFlagOptions<T> & ({
|
|
20
|
+
required: true;
|
|
21
|
+
} | {
|
|
22
|
+
default: Default<T>;
|
|
23
|
+
})): OptionFlag<T>;
|
|
24
|
+
export declare function _enum<T = string>(opts: EnumFlagOptions<T>): OptionFlag<T | undefined>;
|
|
10
25
|
export { _enum as enum };
|
|
11
26
|
declare const stringFlag: Definition<string>;
|
|
12
27
|
export { stringFlag as string };
|
package/lib/flags.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.help = exports.version = exports.file = exports.directory = exports.url = exports.integer = exports.boolean = exports.string = exports.enum = exports.option = exports.build = void 0;
|
|
3
|
+
exports.help = exports.version = exports.file = exports.directory = exports.url = exports.integer = exports.boolean = exports.string = exports.enum = exports._enum = exports.option = exports.build = void 0;
|
|
4
4
|
const Parser = require("./parser");
|
|
5
5
|
function build(defaults) {
|
|
6
6
|
return Parser.flags.build(defaults);
|
|
@@ -10,7 +10,7 @@ function option(options) {
|
|
|
10
10
|
return build(options)();
|
|
11
11
|
}
|
|
12
12
|
exports.option = option;
|
|
13
|
-
|
|
13
|
+
function _enum(opts) {
|
|
14
14
|
return build({
|
|
15
15
|
async parse(input) {
|
|
16
16
|
if (!opts.options.includes(input))
|
|
@@ -20,7 +20,8 @@ const _enum = (opts) => {
|
|
|
20
20
|
helpValue: `(${opts.options.join('|')})`,
|
|
21
21
|
...opts,
|
|
22
22
|
})();
|
|
23
|
-
}
|
|
23
|
+
}
|
|
24
|
+
exports._enum = _enum;
|
|
24
25
|
exports.enum = _enum;
|
|
25
26
|
const stringFlag = build({});
|
|
26
27
|
exports.string = stringFlag;
|
package/lib/parser/flags.d.ts
CHANGED
package/lib/parser/flags.js
CHANGED
|
@@ -37,7 +37,7 @@ function integer(opts = {}) {
|
|
|
37
37
|
throw new Error(`Expected an integer greater than or equal to ${opts.min} but received: ${input}`);
|
|
38
38
|
if (opts.max !== undefined && num > opts.max)
|
|
39
39
|
throw new Error(`Expected an integer less than or equal to ${opts.max} but received: ${input}`);
|
|
40
|
-
return num;
|
|
40
|
+
return opts.parse ? opts.parse(input, 1) : num;
|
|
41
41
|
},
|
|
42
42
|
})();
|
|
43
43
|
}
|
|
@@ -45,14 +45,26 @@ exports.integer = integer;
|
|
|
45
45
|
function directory(opts = {}) {
|
|
46
46
|
return build({
|
|
47
47
|
...opts,
|
|
48
|
-
parse: async (input) =>
|
|
48
|
+
parse: async (input) => {
|
|
49
|
+
if (opts.exists) {
|
|
50
|
+
// 2nd "context" arg is required but unused
|
|
51
|
+
return opts.parse ? opts.parse(await dirExists(input), true) : dirExists(input);
|
|
52
|
+
}
|
|
53
|
+
return opts.parse ? opts.parse(input, true) : input;
|
|
54
|
+
},
|
|
49
55
|
})();
|
|
50
56
|
}
|
|
51
57
|
exports.directory = directory;
|
|
52
58
|
function file(opts = {}) {
|
|
53
59
|
return build({
|
|
54
60
|
...opts,
|
|
55
|
-
parse: async (input) =>
|
|
61
|
+
parse: async (input) => {
|
|
62
|
+
if (opts.exists) {
|
|
63
|
+
// 2nd "context" arg is required but unused
|
|
64
|
+
return opts.parse ? opts.parse(await fileExists(input), true) : fileExists(input);
|
|
65
|
+
}
|
|
66
|
+
return opts.parse ? opts.parse(input, true) : input;
|
|
67
|
+
},
|
|
56
68
|
})();
|
|
57
69
|
}
|
|
58
70
|
exports.file = file;
|
package/lib/parser/parse.d.ts
CHANGED
package/lib/parser/parse.js
CHANGED
|
@@ -153,9 +153,7 @@ class Parser {
|
|
|
153
153
|
}
|
|
154
154
|
else {
|
|
155
155
|
const input = token.input;
|
|
156
|
-
|
|
157
|
-
throw new m.errors.FlagInvalidOptionError(flag, input);
|
|
158
|
-
}
|
|
156
|
+
this._validateOptions(flag, input);
|
|
159
157
|
// eslint-disable-next-line no-await-in-loop
|
|
160
158
|
const value = flag.parse ? await flag.parse(input, this.context) : input;
|
|
161
159
|
if (flag.multiple) {
|
|
@@ -173,9 +171,11 @@ class Parser {
|
|
|
173
171
|
continue;
|
|
174
172
|
if (flag.type === 'option' && flag.env) {
|
|
175
173
|
const input = process.env[flag.env];
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
if (input) {
|
|
175
|
+
this._validateOptions(flag, input);
|
|
176
|
+
// eslint-disable-next-line no-await-in-loop
|
|
178
177
|
flags[k] = await flag.parse(input, this.context);
|
|
178
|
+
}
|
|
179
179
|
}
|
|
180
180
|
if (!(k in flags) && flag.default !== undefined) {
|
|
181
181
|
this.metaData.flags[k] = { setFromDefault: true };
|
|
@@ -186,6 +186,10 @@ class Parser {
|
|
|
186
186
|
}
|
|
187
187
|
return flags;
|
|
188
188
|
}
|
|
189
|
+
_validateOptions(flag, input) {
|
|
190
|
+
if (flag.options && !flag.options.includes(input))
|
|
191
|
+
throw new m.errors.FlagInvalidOptionError(flag, input);
|
|
192
|
+
}
|
|
189
193
|
async _argv() {
|
|
190
194
|
const args = [];
|
|
191
195
|
const tokens = this._argTokens;
|