@oclif/core 1.14.0 → 1.15.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 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.15.0](https://github.com/oclif/core/compare/v1.14.2...v1.15.0) (2022-08-23)
6
+
7
+
8
+ ### Features
9
+
10
+ * add InferredFlags type ([#473](https://github.com/oclif/core/issues/473)) ([ee5ce65](https://github.com/oclif/core/commit/ee5ce651899c0ef586d425567ef3b78468dca627))
11
+
12
+ ### [1.14.2](https://github.com/oclif/core/compare/v1.14.1...v1.14.2) (2022-08-18)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * add overloads to enum flag ([799455b](https://github.com/oclif/core/commit/799455bbb526b221c806bf8feff6b625dcf50a56))
18
+
19
+ ### [1.14.1](https://github.com/oclif/core/compare/v1.14.0...v1.14.1) (2022-08-16)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * 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))
25
+
5
26
  ## [1.14.0](https://github.com/oclif/core/compare/v1.13.11...v1.14.0) (2022-08-16)
6
27
 
7
28
 
package/lib/flags.d.ts CHANGED
@@ -1,15 +1,21 @@
1
- import { OptionFlag, Definition, BooleanFlag, EnumFlagOptions } from './interfaces';
2
- export declare function build<T>(defaults: {
3
- parse: OptionFlag<T>['parse'];
4
- } & Partial<OptionFlag<T>>): Definition<T>;
5
- export declare function build(defaults: Partial<OptionFlag<string>>): Definition<string>;
6
- export declare function option<T>(options: {
7
- parse: OptionFlag<T>['parse'];
8
- } & Partial<OptionFlag<T>>): OptionFlag<T | undefined>;
9
- declare const _enum: <T = string>(opts: EnumFlagOptions<T>) => OptionFlag<T>;
1
+ import { OptionFlag, BooleanFlag, EnumFlagOptions, Default } from './interfaces';
2
+ export { boolean, integer, url, directory, file, string, build, option, custom } from './parser';
3
+ export declare function _enum<T = string>(opts: EnumFlagOptions<T, true> & {
4
+ multiple: true;
5
+ } & ({
6
+ required: true;
7
+ } | {
8
+ default: Default<T[]>;
9
+ })): OptionFlag<T[]>;
10
+ export declare function _enum<T = string>(opts: EnumFlagOptions<T, true> & {
11
+ multiple: true;
12
+ }): OptionFlag<T[] | undefined>;
13
+ export declare function _enum<T = string>(opts: EnumFlagOptions<T> & ({
14
+ required: true;
15
+ } | {
16
+ default: Default<T>;
17
+ })): OptionFlag<T>;
18
+ export declare function _enum<T = string>(opts: EnumFlagOptions<T>): OptionFlag<T | undefined>;
10
19
  export { _enum as enum };
11
- declare const stringFlag: Definition<string>;
12
- export { stringFlag as string };
13
- export { boolean, integer, url, directory, file } from './parser';
14
20
  export declare const version: (opts?: Partial<BooleanFlag<boolean>>) => BooleanFlag<void>;
15
21
  export declare const help: (opts?: Partial<BooleanFlag<boolean>>) => BooleanFlag<void>;
package/lib/flags.js CHANGED
@@ -1,17 +1,19 @@
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;
4
- const Parser = require("./parser");
5
- function build(defaults) {
6
- return Parser.flags.build(defaults);
7
- }
8
- exports.build = build;
9
- function option(options) {
10
- return build(options)();
11
- }
12
- exports.option = option;
13
- const _enum = (opts) => {
14
- return build({
3
+ exports.help = exports.version = exports.enum = exports._enum = exports.custom = exports.option = exports.build = exports.string = exports.file = exports.directory = exports.url = exports.integer = exports.boolean = void 0;
4
+ const parser_1 = require("./parser");
5
+ var parser_2 = require("./parser");
6
+ Object.defineProperty(exports, "boolean", { enumerable: true, get: function () { return parser_2.boolean; } });
7
+ Object.defineProperty(exports, "integer", { enumerable: true, get: function () { return parser_2.integer; } });
8
+ Object.defineProperty(exports, "url", { enumerable: true, get: function () { return parser_2.url; } });
9
+ Object.defineProperty(exports, "directory", { enumerable: true, get: function () { return parser_2.directory; } });
10
+ Object.defineProperty(exports, "file", { enumerable: true, get: function () { return parser_2.file; } });
11
+ Object.defineProperty(exports, "string", { enumerable: true, get: function () { return parser_2.string; } });
12
+ Object.defineProperty(exports, "build", { enumerable: true, get: function () { return parser_2.build; } });
13
+ Object.defineProperty(exports, "option", { enumerable: true, get: function () { return parser_2.option; } });
14
+ Object.defineProperty(exports, "custom", { enumerable: true, get: function () { return parser_2.custom; } });
15
+ function _enum(opts) {
16
+ return (0, parser_1.custom)({
15
17
  async parse(input) {
16
18
  if (!opts.options.includes(input))
17
19
  throw new Error(`Expected --${this.name}=${input} to be one of: ${opts.options.join(', ')}`);
@@ -20,18 +22,11 @@ const _enum = (opts) => {
20
22
  helpValue: `(${opts.options.join('|')})`,
21
23
  ...opts,
22
24
  })();
23
- };
25
+ }
26
+ exports._enum = _enum;
24
27
  exports.enum = _enum;
25
- const stringFlag = build({});
26
- exports.string = stringFlag;
27
- var parser_1 = require("./parser");
28
- Object.defineProperty(exports, "boolean", { enumerable: true, get: function () { return parser_1.boolean; } });
29
- Object.defineProperty(exports, "integer", { enumerable: true, get: function () { return parser_1.integer; } });
30
- Object.defineProperty(exports, "url", { enumerable: true, get: function () { return parser_1.url; } });
31
- Object.defineProperty(exports, "directory", { enumerable: true, get: function () { return parser_1.directory; } });
32
- Object.defineProperty(exports, "file", { enumerable: true, get: function () { return parser_1.file; } });
33
28
  const version = (opts = {}) => {
34
- return Parser.flags.boolean({
29
+ return (0, parser_1.boolean)({
35
30
  description: 'Show CLI version.',
36
31
  ...opts,
37
32
  parse: async (_, cmd) => {
@@ -42,7 +37,7 @@ const version = (opts = {}) => {
42
37
  };
43
38
  exports.version = version;
44
39
  const help = (opts = {}) => {
45
- return Parser.flags.boolean({
40
+ return (0, parser_1.boolean)({
46
41
  description: 'Show CLI help.',
47
42
  ...opts,
48
43
  parse: async (_, cmd) => {
@@ -0,0 +1,34 @@
1
+ import { FlagInput } from './parser';
2
+ /**
3
+ * Infer the flags that are returned by Command.parse. This is useful for when you want to assign the flags as a class property.
4
+ *
5
+ * @example
6
+ * export type StatusFlags = Interfaces.InferredFlags<typeof Status.flags & typeof Status.globalFlags>
7
+ *
8
+ * export abstract class BaseCommand extends Command {
9
+ * static enableJsonFlag = true
10
+ *
11
+ * static globalFlags = {
12
+ * config: Flags.string({
13
+ * description: 'specify config file',
14
+ * }),
15
+ * }
16
+ * }
17
+ *
18
+ * export default class Status extends BaseCommand {
19
+ * static flags = {
20
+ * force: Flags.boolean({char: 'f', description: 'a flag'}),
21
+ * }
22
+ *
23
+ * public flags!: StatusFlags
24
+ *
25
+ * public async run(): Promise<StatusFlags> {
26
+ * const result = await this.parse(Status)
27
+ * this.flags = result.flags
28
+ * return result.flags
29
+ * }
30
+ * }
31
+ */
32
+ export declare type InferredFlags<T> = T extends FlagInput<infer F> ? F & {
33
+ json: boolean | undefined;
34
+ } : unknown;
@@ -1 +1,2 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -11,3 +11,4 @@ export { PJSON } from './pjson';
11
11
  export { Plugin, PluginOptions, Options } from './plugin';
12
12
  export { Topic } from './topic';
13
13
  export { TSConfig } from './ts-config';
14
+ export { InferredFlags } from './flags';
@@ -78,14 +78,12 @@ declare type MetadataFlag = {
78
78
  };
79
79
  export declare type ListItem = [string, string | undefined];
80
80
  export declare type List = ListItem[];
81
- export declare type DefaultContext<T> = {
82
- options: OptionFlag<T>;
83
- flags: {
84
- [k: string]: string;
85
- };
81
+ export declare type DefaultContext<T, P> = {
82
+ options: P & OptionFlag<T>;
83
+ flags: Record<string, string>;
86
84
  };
87
- export declare type Default<T> = T | ((context: DefaultContext<T>) => Promise<T>);
88
- export declare type DefaultHelp<T> = T | ((context: DefaultContext<T>) => Promise<string | undefined>);
85
+ export declare type Default<T, P = Record<string, unknown>> = T | ((context: DefaultContext<T, P>) => Promise<T>);
86
+ export declare type DefaultHelp<T, P = Record<string, unknown>> = T | ((context: DefaultContext<T, P>) => Promise<string | undefined>);
89
87
  export declare type FlagProps = {
90
88
  name: string;
91
89
  char?: AlphabetLowercase | AlphabetUppercase;
@@ -109,10 +107,30 @@ export declare type FlagProps = {
109
107
  * Shows this flag in a separate list in the help.
110
108
  */
111
109
  helpGroup?: string;
110
+ /**
111
+ * Accept an environment variable as input
112
+ */
113
+ env?: string;
114
+ /**
115
+ * If true, the flag will not be shown in the help.
116
+ */
112
117
  hidden?: boolean;
118
+ /**
119
+ * If true, the flag will be required.
120
+ */
113
121
  required?: boolean;
122
+ /**
123
+ * List of flags that this flag depends on.
124
+ */
114
125
  dependsOn?: string[];
126
+ /**
127
+ * List of flags that cannot be used with this flag.
128
+ */
115
129
  exclusive?: string[];
130
+ /**
131
+ * Exactly one of these flags must be provided.
132
+ */
133
+ exactlyOne?: string[];
116
134
  };
117
135
  export declare type BooleanFlagProps = FlagProps & {
118
136
  type: 'boolean';
@@ -122,48 +140,60 @@ export declare type OptionFlagProps = FlagProps & {
122
140
  type: 'option';
123
141
  helpValue?: string;
124
142
  options?: string[];
125
- multiple: boolean;
143
+ multiple?: boolean;
126
144
  };
127
- export declare type FlagBase<T, I> = FlagProps & {
128
- exactlyOne?: string[];
129
- /**
130
- * also accept an environment variable as input
131
- */
132
- env?: string;
133
- parse(input: I, context: any): Promise<T>;
145
+ export declare type FlagParser<T, I, P = any> = (input: I, context: any, opts: P & OptionFlag<T>) => Promise<T>;
146
+ export declare type FlagBase<T, I, P = any> = FlagProps & {
147
+ parse: FlagParser<T, I, P>;
134
148
  };
135
149
  export declare type BooleanFlag<T> = FlagBase<T, boolean> & BooleanFlagProps & {
136
150
  /**
137
- * specifying a default of false is the same not specifying a default
151
+ * specifying a default of false is the same as not specifying a default
138
152
  */
139
153
  default?: Default<boolean>;
140
154
  };
141
- export declare type OptionFlag<T> = FlagBase<T, string> & OptionFlagProps & {
142
- default?: Default<T | undefined>;
155
+ export declare type CustomOptionFlag<T, P = any, M = false> = FlagBase<T, string, P> & OptionFlagProps & {
143
156
  defaultHelp?: DefaultHelp<T>;
144
157
  input: string[];
158
+ default?: M extends true ? Default<T[] | undefined, P> : Default<T | undefined, P>;
145
159
  };
146
- export declare type Definition<T> = {
147
- (options: {
160
+ export declare type OptionFlag<T> = FlagBase<T, string> & OptionFlagProps & {
161
+ defaultHelp?: DefaultHelp<T>;
162
+ input: string[];
163
+ } & ({
164
+ default?: Default<T | undefined>;
165
+ multiple: false;
166
+ } | {
167
+ default?: Default<T[] | undefined>;
168
+ multiple: true;
169
+ });
170
+ export declare type Definition<T, P = Record<string, unknown>> = {
171
+ (options: P & {
148
172
  multiple: true;
149
173
  } & ({
150
174
  required: true;
151
175
  } | {
152
- default: Default<T>;
176
+ default: Default<T[]>;
153
177
  }) & Partial<OptionFlag<T>>): OptionFlag<T[]>;
154
- (options: {
178
+ (options: P & {
155
179
  multiple: true;
156
- } & Partial<OptionFlag<T[]>>): OptionFlag<T[] | undefined>;
157
- (options: ({
180
+ } & Partial<OptionFlag<T>>): OptionFlag<T[] | undefined>;
181
+ (options: P & ({
158
182
  required: true;
159
183
  } | {
160
184
  default: Default<T>;
161
185
  }) & Partial<OptionFlag<T>>): OptionFlag<T>;
162
- (options?: Partial<OptionFlag<T>>): OptionFlag<T | undefined>;
186
+ (options?: P & Partial<OptionFlag<T>>): OptionFlag<T | undefined>;
163
187
  };
164
- export declare type EnumFlagOptions<T> = Partial<OptionFlag<T>> & {
188
+ export declare type EnumFlagOptions<T, M = false> = Partial<CustomOptionFlag<T, any, M>> & {
165
189
  options: T[];
166
- };
190
+ } & ({
191
+ default?: Default<T | undefined>;
192
+ multiple?: false;
193
+ } | {
194
+ default?: Default<T[] | undefined>;
195
+ multiple: true;
196
+ });
167
197
  export declare type Flag<T> = BooleanFlag<T> | OptionFlag<T>;
168
198
  export declare type Input<TFlags extends FlagOutput, GFlags extends FlagOutput> = {
169
199
  flags?: FlagInput<TFlags>;
@@ -1,96 +1,59 @@
1
1
  /// <reference types="node" />
2
2
  import { URL } from 'url';
3
- import { Definition, OptionFlag, BooleanFlag, Default } from '../interfaces';
3
+ import { Definition, OptionFlag, BooleanFlag } from '../interfaces';
4
+ import { FlagParser, CustomOptionFlag } from '../interfaces/parser';
5
+ /**
6
+ * Create a custom flag.
7
+ *
8
+ * @example
9
+ * type Id = string
10
+ * type IdOpts = { startsWith: string; length: number };
11
+ *
12
+ * export const myFlag = custom<Id, IdOpts>({
13
+ * parse: async (input, opts) => {
14
+ * if (input.startsWith(opts.startsWith) && input.length === opts.length) {
15
+ * return input
16
+ * }
17
+ *
18
+ * throw new Error('Invalid id')
19
+ * },
20
+ * })
21
+ */
22
+ export declare function custom<T, P = Record<string, unknown>>(defaults: {
23
+ parse: FlagParser<T, string, P>;
24
+ multiple: true;
25
+ } & Partial<CustomOptionFlag<T, P, true>>): Definition<T, P>;
26
+ export declare function custom<T, P = Record<string, unknown>>(defaults: {
27
+ parse: FlagParser<T, string, P>;
28
+ } & Partial<CustomOptionFlag<T, P>>): Definition<T, P>;
29
+ export declare function custom<T = string, P = Record<string, unknown>>(defaults: Partial<CustomOptionFlag<T, P>>): Definition<T, P>;
30
+ /**
31
+ * @deprecated Use Flags.custom instead.
32
+ */
4
33
  export declare function build<T>(defaults: {
5
34
  parse: OptionFlag<T>['parse'];
6
35
  } & Partial<OptionFlag<T>>): Definition<T>;
7
36
  export declare function build(defaults: Partial<OptionFlag<string>>): Definition<string>;
8
37
  export declare function boolean<T = boolean>(options?: Partial<BooleanFlag<T>>): BooleanFlag<T>;
9
- export declare function integer(opts: Partial<OptionFlag<number>> & {
10
- min?: number;
11
- max?: number;
12
- } & {
13
- multiple: true;
14
- } & ({
15
- required: true;
16
- } | {
17
- default: Default<number>;
18
- })): OptionFlag<number[]>;
19
- export declare function integer(opts: Partial<OptionFlag<number>> & {
20
- min?: number;
21
- max?: number;
22
- } & {
23
- multiple: true;
24
- }): OptionFlag<number[] | undefined>;
25
- export declare function integer(opts: Partial<OptionFlag<number>> & {
26
- min?: number;
27
- max?: number;
28
- } & ({
29
- required: true;
30
- } | {
31
- default: Default<number>;
32
- })): OptionFlag<number>;
33
- export declare function integer(opts?: Partial<OptionFlag<number>> & {
34
- min?: number;
35
- max?: number;
36
- }): OptionFlag<number | undefined>;
37
- export declare function directory(opts: Partial<OptionFlag<string>> & {
38
- exists?: boolean;
39
- } & {
40
- multiple: true;
41
- } & ({
42
- required: true;
43
- } | {
44
- default: Default<string>;
45
- })): OptionFlag<string[]>;
46
- export declare function directory(opts: Partial<OptionFlag<string>> & {
47
- exists?: boolean;
48
- } & {
49
- multiple: true;
50
- }): OptionFlag<string[] | undefined>;
51
- export declare function directory(opts: {
52
- exists?: boolean;
53
- } & Partial<OptionFlag<string>> & ({
54
- required: true;
55
- } | {
56
- default: Default<string>;
57
- })): OptionFlag<string>;
58
- export declare function directory(opts?: {
59
- exists?: boolean;
60
- } & Partial<OptionFlag<string>>): OptionFlag<string | undefined>;
61
- export declare function file(opts: Partial<OptionFlag<string>> & {
62
- exists?: boolean;
63
- } & {
64
- multiple: true;
65
- } & ({
66
- required: true;
67
- } | {
68
- default: Default<string>;
69
- })): OptionFlag<string[]>;
70
- export declare function file(opts: Partial<OptionFlag<string>> & {
71
- exists?: boolean;
72
- } & {
73
- multiple: true;
74
- }): OptionFlag<string[] | undefined>;
75
- export declare function file(opts: {
76
- exists?: boolean;
77
- } & Partial<OptionFlag<string>> & ({
78
- required: true;
79
- } | {
80
- default: string;
81
- })): OptionFlag<string>;
82
- export declare function file(opts?: {
83
- exists?: boolean;
84
- } & Partial<OptionFlag<string>>): OptionFlag<string | undefined>;
38
+ export declare const integer: Definition<number, {
39
+ min?: number | undefined;
40
+ max?: number | undefined;
41
+ }>;
42
+ export declare const directory: Definition<string, {
43
+ exists?: boolean | undefined;
44
+ }>;
45
+ export declare const file: Definition<string, {
46
+ exists?: boolean | undefined;
47
+ }>;
85
48
  /**
86
49
  * Initializes a string as a URL. Throws an error
87
50
  * if the string is not a valid URL.
88
51
  */
89
- export declare const url: Definition<URL>;
52
+ export declare const url: Definition<URL, Record<string, unknown>>;
90
53
  export declare function option<T>(options: {
91
54
  parse: OptionFlag<T>['parse'];
92
- } & Partial<OptionFlag<T>>): OptionFlag<T | undefined>;
93
- declare const stringFlag: Definition<string>;
55
+ } & Partial<CustomOptionFlag<T>>): OptionFlag<T | undefined>;
56
+ declare const stringFlag: Definition<string, Record<string, unknown>>;
94
57
  export { stringFlag as string };
95
58
  export declare const defaultFlags: {
96
59
  color: BooleanFlag<boolean>;
@@ -1,13 +1,25 @@
1
1
  "use strict";
2
- // tslint:disable interface-over-type-literal
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.defaultFlags = exports.string = exports.option = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.build = void 0;
3
+ exports.defaultFlags = exports.string = exports.option = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.build = exports.custom = void 0;
5
4
  const url_1 = require("url");
6
5
  const fs = require("fs");
6
+ function custom(defaults) {
7
+ return (options = {}) => {
8
+ return {
9
+ parse: async (i, _context, _opts) => i,
10
+ ...defaults,
11
+ ...options,
12
+ input: [],
13
+ multiple: Boolean(options.multiple === undefined ? defaults.multiple : options.multiple),
14
+ type: 'option',
15
+ };
16
+ };
17
+ }
18
+ exports.custom = custom;
7
19
  function build(defaults) {
8
20
  return (options = {}) => {
9
21
  return {
10
- parse: async (i, _) => i,
22
+ parse: async (i, _context) => i,
11
23
  ...defaults,
12
24
  ...options,
13
25
  input: [],
@@ -26,53 +38,37 @@ function boolean(options = {}) {
26
38
  };
27
39
  }
28
40
  exports.boolean = boolean;
29
- function integer(opts = {}) {
30
- return build({
31
- ...opts,
32
- parse: async (input) => {
33
- if (!/^-?\d+$/.test(input))
34
- throw new Error(`Expected an integer but received: ${input}`);
35
- const num = Number.parseInt(input, 10);
36
- if (opts.min !== undefined && num < opts.min)
37
- throw new Error(`Expected an integer greater than or equal to ${opts.min} but received: ${input}`);
38
- if (opts.max !== undefined && num > opts.max)
39
- throw new Error(`Expected an integer less than or equal to ${opts.max} but received: ${input}`);
40
- return opts.parse ? opts.parse(input, 1) : num;
41
- },
42
- })();
43
- }
44
- exports.integer = integer;
45
- function directory(opts = {}) {
46
- return build({
47
- ...opts,
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
- },
55
- })();
56
- }
57
- exports.directory = directory;
58
- function file(opts = {}) {
59
- return build({
60
- ...opts,
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
- },
68
- })();
69
- }
70
- exports.file = file;
41
+ exports.integer = custom({
42
+ parse: async (input, _, opts) => {
43
+ if (!/^-?\d+$/.test(input))
44
+ throw new Error(`Expected an integer but received: ${input}`);
45
+ const num = Number.parseInt(input, 10);
46
+ if (opts.min !== undefined && num < opts.min)
47
+ throw new Error(`Expected an integer greater than or equal to ${opts.min} but received: ${input}`);
48
+ if (opts.max !== undefined && num > opts.max)
49
+ throw new Error(`Expected an integer less than or equal to ${opts.max} but received: ${input}`);
50
+ return num;
51
+ },
52
+ });
53
+ exports.directory = custom({
54
+ parse: async (input, _, opts) => {
55
+ if (opts.exists)
56
+ return dirExists(input);
57
+ return input;
58
+ },
59
+ });
60
+ exports.file = custom({
61
+ parse: async (input, _, opts) => {
62
+ if (opts.exists)
63
+ return fileExists(input);
64
+ return input;
65
+ },
66
+ });
71
67
  /**
72
68
  * Initializes a string as a URL. Throws an error
73
69
  * if the string is not a valid URL.
74
70
  */
75
- exports.url = build({
71
+ exports.url = custom({
76
72
  parse: async (input) => {
77
73
  try {
78
74
  return new url_1.URL(input);
@@ -83,10 +79,10 @@ exports.url = build({
83
79
  },
84
80
  });
85
81
  function option(options) {
86
- return build(options)();
82
+ return custom(options)();
87
83
  }
88
84
  exports.option = option;
89
- const stringFlag = build({});
85
+ const stringFlag = custom({});
90
86
  exports.string = stringFlag;
91
87
  exports.defaultFlags = {
92
88
  color: boolean({ allowNo: true }),
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import * as args from './args';
3
2
  import * as flags from './flags';
4
3
  import { Input, ParserOutput } from '../interfaces';
@@ -8,5 +7,4 @@ export { flagUsages } from './help';
8
7
  export declare function parse<TFlags, GFlags, TArgs extends {
9
8
  [name: string]: string;
10
9
  }>(argv: string[], options: Input<TFlags, GFlags>): Promise<ParserOutput<TFlags, GFlags, TArgs>>;
11
- declare const boolean: typeof flags.boolean, integer: typeof flags.integer, url: import("../interfaces").Definition<import("url").URL>, directory: typeof flags.directory, file: typeof flags.file;
12
- export { boolean, integer, url, directory, file };
10
+ export { boolean, integer, url, directory, file, string, build, option, custom } from './flags';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.file = exports.directory = exports.url = exports.integer = exports.boolean = exports.parse = exports.flagUsages = exports.flags = exports.args = void 0;
3
+ exports.custom = exports.option = exports.build = exports.string = exports.file = exports.directory = exports.url = exports.integer = exports.boolean = exports.parse = exports.flagUsages = exports.flags = exports.args = void 0;
4
4
  const args = require("./args");
5
5
  exports.args = args;
6
6
  const deps_1 = require("./deps");
@@ -31,9 +31,13 @@ async function parse(argv, options) {
31
31
  return output;
32
32
  }
33
33
  exports.parse = parse;
34
- const { boolean, integer, url, directory, file } = flags;
35
- exports.boolean = boolean;
36
- exports.integer = integer;
37
- exports.url = url;
38
- exports.directory = directory;
39
- exports.file = file;
34
+ var flags_1 = require("./flags");
35
+ Object.defineProperty(exports, "boolean", { enumerable: true, get: function () { return flags_1.boolean; } });
36
+ Object.defineProperty(exports, "integer", { enumerable: true, get: function () { return flags_1.integer; } });
37
+ Object.defineProperty(exports, "url", { enumerable: true, get: function () { return flags_1.url; } });
38
+ Object.defineProperty(exports, "directory", { enumerable: true, get: function () { return flags_1.directory; } });
39
+ Object.defineProperty(exports, "file", { enumerable: true, get: function () { return flags_1.file; } });
40
+ Object.defineProperty(exports, "string", { enumerable: true, get: function () { return flags_1.string; } });
41
+ Object.defineProperty(exports, "build", { enumerable: true, get: function () { return flags_1.build; } });
42
+ Object.defineProperty(exports, "option", { enumerable: true, get: function () { return flags_1.option; } });
43
+ Object.defineProperty(exports, "custom", { enumerable: true, get: function () { return flags_1.custom; } });
@@ -17,6 +17,7 @@ export declare class Parser<T extends ParserInput, TFlags extends OutputFlags<T[
17
17
  }>;
18
18
  private _args;
19
19
  private _flags;
20
+ private _validateOptions;
20
21
  private _argv;
21
22
  private _debugOutput;
22
23
  private _debugInput;
@@ -149,15 +149,13 @@ class Parser {
149
149
  flags[token.flag] = true;
150
150
  }
151
151
  // eslint-disable-next-line no-await-in-loop
152
- flags[token.flag] = await flag.parse(flags[token.flag], this.context);
152
+ flags[token.flag] = await flag.parse(flags[token.flag], this.context, flag);
153
153
  }
154
154
  else {
155
155
  const input = token.input;
156
- if (flag.options && !flag.options.includes(input)) {
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
- const value = flag.parse ? await flag.parse(input, this.context) : input;
158
+ const value = flag.parse ? await flag.parse(input, this.context, flag) : input;
161
159
  if (flag.multiple) {
162
160
  flags[token.flag] = flags[token.flag] || [];
163
161
  flags[token.flag].push(value);
@@ -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
- // eslint-disable-next-line no-await-in-loop
177
- if (input)
178
- flags[k] = await flag.parse(input, this.context);
174
+ if (input) {
175
+ this._validateOptions(flag, input);
176
+ // eslint-disable-next-line no-await-in-loop
177
+ flags[k] = await flag.parse(input, this.context, flag);
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;
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": "1.14.0",
4
+ "version": "1.15.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -74,6 +74,7 @@
74
74
  "shx": "^0.3.4",
75
75
  "sinon": "^11.1.2",
76
76
  "ts-node": "^9.1.1",
77
+ "tsd": "^0.22.0",
77
78
  "typescript": "4.5.5"
78
79
  },
79
80
  "engines": {