@oclif/core 2.0.0-beta.3 → 2.0.0-beta.4

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.
Files changed (90) hide show
  1. package/README.md +5 -5
  2. package/lib/args.d.ts +39 -0
  3. package/lib/args.js +62 -0
  4. package/lib/cli-ux/action/base.d.ts +1 -1
  5. package/lib/cli-ux/action/pride-spinner.js +0 -1
  6. package/lib/cli-ux/action/spinner.js +10 -11
  7. package/lib/cli-ux/action/spinners.d.ts +251 -0
  8. package/lib/cli-ux/action/spinners.js +2 -1
  9. package/lib/cli-ux/config.d.ts +1 -1
  10. package/lib/cli-ux/config.js +7 -5
  11. package/lib/cli-ux/index.d.ts +27 -32
  12. package/lib/cli-ux/index.js +67 -24
  13. package/lib/cli-ux/list.js +3 -4
  14. package/lib/cli-ux/prompt.js +9 -8
  15. package/lib/cli-ux/styled/header.js +1 -1
  16. package/lib/cli-ux/styled/index.d.ts +7 -0
  17. package/lib/cli-ux/styled/index.js +15 -0
  18. package/lib/cli-ux/styled/json.d.ts +1 -1
  19. package/lib/cli-ux/styled/json.js +2 -3
  20. package/lib/cli-ux/styled/object.js +1 -1
  21. package/lib/cli-ux/styled/progress.d.ts +2 -1
  22. package/lib/cli-ux/styled/progress.js +1 -5
  23. package/lib/cli-ux/styled/table.js +1 -3
  24. package/lib/cli-ux/styled/tree.js +0 -1
  25. package/lib/cli-ux/wait.d.ts +1 -1
  26. package/lib/cli-ux/wait.js +0 -1
  27. package/lib/command.d.ts +77 -26
  28. package/lib/command.js +46 -43
  29. package/lib/config/config.d.ts +18 -17
  30. package/lib/config/config.js +46 -22
  31. package/lib/config/index.js +0 -5
  32. package/lib/config/plugin.d.ts +3 -2
  33. package/lib/config/plugin.js +4 -13
  34. package/lib/config/util.js +2 -2
  35. package/lib/errors/index.js +0 -1
  36. package/lib/errors/logger.js +2 -4
  37. package/lib/flags.d.ts +46 -18
  38. package/lib/flags.js +71 -29
  39. package/lib/help/command.d.ts +12 -12
  40. package/lib/help/command.js +6 -6
  41. package/lib/help/docopts.d.ts +3 -3
  42. package/lib/help/docopts.js +2 -3
  43. package/lib/help/formatter.d.ts +4 -3
  44. package/lib/help/index.d.ts +10 -14
  45. package/lib/help/index.js +0 -5
  46. package/lib/help/util.d.ts +3 -3
  47. package/lib/help/util.js +1 -1
  48. package/lib/index.d.ts +5 -4
  49. package/lib/index.js +10 -8
  50. package/lib/interfaces/args.d.ts +22 -0
  51. package/lib/interfaces/{command.js → args.js} +0 -0
  52. package/lib/interfaces/config.d.ts +1 -2
  53. package/lib/interfaces/flags.d.ts +2 -2
  54. package/lib/interfaces/hooks.d.ts +1 -1
  55. package/lib/interfaces/index.d.ts +2 -2
  56. package/lib/interfaces/manifest.d.ts +2 -2
  57. package/lib/interfaces/parser.d.ts +96 -81
  58. package/lib/interfaces/plugin.d.ts +1 -1
  59. package/lib/main.d.ts +54 -1
  60. package/lib/main.js +70 -6
  61. package/lib/parser/errors.d.ts +15 -8
  62. package/lib/parser/errors.js +17 -14
  63. package/lib/parser/help.d.ts +1 -1
  64. package/lib/parser/help.js +4 -9
  65. package/lib/parser/index.d.ts +2 -9
  66. package/lib/parser/index.js +5 -26
  67. package/lib/parser/parse.d.ts +4 -11
  68. package/lib/parser/parse.js +108 -72
  69. package/lib/parser/validate.d.ts +1 -1
  70. package/lib/parser/validate.js +6 -3
  71. package/lib/util.d.ts +8 -0
  72. package/lib/util.js +44 -1
  73. package/package.json +4 -4
  74. package/lib/cli-ux/deps.d.ts +0 -22
  75. package/lib/cli-ux/deps.js +0 -47
  76. package/lib/cli-ux/open.d.ts +0 -6
  77. package/lib/cli-ux/open.js +0 -69
  78. package/lib/help/_test-help-class.d.ts +0 -6
  79. package/lib/help/_test-help-class.js +0 -19
  80. package/lib/interfaces/command.d.ts +0 -110
  81. package/lib/parser/args.d.ts +0 -5
  82. package/lib/parser/args.js +0 -11
  83. package/lib/parser/deps.d.ts +0 -4
  84. package/lib/parser/deps.js +0 -17
  85. package/lib/parser/flags.d.ts +0 -60
  86. package/lib/parser/flags.js +0 -107
  87. package/lib/parser/list.d.ts +0 -2
  88. package/lib/parser/list.js +0 -29
  89. package/lib/parser/util.d.ts +0 -7
  90. package/lib/parser/util.js +0 -50
@@ -1,62 +1,37 @@
1
+ import { Command } from '../command';
1
2
  import { AlphabetLowercase, AlphabetUppercase } from './alphabet';
2
3
  import { Config } from './config';
3
- export type ParseFn<T> = (input: string) => Promise<T>;
4
- export interface Arg<T = string> {
5
- name: string;
6
- description?: string;
7
- required?: boolean;
8
- hidden?: boolean;
9
- parse?: ParseFn<T>;
10
- default?: T | (() => T);
11
- options?: string[];
12
- ignoreStdin?: boolean;
13
- }
14
- export interface ArgBase<T> {
15
- name?: string;
16
- description?: string;
17
- hidden?: boolean;
18
- parse: ParseFn<T>;
19
- default?: T | (() => Promise<T>);
20
- input?: string;
21
- options?: string[];
22
- ignoreStdin?: boolean;
23
- }
24
- export type RequiredArg<T> = ArgBase<T> & {
25
- required: true;
26
- value: T;
27
- };
28
- export type OptionalArg<T> = ArgBase<T> & {
29
- required: false;
30
- value?: T;
4
+ export type FlagOutput = {
5
+ [name: string]: any;
31
6
  };
32
- export type ParserArg<T> = RequiredArg<T> | OptionalArg<T>;
33
- export interface FlagOutput {
7
+ export type ArgOutput = {
34
8
  [name: string]: any;
35
- }
36
- export type ArgInput = Arg<any>[];
37
- export interface CLIParseErrorOptions {
9
+ };
10
+ export type CLIParseErrorOptions = {
38
11
  parse: {
39
12
  input?: ParserInput;
40
13
  output?: ParserOutput;
41
14
  };
42
- }
43
- export type OutputArgs = {
44
- [name: string]: any;
15
+ };
16
+ export type OutputArgs<T extends ParserInput['args']> = {
17
+ [P in keyof T]: any;
45
18
  };
46
19
  export type OutputFlags<T extends ParserInput['flags']> = {
47
20
  [P in keyof T]: any;
48
21
  };
49
- export type ParserOutput<TFlags extends OutputFlags<any> = any, GFlags extends OutputFlags<any> = any, TArgs extends OutputArgs = any> = {
50
- flags: TFlags & GFlags & {
22
+ export type ParserOutput<TFlags extends OutputFlags<any> = any, BFlags extends OutputFlags<any> = any, TArgs extends OutputFlags<any> = any> = {
23
+ flags: TFlags & BFlags & {
51
24
  json: boolean | undefined;
52
25
  };
53
26
  args: TArgs;
54
- argv: string[];
27
+ argv: unknown[];
55
28
  raw: ParsingToken[];
56
29
  metadata: Metadata;
30
+ nonExistentFlags: string[];
57
31
  };
58
32
  export type ArgToken = {
59
33
  type: 'arg';
34
+ arg: string;
60
35
  input: string;
61
36
  };
62
37
  export type FlagToken = {
@@ -65,9 +40,9 @@ export type FlagToken = {
65
40
  input: string;
66
41
  };
67
42
  export type ParsingToken = ArgToken | FlagToken;
68
- export interface FlagUsageOptions {
43
+ export type FlagUsageOptions = {
69
44
  displayRequired?: boolean;
70
- }
45
+ };
71
46
  export type Metadata = {
72
47
  flags: {
73
48
  [key: string]: MetadataFlag;
@@ -78,12 +53,15 @@ type MetadataFlag = {
78
53
  };
79
54
  export type ListItem = [string, string | undefined];
80
55
  export type List = ListItem[];
81
- export type DefaultContext<T, P> = {
82
- options: P & OptionFlag<T>;
56
+ export type CustomOptions = Record<string, unknown>;
57
+ export type DefaultContext<T> = {
58
+ options: T;
83
59
  flags: Record<string, string>;
84
60
  };
85
- export type Default<T, P = Record<string, unknown>> = T | ((context: DefaultContext<T, P>) => Promise<T>);
86
- export type DefaultHelp<T, P = Record<string, unknown>> = T | ((context: DefaultContext<T, P>) => Promise<string | undefined>);
61
+ export type FlagDefault<T, P = CustomOptions> = T | ((context: DefaultContext<OptionFlag<T, P> & P>) => Promise<T>);
62
+ export type FlagDefaultHelp<T, P = CustomOptions> = T | ((context: DefaultContext<OptionFlag<T, P> & P>) => Promise<string | undefined>);
63
+ export type ArgDefault<T, P = CustomOptions> = T | ((context: DefaultContext<Arg<T, P>>) => Promise<T>);
64
+ export type ArgDefaultHelp<T, P = CustomOptions> = T | ((context: DefaultContext<Arg<T, P>>) => Promise<string | undefined>);
87
65
  export type FlagRelationship = string | {
88
66
  name: string;
89
67
  when: (flags: Record<string, unknown>) => Promise<boolean>;
@@ -160,6 +138,31 @@ export type FlagProps = {
160
138
  * Emit deprecation warning when a flag alias is provided
161
139
  */
162
140
  deprecateAliases?: boolean;
141
+ /**
142
+ * Delimiter to separate the values for a multiple value flag.
143
+ * Only respected if multiple is set to true. Default behavior is to
144
+ * separate on spaces.
145
+ */
146
+ delimiter?: ',';
147
+ };
148
+ export type ArgProps = {
149
+ name: string;
150
+ /**
151
+ * A description of flag usage. If summary is provided, the description
152
+ * is assumed to be a longer description and will be shown in a separate
153
+ * section within help.
154
+ */
155
+ description?: string;
156
+ /**
157
+ * If true, the flag will not be shown in the help.
158
+ */
159
+ hidden?: boolean;
160
+ /**
161
+ * If true, the flag will be required.
162
+ */
163
+ required?: boolean;
164
+ options?: string[];
165
+ ignoreStdin?: boolean;
163
166
  };
164
167
  export type BooleanFlagProps = FlagProps & {
165
168
  type: 'boolean';
@@ -171,75 +174,82 @@ export type OptionFlagProps = FlagProps & {
171
174
  options?: string[];
172
175
  multiple?: boolean;
173
176
  };
174
- export type FlagParser<T, I, P = any> = (input: I, context: any, opts: P & OptionFlag<T>) => Promise<T | T[]>;
175
- export type FlagBase<T, I, P = any> = FlagProps & {
176
- parse: FlagParser<T, I, P>;
177
+ export type FlagParser<T, I extends string | boolean, P = CustomOptions> = (input: I, context: Command, opts: P & OptionFlag<T, P>) => Promise<T>;
178
+ export type ArgParser<T, P = CustomOptions> = (input: string, context: Command, opts: P & Arg<T, P>) => Promise<T>;
179
+ export type Arg<T, P = CustomOptions> = ArgProps & {
180
+ options?: T[];
181
+ defaultHelp?: ArgDefaultHelp<T>;
182
+ input: string[];
183
+ default?: ArgDefault<T | undefined>;
184
+ parse: ArgParser<T, P>;
185
+ };
186
+ export type ArgDefinition<T, P = CustomOptions> = {
187
+ (options: P & ({
188
+ required: true;
189
+ } | {
190
+ default: ArgDefault<T>;
191
+ }) & Partial<Arg<T, P>>): Arg<T, P>;
192
+ (options?: P & Partial<Arg<T, P>>): Arg<T | undefined, P>;
177
193
  };
178
- export type BooleanFlag<T> = FlagBase<T, boolean> & BooleanFlagProps & {
194
+ export type BooleanFlag<T> = FlagProps & BooleanFlagProps & {
179
195
  /**
180
196
  * specifying a default of false is the same as not specifying a default
181
197
  */
182
- default?: Default<boolean>;
198
+ default?: FlagDefault<boolean>;
199
+ parse: (input: boolean, context: Command, opts: FlagProps & BooleanFlagProps) => Promise<T>;
183
200
  };
184
- export type CustomOptionFlag<T, P = any, M = false> = FlagBase<T, string, P> & OptionFlagProps & {
185
- defaultHelp?: DefaultHelp<T>;
201
+ export type OptionFlagDefaults<T, P = CustomOptions, M = false> = FlagProps & OptionFlagProps & {
202
+ parse: FlagParser<T, string, P & OptionFlag<T, P>>;
203
+ defaultHelp?: FlagDefaultHelp<T>;
186
204
  input: string[];
187
- default?: M extends true ? Default<T[] | undefined, P> : Default<T | undefined, P>;
205
+ default?: M extends true ? FlagDefault<T[] | undefined, P> : FlagDefault<T | undefined, P>;
188
206
  };
189
- export type OptionFlag<T> = FlagBase<T, string> & OptionFlagProps & {
190
- defaultHelp?: DefaultHelp<T>;
207
+ export type OptionFlag<T, P = CustomOptions> = FlagProps & OptionFlagProps & {
208
+ parse: FlagParser<T, string, P & OptionFlag<T, P>>;
209
+ defaultHelp?: FlagDefaultHelp<T, P>;
191
210
  input: string[];
192
211
  } & ({
193
- default?: Default<T | undefined>;
212
+ default?: FlagDefault<T | undefined, P>;
194
213
  multiple: false;
195
214
  } | {
196
- default?: Default<T[] | undefined>;
215
+ default?: FlagDefault<T[] | undefined, P>;
197
216
  multiple: true;
198
217
  });
199
- export type Definition<T, P = Record<string, unknown>> = {
218
+ export type FlagDefinition<T, P = CustomOptions> = {
200
219
  (options: P & {
201
220
  multiple: true;
202
221
  } & ({
203
222
  required: true;
204
223
  } | {
205
- default: Default<T[]>;
206
- }) & Partial<OptionFlag<T>>): OptionFlag<T[]>;
224
+ default: FlagDefault<T[]>;
225
+ }) & Partial<OptionFlag<T, P>>): OptionFlag<T[]>;
207
226
  (options: P & {
208
227
  multiple: true;
209
- } & Partial<OptionFlag<T>>): OptionFlag<T[] | undefined>;
228
+ } & Partial<OptionFlag<T>>): OptionFlag<T[] | undefined, P>;
210
229
  (options: P & ({
211
230
  required: true;
212
231
  } | {
213
- default: Default<T>;
214
- }) & Partial<OptionFlag<T>>): OptionFlag<T>;
215
- (options?: P & Partial<OptionFlag<T>>): OptionFlag<T | undefined>;
232
+ default: FlagDefault<T>;
233
+ }) & Partial<OptionFlag<T>>): OptionFlag<T, P>;
234
+ (options?: P & Partial<OptionFlag<T>>): OptionFlag<T | undefined, P>;
216
235
  };
217
- export type EnumFlagOptions<T, M = false> = Partial<CustomOptionFlag<T, any, M>> & {
218
- options: T[];
219
- } & ({
220
- default?: Default<T | undefined>;
221
- multiple?: false;
222
- } | {
223
- default?: Default<T[] | undefined>;
224
- multiple: true;
225
- });
226
236
  export type Flag<T> = BooleanFlag<T> | OptionFlag<T>;
227
- export type Input<TFlags extends FlagOutput, GFlags extends FlagOutput> = {
237
+ export type Input<TFlags extends FlagOutput, BFlags extends FlagOutput, AFlags extends ArgOutput> = {
228
238
  flags?: FlagInput<TFlags>;
229
- globalFlags?: FlagInput<GFlags>;
230
- args?: ArgInput;
239
+ baseFlags?: FlagInput<BFlags>;
240
+ args?: ArgInput<AFlags>;
231
241
  strict?: boolean;
232
- context?: any;
242
+ context?: Command;
233
243
  '--'?: boolean;
234
244
  };
235
- export interface ParserInput {
245
+ export type ParserInput = {
236
246
  argv: string[];
237
247
  flags: FlagInput<any>;
238
- args: ParserArg<any>[];
248
+ args: ArgInput<any>;
239
249
  strict: boolean;
240
- context: any;
250
+ context: Command | undefined;
241
251
  '--'?: boolean;
242
- }
252
+ };
243
253
  export type CompletionContext = {
244
254
  args?: {
245
255
  [name: string]: string;
@@ -265,4 +275,9 @@ export type FlagInput<T extends FlagOutput = {
265
275
  }> = {
266
276
  [P in keyof T]: CompletableFlag<T[P]>;
267
277
  };
278
+ export type ArgInput<T extends ArgOutput = {
279
+ [arg: string]: any;
280
+ }> = {
281
+ [P in keyof T]: Arg<T[P]>;
282
+ };
268
283
  export {};
@@ -1,4 +1,4 @@
1
- import { Command } from './command';
1
+ import { Command } from '../command';
2
2
  import { PJSON } from './pjson';
3
3
  import { Topic } from './topic';
4
4
  export interface PluginOptions {
package/lib/main.d.ts CHANGED
@@ -2,4 +2,57 @@ import * as Interfaces from './interfaces';
2
2
  import { Config } from './config';
3
3
  export declare const helpAddition: (argv: string[], config: Interfaces.Config) => boolean;
4
4
  export declare const versionAddition: (argv: string[], config?: Interfaces.Config) => boolean;
5
- export declare function run(argv?: string[], options?: Interfaces.LoadOptions): Promise<unknown>;
5
+ export declare function run(argv?: string[], options?: Interfaces.LoadOptions): Promise<void>;
6
+ /**
7
+ * Load and run oclif CLI
8
+ *
9
+ * @param options - options to load the CLI
10
+ * @returns Promise<void>
11
+ *
12
+ * @example For ESM dev.js
13
+ * ```
14
+ * #!/usr/bin/env ts-node
15
+ * // eslint-disable-next-line node/shebang
16
+ * (async () => {
17
+ * const oclif = await import('@oclif/core')
18
+ * await oclif.execute({type: 'esm', development: true, dir: import.meta.url})
19
+ * })()
20
+ * ```
21
+ *
22
+ * @example For ESM run.js
23
+ * ```
24
+ * #!/usr/bin/env node
25
+ * // eslint-disable-next-line node/shebang
26
+ * (async () => {
27
+ * const oclif = await import('@oclif/core')
28
+ * await oclif.execute({type: 'esm', dir: import.meta.url})
29
+ * })()
30
+ * ```
31
+ *
32
+ * @example For CJS dev.js
33
+ * ```
34
+ * #!/usr/bin/env node
35
+ * // eslint-disable-next-line node/shebang
36
+ * (async () => {
37
+ * const oclif = await import('@oclif/core')
38
+ * await oclif.execute({type: 'cjs', development: true, dir: __dirname})
39
+ * })()
40
+ * ```
41
+ *
42
+ * @example For CJS run.js
43
+ * ```
44
+ * #!/usr/bin/env node
45
+ * // eslint-disable-next-line node/shebang
46
+ * (async () => {
47
+ * const oclif = await import('@oclif/core')
48
+ * await oclif.execute({type: 'cjs', dir: import.meta.url})
49
+ * })()
50
+ * ```
51
+ */
52
+ export declare function execute(options: {
53
+ type: 'cjs' | 'esm';
54
+ dir: string;
55
+ args?: string[];
56
+ loadOptions?: Interfaces.LoadOptions;
57
+ development?: boolean;
58
+ }): Promise<void>;
package/lib/main.js CHANGED
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = exports.versionAddition = exports.helpAddition = void 0;
3
+ exports.execute = exports.run = exports.versionAddition = exports.helpAddition = void 0;
4
4
  const url_1 = require("url");
5
5
  const util_1 = require("util");
6
6
  const url_2 = require("url");
7
7
  const config_1 = require("./config");
8
8
  const help_1 = require("./help");
9
+ const settings_1 = require("./settings");
10
+ const _1 = require(".");
11
+ const path_1 = require("path");
9
12
  const log = (message = '', ...args) => {
10
- // tslint:disable-next-line strict-type-predicates
11
13
  message = typeof message === 'string' ? message : (0, util_1.inspect)(message);
12
14
  process.stdout.write((0, util_1.format)(message, ...args) + '\n');
13
15
  };
@@ -32,14 +34,13 @@ const versionAddition = (argv, config) => {
32
34
  return false;
33
35
  };
34
36
  exports.versionAddition = versionAddition;
35
- // eslint-disable-next-line default-param-last
36
- async function run(argv = process.argv.slice(2), options) {
37
+ async function run(argv, options) {
38
+ argv = argv ?? process.argv.slice(2);
37
39
  // Handle the case when a file URL string or URL is passed in such as 'import.meta.url'; covert to file path.
38
40
  if (options && ((typeof options === 'string' && options.startsWith('file://')) || options instanceof url_2.URL)) {
39
41
  options = (0, url_1.fileURLToPath)(options);
40
42
  }
41
- // return Main.run(argv, options)
42
- const config = await config_1.Config.load(options || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname);
43
+ const config = await config_1.Config.load(options ?? require.main?.filename ?? __dirname);
43
44
  let [id, ...argvSlice] = (0, help_1.normalizeArgv)(config, argv);
44
45
  // run init hook
45
46
  await config.runHook('init', { id, argv: argvSlice });
@@ -74,3 +75,66 @@ async function run(argv = process.argv.slice(2), options) {
74
75
  await config.runCommand(id, argvSlice, cmd);
75
76
  }
76
77
  exports.run = run;
78
+ function getTsConfigPath(dir, type) {
79
+ return type === 'cjs' ? (0, path_1.join)(dir, '..', 'tsconfig.json') : (0, path_1.join)((0, path_1.dirname)((0, url_1.fileURLToPath)(dir)), '..', 'tsconfig.json');
80
+ }
81
+ /**
82
+ * Load and run oclif CLI
83
+ *
84
+ * @param options - options to load the CLI
85
+ * @returns Promise<void>
86
+ *
87
+ * @example For ESM dev.js
88
+ * ```
89
+ * #!/usr/bin/env ts-node
90
+ * // eslint-disable-next-line node/shebang
91
+ * (async () => {
92
+ * const oclif = await import('@oclif/core')
93
+ * await oclif.execute({type: 'esm', development: true, dir: import.meta.url})
94
+ * })()
95
+ * ```
96
+ *
97
+ * @example For ESM run.js
98
+ * ```
99
+ * #!/usr/bin/env node
100
+ * // eslint-disable-next-line node/shebang
101
+ * (async () => {
102
+ * const oclif = await import('@oclif/core')
103
+ * await oclif.execute({type: 'esm', dir: import.meta.url})
104
+ * })()
105
+ * ```
106
+ *
107
+ * @example For CJS dev.js
108
+ * ```
109
+ * #!/usr/bin/env node
110
+ * // eslint-disable-next-line node/shebang
111
+ * (async () => {
112
+ * const oclif = await import('@oclif/core')
113
+ * await oclif.execute({type: 'cjs', development: true, dir: __dirname})
114
+ * })()
115
+ * ```
116
+ *
117
+ * @example For CJS run.js
118
+ * ```
119
+ * #!/usr/bin/env node
120
+ * // eslint-disable-next-line node/shebang
121
+ * (async () => {
122
+ * const oclif = await import('@oclif/core')
123
+ * await oclif.execute({type: 'cjs', dir: import.meta.url})
124
+ * })()
125
+ * ```
126
+ */
127
+ async function execute(options) {
128
+ if (options.development) {
129
+ // In dev mode -> use ts-node and dev plugins
130
+ process.env.NODE_ENV = 'development';
131
+ require('ts-node').register({
132
+ project: getTsConfigPath(options.dir, options.type),
133
+ });
134
+ settings_1.settings.debug = true;
135
+ }
136
+ await run(options.args ?? process.argv.slice(2), options.loadOptions ?? options.dir)
137
+ .then(async () => (0, _1.flush)())
138
+ .catch(_1.Errors.handle);
139
+ }
140
+ exports.execute = execute;
@@ -1,5 +1,6 @@
1
1
  import { CLIError } from '../errors';
2
- import { ParserArg, CLIParseErrorOptions, OptionFlag, Flag } from '../interfaces';
2
+ import { OptionFlag, Flag } from '../interfaces';
3
+ import { Arg, ArgInput, CLIParseErrorOptions } from '../interfaces/parser';
3
4
  export { CLIError } from '../errors';
4
5
  export type Validation = {
5
6
  name: string;
@@ -14,15 +15,15 @@ export declare class CLIParseError extends CLIError {
14
15
  });
15
16
  }
16
17
  export declare class InvalidArgsSpecError extends CLIParseError {
17
- args: ParserArg<any>[];
18
+ args: ArgInput;
18
19
  constructor({ args, parse }: CLIParseErrorOptions & {
19
- args: ParserArg<any>[];
20
+ args: ArgInput;
20
21
  });
21
22
  }
22
23
  export declare class RequiredArgsError extends CLIParseError {
23
- args: ParserArg<any>[];
24
+ args: Arg<any>[];
24
25
  constructor({ args, parse }: CLIParseErrorOptions & {
25
- args: ParserArg<any>[];
26
+ args: Arg<any>[];
26
27
  });
27
28
  }
28
29
  export declare class RequiredFlagError extends CLIParseError {
@@ -32,16 +33,22 @@ export declare class RequiredFlagError extends CLIParseError {
32
33
  });
33
34
  }
34
35
  export declare class UnexpectedArgsError extends CLIParseError {
35
- args: string[];
36
+ args: unknown[];
36
37
  constructor({ parse, args }: CLIParseErrorOptions & {
37
- args: string[];
38
+ args: unknown[];
39
+ });
40
+ }
41
+ export declare class NonExistentFlagsError extends CLIParseError {
42
+ flags: string[];
43
+ constructor({ parse, flags }: CLIParseErrorOptions & {
44
+ flags: string[];
38
45
  });
39
46
  }
40
47
  export declare class FlagInvalidOptionError extends CLIParseError {
41
48
  constructor(flag: OptionFlag<any>, input: string);
42
49
  }
43
50
  export declare class ArgInvalidOptionError extends CLIParseError {
44
- constructor(arg: ParserArg<any>, input: string);
51
+ constructor(arg: Arg<any>, input: string);
45
52
  }
46
53
  export declare class FailedFlagValidationError extends CLIParseError {
47
54
  constructor({ parse, failed }: CLIParseErrorOptions & {
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.UnexpectedArgsError = exports.RequiredFlagError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
3
+ exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredFlagError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
4
4
  const errors_1 = require("../errors");
5
- const deps_1 = require("./deps");
5
+ const help_1 = require("./help");
6
+ const list_1 = require("../cli-ux/list");
7
+ const chalk = require("chalk");
6
8
  const util_1 = require("../config/util");
7
9
  var errors_2 = require("../errors");
8
10
  Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return errors_2.CLIError; } });
9
- // eslint-disable-next-line new-cap
10
- const m = (0, deps_1.default)()
11
- // eslint-disable-next-line node/no-missing-require
12
- .add('help', () => require('./help'))
13
- // eslint-disable-next-line node/no-missing-require
14
- .add('list', () => require('./list'))
15
- .add('chalk', () => require('chalk'));
16
11
  class CLIParseError extends errors_1.CLIError {
17
12
  constructor(options) {
18
13
  options.message += '\nSee more help with --help';
@@ -24,9 +19,9 @@ exports.CLIParseError = CLIParseError;
24
19
  class InvalidArgsSpecError extends CLIParseError {
25
20
  constructor({ args, parse }) {
26
21
  let message = 'Invalid argument spec';
27
- const namedArgs = args.filter(a => a.name);
22
+ const namedArgs = Object.values(args).filter(a => a.name);
28
23
  if (namedArgs.length > 0) {
29
- const list = m.list.renderList(namedArgs.map(a => [`${a.name} (${a.required ? 'required' : 'optional'})`, a.description]));
24
+ const list = (0, list_1.renderList)(namedArgs.map(a => [`${a.name} (${a.required ? 'required' : 'optional'})`, a.description]));
30
25
  message += `:\n${list}`;
31
26
  }
32
27
  super({ parse, message });
@@ -39,7 +34,7 @@ class RequiredArgsError extends CLIParseError {
39
34
  let message = `Missing ${args.length} required arg${args.length === 1 ? '' : 's'}`;
40
35
  const namedArgs = args.filter(a => a.name);
41
36
  if (namedArgs.length > 0) {
42
- const list = m.list.renderList(namedArgs.map(a => [a.name, a.description]));
37
+ const list = (0, list_1.renderList)(namedArgs.map(a => [a.name, a.description]));
43
38
  message += `:\n${list}`;
44
39
  }
45
40
  super({ parse, message });
@@ -49,7 +44,7 @@ class RequiredArgsError extends CLIParseError {
49
44
  exports.RequiredArgsError = RequiredArgsError;
50
45
  class RequiredFlagError extends CLIParseError {
51
46
  constructor({ flag, parse }) {
52
- const usage = m.list.renderList(m.help.flagUsages([flag], { displayRequired: false }));
47
+ const usage = (0, list_1.renderList)((0, help_1.flagUsages)([flag], { displayRequired: false }));
53
48
  const message = `Missing required flag:\n${usage}`;
54
49
  super({ parse, message });
55
50
  this.flag = flag;
@@ -64,6 +59,14 @@ class UnexpectedArgsError extends CLIParseError {
64
59
  }
65
60
  }
66
61
  exports.UnexpectedArgsError = UnexpectedArgsError;
62
+ class NonExistentFlagsError extends CLIParseError {
63
+ constructor({ parse, flags }) {
64
+ const message = `Nonexistent flag${flags.length === 1 ? '' : 's'}: ${flags.join(', ')}`;
65
+ super({ parse, message });
66
+ this.flags = flags;
67
+ }
68
+ }
69
+ exports.NonExistentFlagsError = NonExistentFlagsError;
67
70
  class FlagInvalidOptionError extends CLIParseError {
68
71
  constructor(flag, input) {
69
72
  const message = `Expected --${flag.name}=${input} to be one of: ${flag.options.join(', ')}`;
@@ -83,7 +86,7 @@ class FailedFlagValidationError extends CLIParseError {
83
86
  const reasons = failed.map(r => r.reason);
84
87
  const deduped = (0, util_1.uniq)(reasons);
85
88
  const errString = deduped.length === 1 ? 'error' : 'errors';
86
- const message = `The following ${errString} occurred:\n ${m.chalk.dim(deduped.join('\n '))}`;
89
+ const message = `The following ${errString} occurred:\n ${chalk.dim(deduped.join('\n '))}`;
87
90
  super({ parse, message });
88
91
  }
89
92
  }
@@ -1,3 +1,3 @@
1
- import { FlagUsageOptions, Flag } from '../interfaces';
1
+ import { Flag, FlagUsageOptions } from '../interfaces/parser';
2
2
  export declare function flagUsage(flag: Flag<any>, options?: FlagUsageOptions): [string, string | undefined];
3
3
  export declare function flagUsages(flags: Flag<any>[], options?: FlagUsageOptions): [string, string | undefined][];
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.flagUsages = exports.flagUsage = void 0;
4
- const deps_1 = require("./deps");
5
- // eslint-disable-next-line new-cap
6
- const m = (0, deps_1.default)()
7
- .add('chalk', () => require('chalk'))
8
- // eslint-disable-next-line node/no-missing-require
9
- .add('util', () => require('./util'));
4
+ const chalk = require("chalk");
5
+ const util_1 = require("../util");
10
6
  function flagUsage(flag, options = {}) {
11
7
  const label = [];
12
8
  if (flag.helpLabel) {
@@ -22,15 +18,14 @@ function flagUsage(flag, options = {}) {
22
18
  let description = flag.summary || flag.description || '';
23
19
  if (options.displayRequired && flag.required)
24
20
  description = `(required) ${description}`;
25
- description = description ? m.chalk.dim(description) : undefined;
21
+ description = description ? chalk.dim(description) : undefined;
26
22
  return [` ${label.join(',').trim()}${usage}`, description];
27
23
  }
28
24
  exports.flagUsage = flagUsage;
29
25
  function flagUsages(flags, options = {}) {
30
26
  if (flags.length === 0)
31
27
  return [];
32
- const { sortBy } = m.util;
33
- return sortBy(flags, f => [f.char ? -1 : 1, f.char, f.name])
28
+ return (0, util_1.sortBy)(flags, f => [f.char ? -1 : 1, f.char, f.name])
34
29
  .map(f => flagUsage(f, options));
35
30
  }
36
31
  exports.flagUsages = flagUsages;
@@ -1,10 +1,3 @@
1
- import * as args from './args';
2
- import * as flags from './flags';
3
- import { Input, ParserOutput, OutputFlags, FlagOutput } from '../interfaces';
4
- export { args };
5
- export { flags };
1
+ import { Input, OutputArgs, OutputFlags, ParserOutput } from '../interfaces/parser';
6
2
  export { flagUsages } from './help';
7
- export declare function parse<TFlags extends OutputFlags<any>, GFlags extends FlagOutput, TArgs extends {
8
- [name: string]: string;
9
- }>(argv: string[], options: Input<TFlags, GFlags>): Promise<ParserOutput<TFlags, GFlags, TArgs>>;
10
- export { boolean, integer, url, directory, file, string, build, option, custom } from './flags';
3
+ export declare function parse<TFlags extends OutputFlags<any>, BFlags extends OutputFlags<any>, TArgs extends OutputArgs<any>>(argv: string[], options: Input<TFlags, BFlags, TArgs>): Promise<ParserOutput<TFlags, BFlags, TArgs>>;
@@ -1,43 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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
- const args = require("./args");
5
- exports.args = args;
6
- const deps_1 = require("./deps");
7
- const flags = require("./flags");
8
- exports.flags = flags;
3
+ exports.parse = exports.flagUsages = void 0;
9
4
  const parse_1 = require("./parse");
5
+ const validate_1 = require("./validate");
10
6
  var help_1 = require("./help");
11
7
  Object.defineProperty(exports, "flagUsages", { enumerable: true, get: function () { return help_1.flagUsages; } });
12
- // eslint-disable-next-line new-cap
13
- const m = (0, deps_1.default)()
14
- // eslint-disable-next-line node/no-missing-require
15
- .add('validate', () => require('./validate').validate);
16
8
  async function parse(argv, options) {
17
9
  const input = {
18
10
  argv,
19
11
  context: options.context,
20
- args: (options.args || []).map((a) => args.newArg(a)),
21
12
  '--': options['--'],
22
- flags: {
23
- color: flags.defaultFlags.color,
24
- ...options.flags,
25
- },
13
+ flags: (options.flags ?? {}),
14
+ args: (options.args ?? {}),
26
15
  strict: options.strict !== false,
27
16
  };
28
17
  const parser = new parse_1.Parser(input);
29
18
  const output = await parser.parse();
30
- await m.validate({ input, output });
19
+ await (0, validate_1.validate)({ input, output });
31
20
  return output;
32
21
  }
33
22
  exports.parse = parse;
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; } });