pgflow 0.0.1-a → 0.0.1-prealpha.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.
Files changed (112) hide show
  1. package/README.md +9 -3
  2. package/dist/node_modules/.package-lock.json +129 -0
  3. package/dist/node_modules/@commander-js/extra-typings/LICENSE +21 -0
  4. package/dist/node_modules/@commander-js/extra-typings/README.md +66 -0
  5. package/dist/node_modules/@commander-js/extra-typings/esm.d.mts +2 -0
  6. package/dist/node_modules/@commander-js/extra-typings/esm.mjs +16 -0
  7. package/dist/node_modules/@commander-js/extra-typings/index.d.ts +1467 -0
  8. package/dist/node_modules/@commander-js/extra-typings/index.js +25 -0
  9. package/dist/node_modules/@commander-js/extra-typings/package.json +63 -0
  10. package/dist/node_modules/@esbuild/linux-x64/README.md +3 -0
  11. package/dist/node_modules/@esbuild/linux-x64/bin/esbuild +0 -0
  12. package/dist/node_modules/@esbuild/linux-x64/package.json +20 -0
  13. package/dist/node_modules/commander/LICENSE +22 -0
  14. package/dist/node_modules/commander/Readme.md +1149 -0
  15. package/dist/node_modules/commander/esm.mjs +16 -0
  16. package/dist/node_modules/commander/index.js +24 -0
  17. package/dist/node_modules/commander/lib/argument.js +149 -0
  18. package/dist/node_modules/commander/lib/command.js +2662 -0
  19. package/dist/node_modules/commander/lib/error.js +39 -0
  20. package/dist/node_modules/commander/lib/help.js +709 -0
  21. package/dist/node_modules/commander/lib/option.js +367 -0
  22. package/dist/node_modules/commander/lib/suggestSimilar.js +101 -0
  23. package/dist/node_modules/commander/package-support.json +16 -0
  24. package/dist/node_modules/commander/package.json +82 -0
  25. package/dist/node_modules/commander/typings/esm.d.mts +3 -0
  26. package/dist/node_modules/commander/typings/index.d.ts +1045 -0
  27. package/dist/node_modules/esbuild/LICENSE.md +21 -0
  28. package/dist/node_modules/esbuild/README.md +3 -0
  29. package/dist/node_modules/esbuild/bin/esbuild +0 -0
  30. package/dist/node_modules/esbuild/install.js +287 -0
  31. package/dist/node_modules/esbuild/lib/main.d.ts +705 -0
  32. package/dist/node_modules/esbuild/lib/main.js +2251 -0
  33. package/dist/node_modules/esbuild/package.json +48 -0
  34. package/dist/node_modules/get-tsconfig/LICENSE +21 -0
  35. package/dist/node_modules/get-tsconfig/README.md +235 -0
  36. package/dist/node_modules/get-tsconfig/dist/index.cjs +7 -0
  37. package/dist/node_modules/get-tsconfig/dist/index.d.cts +1439 -0
  38. package/dist/node_modules/get-tsconfig/dist/index.d.mts +1439 -0
  39. package/dist/node_modules/get-tsconfig/dist/index.mjs +7 -0
  40. package/dist/node_modules/get-tsconfig/package.json +46 -0
  41. package/dist/node_modules/resolve-pkg-maps/LICENSE +21 -0
  42. package/dist/node_modules/resolve-pkg-maps/README.md +216 -0
  43. package/dist/node_modules/resolve-pkg-maps/dist/index.cjs +1 -0
  44. package/dist/node_modules/resolve-pkg-maps/dist/index.d.cts +11 -0
  45. package/dist/node_modules/resolve-pkg-maps/dist/index.d.mts +11 -0
  46. package/dist/node_modules/resolve-pkg-maps/dist/index.mjs +1 -0
  47. package/dist/node_modules/resolve-pkg-maps/package.json +42 -0
  48. package/dist/node_modules/tsx/LICENSE +21 -0
  49. package/dist/node_modules/tsx/README.md +32 -0
  50. package/dist/node_modules/tsx/dist/cjs/api/index.cjs +1 -0
  51. package/dist/node_modules/tsx/dist/cjs/api/index.d.cts +35 -0
  52. package/dist/node_modules/tsx/dist/cjs/api/index.d.mts +35 -0
  53. package/dist/node_modules/tsx/dist/cjs/api/index.mjs +1 -0
  54. package/dist/node_modules/tsx/dist/cjs/index.cjs +1 -0
  55. package/dist/node_modules/tsx/dist/cjs/index.mjs +1 -0
  56. package/dist/node_modules/tsx/dist/cli.cjs +54 -0
  57. package/dist/node_modules/tsx/dist/cli.mjs +55 -0
  58. package/dist/node_modules/tsx/dist/client-BQVF1NaW.mjs +1 -0
  59. package/dist/node_modules/tsx/dist/client-D6NvIMSC.cjs +1 -0
  60. package/dist/node_modules/tsx/dist/esm/api/index.cjs +1 -0
  61. package/dist/node_modules/tsx/dist/esm/api/index.d.cts +35 -0
  62. package/dist/node_modules/tsx/dist/esm/api/index.d.mts +35 -0
  63. package/dist/node_modules/tsx/dist/esm/api/index.mjs +1 -0
  64. package/dist/node_modules/tsx/dist/esm/index.cjs +2 -0
  65. package/dist/node_modules/tsx/dist/esm/index.mjs +2 -0
  66. package/dist/node_modules/tsx/dist/get-pipe-path-BHW2eJdv.mjs +1 -0
  67. package/dist/node_modules/tsx/dist/get-pipe-path-BoR10qr8.cjs +1 -0
  68. package/dist/node_modules/tsx/dist/index-B4SIRlEU.cjs +16 -0
  69. package/dist/node_modules/tsx/dist/index-DlKgSVBb.mjs +16 -0
  70. package/dist/node_modules/tsx/dist/loader.cjs +1 -0
  71. package/dist/node_modules/tsx/dist/loader.mjs +1 -0
  72. package/dist/node_modules/tsx/dist/node-features-_8ZFwP_x.mjs +1 -0
  73. package/dist/node_modules/tsx/dist/node-features-roYmp9jK.cjs +1 -0
  74. package/dist/node_modules/tsx/dist/package--YiorJOq.mjs +1 -0
  75. package/dist/node_modules/tsx/dist/package-BUuKnQXZ.cjs +1 -0
  76. package/dist/node_modules/tsx/dist/patch-repl.cjs +1 -0
  77. package/dist/node_modules/tsx/dist/patch-repl.mjs +1 -0
  78. package/dist/node_modules/tsx/dist/preflight.cjs +1 -0
  79. package/dist/node_modules/tsx/dist/preflight.mjs +1 -0
  80. package/dist/node_modules/tsx/dist/register-C3TE0KFF.mjs +3 -0
  81. package/dist/node_modules/tsx/dist/register-CVZT-Tul.cjs +1 -0
  82. package/dist/node_modules/tsx/dist/register-DCnOAxY2.cjs +3 -0
  83. package/dist/node_modules/tsx/dist/register-RyGUjI6j.mjs +1 -0
  84. package/dist/node_modules/tsx/dist/repl.cjs +3 -0
  85. package/dist/node_modules/tsx/dist/repl.mjs +3 -0
  86. package/dist/node_modules/tsx/dist/require-BnyFnlmk.mjs +1 -0
  87. package/dist/node_modules/tsx/dist/require-DBpSESet.cjs +1 -0
  88. package/dist/node_modules/tsx/dist/suppress-warnings.cjs +1 -0
  89. package/dist/node_modules/tsx/dist/suppress-warnings.mjs +1 -0
  90. package/dist/node_modules/tsx/dist/temporary-directory-B83uKxJF.cjs +1 -0
  91. package/dist/node_modules/tsx/dist/temporary-directory-CwHp0_NW.mjs +1 -0
  92. package/dist/node_modules/tsx/dist/types-Cxp8y2TL.d.ts +5 -0
  93. package/dist/node_modules/tsx/package.json +68 -0
  94. package/dist/package.json +27 -0
  95. package/dist/sql/000000_schema.sql +150 -0
  96. package/dist/sql/000005_create_flow.sql +29 -0
  97. package/dist/sql/000010_add_step.sql +48 -0
  98. package/dist/sql/000015_start_ready_steps.sql +45 -0
  99. package/dist/sql/000020_start_flow.sql +46 -0
  100. package/dist/sql/000030_read_with_poll_backport.sql +70 -0
  101. package/dist/sql/000040_poll_for_tasks.sql +100 -0
  102. package/dist/sql/000045_maybe_complete_run.sql +30 -0
  103. package/dist/sql/000050_complete_task.sql +98 -0
  104. package/dist/sql/000055_calculate_retry_delay.sql +11 -0
  105. package/dist/sql/000060_fail_task.sql +124 -0
  106. package/dist/sql/000_edge_worker_initial.sql +86 -0
  107. package/dist/src/commands/install.d.ts +4 -0
  108. package/dist/src/commands/install.d.ts.map +1 -0
  109. package/dist/src/index.d.ts +2 -0
  110. package/dist/src/index.d.ts.map +1 -0
  111. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  112. package/package.json +23 -15
@@ -0,0 +1,1467 @@
1
+ // eslint complains about {} as a type, but hard to be more accurate.
2
+ /* eslint-disable @typescript-eslint/no-empty-object-type */
3
+
4
+ type TrimRight<S extends string> = S extends `${infer R} ` ? TrimRight<R> : S;
5
+ type TrimLeft<S extends string> = S extends ` ${infer R}` ? TrimLeft<R> : S;
6
+ type Trim<S extends string> = TrimLeft<TrimRight<S>>;
7
+
8
+ type CamelCase<S extends string> = S extends `${infer W}-${infer Rest}`
9
+ ? CamelCase<`${W}${Capitalize<Rest>}`>
10
+ : S;
11
+
12
+ // This is a trick to encourage TypeScript to resolve intersections for displaying,
13
+ // like { a: number } & { b : string } => { a: number, b: string }
14
+ // References:
15
+ // - https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
16
+ // - https://effectivetypescript.com/2022/02/25/gentips-4-display/
17
+ type Resolve<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
18
+
19
+ // This is a trick to encourage editor to suggest the known literals while still
20
+ // allowing any BaseType value.
21
+ // References:
22
+ // - https://github.com/microsoft/TypeScript/issues/29729
23
+ // - https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts
24
+ // - https://github.com/sindresorhus/type-fest/blob/main/source/primitive.d.ts
25
+ type LiteralUnion<LiteralType, BaseType extends string | number> =
26
+ | LiteralType
27
+ | (BaseType & Record<never, never>);
28
+
29
+ // Side note: not trying to represent arrays as non-empty, keep it simple.
30
+ // https://stackoverflow.com/a/56006703/1082434
31
+ type InferVariadic<S extends string, ArgT> = S extends `${string}...`
32
+ ? ArgT[]
33
+ : ArgT;
34
+
35
+ type InferArgumentType<Value extends string, DefaultT, CoerceT, ChoicesT> = [
36
+ CoerceT,
37
+ ] extends [undefined]
38
+ ?
39
+ | InferVariadic<Value, [ChoicesT] extends [undefined] ? string : ChoicesT>
40
+ | DefaultT
41
+ : [ChoicesT] extends [undefined]
42
+ ? CoerceT | DefaultT
43
+ : CoerceT | DefaultT | ChoicesT;
44
+
45
+ // Special handling for optional variadic argument, won't be undefined as implementation returns [].
46
+ type InferArgumentOptionalType<
47
+ Value extends string,
48
+ DefaultT,
49
+ CoerceT,
50
+ ChoicesT,
51
+ > = Value extends `${string}...`
52
+ ? InferArgumentType<
53
+ Value,
54
+ [DefaultT] extends [undefined] ? never : DefaultT,
55
+ CoerceT,
56
+ ChoicesT
57
+ >
58
+ : InferArgumentType<Value, DefaultT, CoerceT, ChoicesT>;
59
+
60
+ // ArgRequired comes from .argRequired()/.argOptional(), and ArgRequiredFromUsage is implied by usage <required>/[optional]
61
+ type ResolveRequired<
62
+ ArgRequired extends boolean | undefined,
63
+ ArgRequiredFromUsage extends boolean,
64
+ > = ArgRequired extends undefined ? ArgRequiredFromUsage : ArgRequired;
65
+
66
+ type InferArgumentTypeResolvedRequired<
67
+ Value extends string,
68
+ DefaultT,
69
+ CoerceT,
70
+ ArgRequired extends boolean,
71
+ ChoicesT,
72
+ > = ArgRequired extends true
73
+ ? InferArgumentType<Value, never, CoerceT, ChoicesT>
74
+ : InferArgumentOptionalType<Value, DefaultT, CoerceT, ChoicesT>;
75
+
76
+ // Resolve whether argument required, and strip []/<> from around value.
77
+ type InferArgument<
78
+ S extends string,
79
+ DefaultT = undefined,
80
+ CoerceT = undefined,
81
+ ArgRequired extends boolean | undefined = undefined,
82
+ ChoicesT = undefined,
83
+ > = S extends `<${infer Value}>`
84
+ ? InferArgumentTypeResolvedRequired<
85
+ Value,
86
+ DefaultT,
87
+ CoerceT,
88
+ ResolveRequired<ArgRequired, true>,
89
+ ChoicesT
90
+ >
91
+ : S extends `[${infer Value}]`
92
+ ? InferArgumentTypeResolvedRequired<
93
+ Value,
94
+ DefaultT,
95
+ CoerceT,
96
+ ResolveRequired<ArgRequired, false>,
97
+ ChoicesT
98
+ >
99
+ : InferArgumentTypeResolvedRequired<
100
+ S,
101
+ DefaultT,
102
+ CoerceT,
103
+ ResolveRequired<ArgRequired, true>,
104
+ ChoicesT
105
+ >; // the implementation fallback is treat as <required>
106
+
107
+ type InferArguments<S extends string> = S extends `${infer First} ${infer Rest}`
108
+ ? [InferArgument<First>, ...InferArguments<TrimLeft<Rest>>]
109
+ : [InferArgument<S>];
110
+
111
+ type InferCommandArguments<S extends string> =
112
+ S extends `${string} ${infer Args}` ? InferArguments<TrimLeft<Args>> : [];
113
+
114
+ type FlagsToFlag<Flags extends string> =
115
+ Flags extends `${string},${infer LongFlag}`
116
+ ? TrimLeft<LongFlag>
117
+ : Flags extends `${string}|${infer LongFlag}`
118
+ ? TrimLeft<LongFlag>
119
+ : Flags extends `${string} ${infer LongFlag}`
120
+ ? TrimLeft<LongFlag>
121
+ : Flags;
122
+
123
+ type ConvertFlagToName<Flag extends string> = Flag extends `--no-${infer Name}`
124
+ ? CamelCase<Name>
125
+ : Flag extends `--${infer Name}`
126
+ ? CamelCase<Name>
127
+ : Flag extends `-${infer Name}`
128
+ ? CamelCase<Name>
129
+ : never;
130
+
131
+ type CombineOptions<Options, O> = keyof O extends keyof Options
132
+ ? {
133
+ [K in keyof Options]: K extends keyof O
134
+ ? Options[K] | O[keyof O]
135
+ : Options[K];
136
+ }
137
+ : Options & O;
138
+
139
+ type IsAlwaysDefined<
140
+ DefaulT,
141
+ Mandatory extends boolean,
142
+ > = Mandatory extends true
143
+ ? true
144
+ : [undefined] extends [DefaulT]
145
+ ? false
146
+ : true;
147
+
148
+ // Modify PresetT to take into account negated.
149
+ type NegatePresetType<
150
+ Flag extends string,
151
+ PresetT,
152
+ > = Flag extends `--no-${string}`
153
+ ? undefined extends PresetT
154
+ ? false
155
+ : PresetT
156
+ : undefined extends PresetT
157
+ ? true
158
+ : PresetT;
159
+
160
+ // Modify DefaultT to take into account negated.
161
+ type NegateDefaultType<
162
+ Flag extends string,
163
+ DefaultT,
164
+ > = Flag extends `--no-${string}`
165
+ ? [undefined] extends [DefaultT]
166
+ ? true
167
+ : DefaultT
168
+ : [undefined] extends [DefaultT]
169
+ ? never
170
+ : DefaultT; // don't add undefined, will make property optional later
171
+
172
+ // Modify ValueT to take into account coerce function.
173
+ type CoerceValueType<CoerceT, ValueT> = [ValueT] extends [never]
174
+ ? never
175
+ : [CoerceT] extends [undefined]
176
+ ? ValueT
177
+ : CoerceT;
178
+
179
+ // Modify PresetT to take into account coerce function.
180
+ type CoercePresetType<CoerceT, PresetT> = [PresetT] extends [never]
181
+ ? never
182
+ : [CoerceT] extends [undefined]
183
+ ? PresetT
184
+ : undefined extends PresetT
185
+ ? undefined
186
+ : CoerceT;
187
+
188
+ type BuildOptionProperty<
189
+ Name extends string,
190
+ FullValueT,
191
+ AlwaysDefined extends boolean,
192
+ > = AlwaysDefined extends true
193
+ ? { [K in Name]: FullValueT }
194
+ : { [K in Name]?: FullValueT };
195
+
196
+ type InferOptionsCombine<
197
+ Options,
198
+ Name extends string,
199
+ FullValueT,
200
+ AlwaysDefined extends boolean,
201
+ > = Resolve<
202
+ CombineOptions<Options, BuildOptionProperty<Name, FullValueT, AlwaysDefined>>
203
+ >;
204
+
205
+ // Combine the possible types
206
+ type InferOptionsNegateCombo<
207
+ Options,
208
+ Flag extends string,
209
+ Name extends string,
210
+ ValueT,
211
+ PresetT,
212
+ DefaultT,
213
+ AlwaysDefined extends boolean,
214
+ > = Flag extends `--no-${string}`
215
+ ? Name extends keyof Options
216
+ ? InferOptionsCombine<Options, Name, PresetT, true> // combo does not set default, leave that to positive option
217
+ : InferOptionsCombine<Options, Name, PresetT | DefaultT, true> // lone negated option sets default
218
+ : InferOptionsCombine<
219
+ Options,
220
+ Name,
221
+ ValueT | PresetT | DefaultT,
222
+ AlwaysDefined
223
+ >;
224
+
225
+ // Recalc values taking into account negated option.
226
+ // Fill in appropriate PresetT value if undefined.
227
+ type InferOptionTypes<
228
+ Options,
229
+ Flag extends string,
230
+ Value extends string,
231
+ ValueT,
232
+ PresetT,
233
+ DefaultT,
234
+ CoerceT,
235
+ Mandatory extends boolean,
236
+ ChoicesT,
237
+ > = InferOptionsNegateCombo<
238
+ Options,
239
+ Flag,
240
+ ConvertFlagToName<Flag>,
241
+ CoerceValueType<
242
+ CoerceT,
243
+ [ChoicesT] extends [undefined]
244
+ ? InferVariadic<Value, ValueT>
245
+ : InferVariadic<Value, ChoicesT>
246
+ >,
247
+ NegatePresetType<Flag, CoercePresetType<CoerceT, PresetT>>,
248
+ NegateDefaultType<Flag, DefaultT>,
249
+ IsAlwaysDefined<DefaultT, Mandatory>
250
+ >;
251
+
252
+ type InferOptionsFlag<
253
+ Options,
254
+ Flags extends string,
255
+ Value extends string,
256
+ ValueT,
257
+ PresetT,
258
+ DefaultT,
259
+ CoerceT,
260
+ Mandatory extends boolean,
261
+ ChoicesT,
262
+ > = InferOptionTypes<
263
+ Options,
264
+ FlagsToFlag<Trim<Flags>>,
265
+ Trim<Value>,
266
+ ValueT,
267
+ PresetT,
268
+ DefaultT,
269
+ CoerceT,
270
+ Mandatory,
271
+ ChoicesT
272
+ >;
273
+
274
+ // Split up Usage into Flags and Value
275
+ type InferOptions<
276
+ Options,
277
+ Usage extends string,
278
+ DefaultT,
279
+ CoerceT,
280
+ Mandatory extends boolean,
281
+ PresetT = undefined,
282
+ ChoicesT = undefined,
283
+ > = Usage extends `${infer Flags} <${infer Value}>`
284
+ ? InferOptionsFlag<
285
+ Options,
286
+ Flags,
287
+ Value,
288
+ string,
289
+ never,
290
+ DefaultT,
291
+ CoerceT,
292
+ Mandatory,
293
+ ChoicesT
294
+ >
295
+ : Usage extends `${infer Flags} [${infer Value}]`
296
+ ? InferOptionsFlag<
297
+ Options,
298
+ Flags,
299
+ Value,
300
+ string,
301
+ PresetT,
302
+ DefaultT,
303
+ CoerceT,
304
+ Mandatory,
305
+ ChoicesT
306
+ >
307
+ : InferOptionsFlag<
308
+ Options,
309
+ Usage,
310
+ '',
311
+ never,
312
+ PresetT,
313
+ DefaultT,
314
+ CoerceT,
315
+ Mandatory,
316
+ ChoicesT
317
+ >;
318
+
319
+ export type CommandUnknownOpts = Command<unknown[], OptionValues, OptionValues>;
320
+
321
+ // ----- full copy of normal commander typings from here down, with extra type inference -----
322
+
323
+ /* eslint-disable @typescript-eslint/no-explicit-any */
324
+
325
+ export class CommanderError extends Error {
326
+ code: string;
327
+ exitCode: number;
328
+ message: string;
329
+ nestedError?: string;
330
+
331
+ /**
332
+ * Constructs the CommanderError class
333
+ * @param exitCode - suggested exit code which could be used with process.exit
334
+ * @param code - an id string representing the error
335
+ * @param message - human-readable description of the error
336
+ * @constructor
337
+ */
338
+ constructor(exitCode: number, code: string, message: string);
339
+ }
340
+
341
+ export class InvalidArgumentError extends CommanderError {
342
+ /**
343
+ * Constructs the InvalidArgumentError class
344
+ * @param message - explanation of why argument is invalid
345
+ * @constructor
346
+ */
347
+ constructor(message: string);
348
+ }
349
+ export { InvalidArgumentError as InvalidOptionArgumentError }; // deprecated old name
350
+
351
+ export interface ErrorOptions {
352
+ // optional parameter for error()
353
+ /** an id string representing the error */
354
+ code?: string;
355
+ /** suggested exit code which could be used with process.exit */
356
+ exitCode?: number;
357
+ }
358
+
359
+ export class Argument<
360
+ Usage extends string = '',
361
+ DefaultT = undefined,
362
+ CoerceT = undefined,
363
+ ArgRequired extends boolean | undefined = undefined,
364
+ ChoicesT = undefined,
365
+ > {
366
+ description: string;
367
+ required: boolean;
368
+ variadic: boolean;
369
+ defaultValue?: any;
370
+ defaultValueDescription?: string;
371
+ argChoices?: string[];
372
+
373
+ /**
374
+ * Initialize a new command argument with the given name and description.
375
+ * The default is that the argument is required, and you can explicitly
376
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
377
+ */
378
+ constructor(arg: Usage, description?: string);
379
+
380
+ /**
381
+ * Return argument name.
382
+ */
383
+ name(): string;
384
+
385
+ /**
386
+ * Set the default value, and optionally supply the description to be displayed in the help.
387
+ */
388
+ default<const T>(
389
+ value: T,
390
+ description?: string,
391
+ ): Argument<Usage, T, CoerceT, ArgRequired, ChoicesT>;
392
+
393
+ /**
394
+ * Set the custom handler for processing CLI command arguments into argument values.
395
+ */
396
+ argParser<T>(
397
+ fn: (value: string, previous: T) => T,
398
+ ): Argument<Usage, DefaultT, T, ArgRequired, undefined>; // setting ChoicesT to undefined because argParser overwrites choices
399
+
400
+ /**
401
+ * Only allow argument value to be one of choices.
402
+ */
403
+ choices<const T extends readonly string[]>(
404
+ values: T,
405
+ ): Argument<Usage, DefaultT, undefined, ArgRequired, T[number]>; // setting CoerceT to undefined because choices overrides argParser
406
+
407
+ /**
408
+ * Make argument required.
409
+ */
410
+ argRequired(): Argument<Usage, DefaultT, CoerceT, true, ChoicesT>;
411
+
412
+ /**
413
+ * Make argument optional.
414
+ */
415
+ argOptional(): Argument<Usage, DefaultT, CoerceT, false, ChoicesT>;
416
+ }
417
+
418
+ export class Option<
419
+ Usage extends string = '',
420
+ PresetT = undefined,
421
+ DefaultT = undefined,
422
+ CoerceT = undefined,
423
+ Mandatory extends boolean = false,
424
+ ChoicesT = undefined,
425
+ > {
426
+ flags: string;
427
+ description: string;
428
+
429
+ required: boolean; // A value must be supplied when the option is specified.
430
+ optional: boolean; // A value is optional when the option is specified.
431
+ variadic: boolean;
432
+ mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line.
433
+ short?: string;
434
+ long?: string;
435
+ negate: boolean;
436
+ defaultValue?: any;
437
+ defaultValueDescription?: string;
438
+ presetArg?: unknown;
439
+ envVar?: string;
440
+ parseArg?: <T>(value: string, previous: T) => T;
441
+ hidden: boolean;
442
+ argChoices?: string[];
443
+
444
+ constructor(flags: Usage, description?: string);
445
+
446
+ /**
447
+ * Set the default value, and optionally supply the description to be displayed in the help.
448
+ */
449
+ default<const T>(
450
+ value: T,
451
+ description?: string,
452
+ ): Option<Usage, PresetT, T, CoerceT, Mandatory, ChoicesT>;
453
+
454
+ /**
455
+ * Preset to use when option used without option-argument, especially optional but also boolean and negated.
456
+ * The custom processing (parseArg) is called.
457
+ *
458
+ * @example
459
+ * ```ts
460
+ * new Option('--color').default('GREYSCALE').preset('RGB');
461
+ * new Option('--donate [amount]').preset('20').argParser(parseFloat);
462
+ * ```
463
+ */
464
+ preset<const T>(
465
+ arg: T,
466
+ ): Option<Usage, T, DefaultT, CoerceT, Mandatory, ChoicesT>;
467
+
468
+ /**
469
+ * Add option name(s) that conflict with this option.
470
+ * An error will be displayed if conflicting options are found during parsing.
471
+ *
472
+ * @example
473
+ * ```ts
474
+ * new Option('--rgb').conflicts('cmyk');
475
+ * new Option('--js').conflicts(['ts', 'jsx']);
476
+ * ```
477
+ */
478
+ conflicts(names: string | string[]): this;
479
+
480
+ /**
481
+ * Specify implied option values for when this option is set and the implied options are not.
482
+ *
483
+ * The custom processing (parseArg) is not called on the implied values.
484
+ *
485
+ * @example
486
+ * program
487
+ * .addOption(new Option('--log', 'write logging information to file'))
488
+ * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
489
+ */
490
+ implies(optionValues: OptionValues): this;
491
+
492
+ /**
493
+ * Set environment variable to check for option value.
494
+ *
495
+ * An environment variables is only used if when processed the current option value is
496
+ * undefined, or the source of the current value is 'default' or 'config' or 'env'.
497
+ */
498
+ env(name: string): this;
499
+
500
+ /**
501
+ * Set the custom handler for processing CLI option arguments into option values.
502
+ */
503
+ argParser<T>(
504
+ fn: (value: string, previous: T) => T,
505
+ ): Option<Usage, PresetT, DefaultT, T, Mandatory, undefined>; // setting ChoicesT to undefined because argParser overrides choices
506
+
507
+ /**
508
+ * Whether the option is mandatory and must have a value after parsing.
509
+ */
510
+ makeOptionMandatory<M extends boolean = true>(
511
+ mandatory?: M,
512
+ ): Option<Usage, PresetT, DefaultT, CoerceT, M, ChoicesT>;
513
+
514
+ /**
515
+ * Hide option in help.
516
+ */
517
+ hideHelp(hide?: boolean): this;
518
+
519
+ /**
520
+ * Only allow option value to be one of choices.
521
+ */
522
+ choices<const T extends readonly string[]>(
523
+ values: T,
524
+ ): Option<Usage, PresetT, DefaultT, undefined, Mandatory, T[number]>; // setting CoerceT to undefined becuase choices overrides argParser
525
+
526
+ /**
527
+ * Return option name.
528
+ */
529
+ name(): string;
530
+
531
+ /**
532
+ * Return option name, in a camelcase format that can be used
533
+ * as an object attribute key.
534
+ */
535
+ attributeName(): string;
536
+
537
+ /**
538
+ * Return whether a boolean option.
539
+ *
540
+ * Options are one of boolean, negated, required argument, or optional argument.
541
+ */
542
+ isBoolean(): boolean;
543
+ }
544
+
545
+ export class Help {
546
+ /** output helpWidth, long lines are wrapped to fit */
547
+ helpWidth?: number;
548
+ minWidthToWrap: number;
549
+ sortSubcommands: boolean;
550
+ sortOptions: boolean;
551
+ showGlobalOptions: boolean;
552
+
553
+ constructor();
554
+
555
+ /*
556
+ * prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
557
+ * and just before calling `formatHelp()`.
558
+ *
559
+ * Commander just uses the helpWidth and the others are provided for subclasses.
560
+ */
561
+ prepareContext(contextOptions: {
562
+ error?: boolean;
563
+ helpWidth?: number;
564
+ outputHasColors?: boolean;
565
+ }): void;
566
+
567
+ /** Get the command term to show in the list of subcommands. */
568
+ subcommandTerm(cmd: CommandUnknownOpts): string;
569
+ /** Get the command summary to show in the list of subcommands. */
570
+ subcommandDescription(cmd: CommandUnknownOpts): string;
571
+ /** Get the option term to show in the list of options. */
572
+ optionTerm(option: Option): string;
573
+ /** Get the option description to show in the list of options. */
574
+ optionDescription(option: Option): string;
575
+ /** Get the argument term to show in the list of arguments. */
576
+ argumentTerm(argument: Argument): string;
577
+ /** Get the argument description to show in the list of arguments. */
578
+ argumentDescription(argument: Argument): string;
579
+
580
+ /** Get the command usage to be displayed at the top of the built-in help. */
581
+ commandUsage(cmd: CommandUnknownOpts): string;
582
+ /** Get the description for the command. */
583
+ commandDescription(cmd: CommandUnknownOpts): string;
584
+
585
+ /** Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one. */
586
+ visibleCommands(cmd: CommandUnknownOpts): CommandUnknownOpts[];
587
+ /** Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one. */
588
+ visibleOptions(cmd: CommandUnknownOpts): Option[];
589
+ /** Get an array of the visible global options. (Not including help.) */
590
+ visibleGlobalOptions(cmd: CommandUnknownOpts): Option[];
591
+ /** Get an array of the arguments which have descriptions. */
592
+ visibleArguments(cmd: CommandUnknownOpts): Argument[];
593
+
594
+ /** Get the longest command term length. */
595
+ longestSubcommandTermLength(cmd: CommandUnknownOpts, helper: Help): number;
596
+ /** Get the longest option term length. */
597
+ longestOptionTermLength(cmd: CommandUnknownOpts, helper: Help): number;
598
+ /** Get the longest global option term length. */
599
+ longestGlobalOptionTermLength(cmd: CommandUnknownOpts, helper: Help): number;
600
+ /** Get the longest argument term length. */
601
+ longestArgumentTermLength(cmd: CommandUnknownOpts, helper: Help): number;
602
+
603
+ /** Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations. */
604
+ displayWidth(str: string): number;
605
+
606
+ /** Style the titles. Called with 'Usage:', 'Options:', etc. */
607
+ styleTitle(title: string): string;
608
+
609
+ /** Usage: <str> */
610
+ styleUsage(str: string): string;
611
+ /** Style for command name in usage string. */
612
+ styleCommandText(str: string): string;
613
+
614
+ styleCommandDescription(str: string): string;
615
+ styleOptionDescription(str: string): string;
616
+ styleSubcommandDescription(str: string): string;
617
+ styleArgumentDescription(str: string): string;
618
+ /** Base style used by descriptions. */
619
+ styleDescriptionText(str: string): string;
620
+
621
+ styleOptionTerm(str: string): string;
622
+ styleSubcommandTerm(str: string): string;
623
+ styleArgumentTerm(str: string): string;
624
+
625
+ /** Base style used in terms and usage for options. */
626
+ styleOptionText(str: string): string;
627
+ /** Base style used in terms and usage for subcommands. */
628
+ styleSubcommandText(str: string): string;
629
+ /** Base style used in terms and usage for arguments. */
630
+ styleArgumentText(str: string): string;
631
+
632
+ /** Calculate the pad width from the maximum term length. */
633
+ padWidth(cmd: CommandUnknownOpts, helper: Help): number;
634
+
635
+ /**
636
+ * Wrap a string at whitespace, preserving existing line breaks.
637
+ * Wrapping is skipped if the width is less than `minWidthToWrap`.
638
+ */
639
+ boxWrap(str: string, width: number): string;
640
+
641
+ /** Detect manually wrapped and indented strings by checking for line break followed by whitespace. */
642
+ preformatted(str: string): boolean;
643
+
644
+ /**
645
+ * Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
646
+ *
647
+ * So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
648
+ * TTT DDD DDDD
649
+ * DD DDD
650
+ */
651
+ formatItem(
652
+ term: string,
653
+ termWidth: number,
654
+ description: string,
655
+ helper: Help,
656
+ ): string;
657
+
658
+ /** Generate the built-in help text. */
659
+ formatHelp(cmd: CommandUnknownOpts, helper: Help): string;
660
+ }
661
+ export type HelpConfiguration = Partial<Help>;
662
+
663
+ export interface ParseOptions {
664
+ from: 'node' | 'electron' | 'user';
665
+ }
666
+ export interface HelpContext {
667
+ // optional parameter for .help() and .outputHelp()
668
+ error: boolean;
669
+ }
670
+ export interface AddHelpTextContext {
671
+ // passed to text function used with .addHelpText()
672
+ error: boolean;
673
+ command: Command;
674
+ }
675
+ export interface OutputConfiguration {
676
+ writeOut?(str: string): void;
677
+ writeErr?(str: string): void;
678
+ outputError?(str: string, write: (str: string) => void): void;
679
+
680
+ getOutHelpWidth?(): number;
681
+ getErrHelpWidth?(): number;
682
+
683
+ getOutHasColors?(): boolean;
684
+ getErrHasColors?(): boolean;
685
+ stripColor?(str: string): string;
686
+ }
687
+
688
+ export type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';
689
+ export type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';
690
+ // The source is a string so author can define their own too.
691
+ export type OptionValueSource =
692
+ | LiteralUnion<'default' | 'config' | 'env' | 'cli' | 'implied', string>
693
+ | undefined;
694
+
695
+ export type OptionValues = Record<string, unknown>;
696
+
697
+ export class Command<
698
+ Args extends any[] = [],
699
+ Opts extends OptionValues = {},
700
+ GlobalOpts extends OptionValues = {},
701
+ > {
702
+ args: string[];
703
+ processedArgs: Args;
704
+ readonly commands: readonly CommandUnknownOpts[];
705
+ readonly options: readonly Option[];
706
+ readonly registeredArguments: readonly Argument[];
707
+ parent: CommandUnknownOpts | null;
708
+
709
+ constructor(name?: string);
710
+
711
+ /**
712
+ * Set the program version to `str`.
713
+ *
714
+ * This method auto-registers the "-V, --version" flag
715
+ * which will print the version number when passed.
716
+ *
717
+ * You can optionally supply the flags and description to override the defaults.
718
+ */
719
+ version(str: string, flags?: string, description?: string): this;
720
+ /**
721
+ * Get the program version.
722
+ */
723
+ version(): string | undefined;
724
+ /**
725
+ * Define a command, implemented using an action handler.
726
+ *
727
+ * @remarks
728
+ * The command description is supplied using `.description`, not as a parameter to `.command`.
729
+ *
730
+ * @example
731
+ * ```ts
732
+ * program
733
+ * .command('clone <source> [destination]')
734
+ * .description('clone a repository into a newly created directory')
735
+ * .action((source, destination) => {
736
+ * console.log('clone command called');
737
+ * });
738
+ * ```
739
+ *
740
+ * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
741
+ * @param opts - configuration options
742
+ * @returns new command
743
+ */
744
+ command<Usage extends string>(
745
+ nameAndArgs: Usage,
746
+ opts?: CommandOptions,
747
+ ): Command<[...InferCommandArguments<Usage>], {}, Opts & GlobalOpts>;
748
+ /**
749
+ * Define a command, implemented in a separate executable file.
750
+ *
751
+ * @remarks
752
+ * The command description is supplied as the second parameter to `.command`.
753
+ *
754
+ * @example
755
+ * ```ts
756
+ * program
757
+ * .command('start <service>', 'start named service')
758
+ * .command('stop [service]', 'stop named service, or all if no name supplied');
759
+ * ```
760
+ *
761
+ * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
762
+ * @param description - description of executable command
763
+ * @param opts - configuration options
764
+ * @returns `this` command for chaining
765
+ */
766
+ command(
767
+ nameAndArgs: string,
768
+ description: string,
769
+ opts?: ExecutableCommandOptions,
770
+ ): this;
771
+
772
+ /**
773
+ * Factory routine to create a new unattached command.
774
+ *
775
+ * See .command() for creating an attached subcommand, which uses this routine to
776
+ * create the command. You can override createCommand to customise subcommands.
777
+ */
778
+ createCommand(name?: string): Command;
779
+
780
+ /**
781
+ * Add a prepared subcommand.
782
+ *
783
+ * See .command() for creating an attached subcommand which inherits settings from its parent.
784
+ *
785
+ * @returns `this` command for chaining
786
+ */
787
+ addCommand(cmd: CommandUnknownOpts, opts?: CommandOptions): this;
788
+
789
+ /**
790
+ * Factory routine to create a new unattached argument.
791
+ *
792
+ * See .argument() for creating an attached argument, which uses this routine to
793
+ * create the argument. You can override createArgument to return a custom argument.
794
+ */
795
+ createArgument<Usage extends string>(
796
+ name: Usage,
797
+ description?: string,
798
+ ): Argument<Usage>;
799
+
800
+ /**
801
+ * Define argument syntax for command.
802
+ *
803
+ * The default is that the argument is required, and you can explicitly
804
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
805
+ *
806
+ * @example
807
+ * ```
808
+ * program.argument('<input-file>');
809
+ * program.argument('[output-file]');
810
+ * ```
811
+ *
812
+ * @returns `this` command for chaining
813
+ */
814
+ argument<S extends string, T>(
815
+ flags: S,
816
+ description: string,
817
+ fn: (value: string, previous: T) => T,
818
+ ): Command<[...Args, InferArgument<S, undefined, T>], Opts, GlobalOpts>;
819
+ argument<S extends string, T>(
820
+ flags: S,
821
+ description: string,
822
+ fn: (value: string, previous: T) => T,
823
+ defaultValue: T,
824
+ ): Command<[...Args, InferArgument<S, T, T>], Opts, GlobalOpts>;
825
+ argument<S extends string>(
826
+ usage: S,
827
+ description?: string,
828
+ ): Command<[...Args, InferArgument<S, undefined>], Opts, GlobalOpts>;
829
+ argument<S extends string, DefaultT>(
830
+ usage: S,
831
+ description: string,
832
+ defaultValue: DefaultT,
833
+ ): Command<[...Args, InferArgument<S, DefaultT>], Opts, GlobalOpts>;
834
+
835
+ /**
836
+ * Define argument syntax for command, adding a prepared argument.
837
+ *
838
+ * @returns `this` command for chaining
839
+ */
840
+ addArgument<
841
+ Usage extends string,
842
+ DefaultT,
843
+ CoerceT,
844
+ ArgRequired extends boolean | undefined,
845
+ ChoicesT,
846
+ >(
847
+ arg: Argument<Usage, DefaultT, CoerceT, ArgRequired, ChoicesT>,
848
+ ): Command<
849
+ [...Args, InferArgument<Usage, DefaultT, CoerceT, ArgRequired, ChoicesT>],
850
+ Opts,
851
+ GlobalOpts
852
+ >;
853
+
854
+ /**
855
+ * Define argument syntax for command, adding multiple at once (without descriptions).
856
+ *
857
+ * See also .argument().
858
+ *
859
+ * @example
860
+ * ```
861
+ * program.arguments('<cmd> [env]');
862
+ * ```
863
+ *
864
+ * @returns `this` command for chaining
865
+ */
866
+ arguments<Names extends string>(
867
+ args: Names,
868
+ ): Command<[...Args, ...InferArguments<Names>], Opts, GlobalOpts>;
869
+
870
+ /**
871
+ * Customise or override default help command. By default a help command is automatically added if your command has subcommands.
872
+ *
873
+ * @example
874
+ * ```ts
875
+ * program.helpCommand('help [cmd]');
876
+ * program.helpCommand('help [cmd]', 'show help');
877
+ * program.helpCommand(false); // suppress default help command
878
+ * program.helpCommand(true); // add help command even if no subcommands
879
+ * ```
880
+ */
881
+ helpCommand(nameAndArgs: string, description?: string): this;
882
+ helpCommand(enable: boolean): this;
883
+
884
+ /**
885
+ * Add prepared custom help command.
886
+ */
887
+ addHelpCommand(cmd: Command): this;
888
+ /** @deprecated since v12, instead use helpCommand */
889
+ addHelpCommand(nameAndArgs: string, description?: string): this;
890
+ /** @deprecated since v12, instead use helpCommand */
891
+ addHelpCommand(enable?: boolean): this;
892
+
893
+ /**
894
+ * Add hook for life cycle event.
895
+ */
896
+ hook(
897
+ event: HookEvent,
898
+ listener: (
899
+ thisCommand: this,
900
+ actionCommand: CommandUnknownOpts,
901
+ ) => void | Promise<void>,
902
+ ): this;
903
+
904
+ /**
905
+ * Register callback to use as replacement for calling process.exit.
906
+ */
907
+ exitOverride(callback?: (err: CommanderError) => never | void): this;
908
+
909
+ /**
910
+ * Display error message and exit (or call exitOverride).
911
+ */
912
+ error(message: string, errorOptions?: ErrorOptions): never;
913
+
914
+ /**
915
+ * You can customise the help with a subclass of Help by overriding createHelp,
916
+ * or by overriding Help properties using configureHelp().
917
+ */
918
+ createHelp(): Help;
919
+
920
+ /**
921
+ * You can customise the help by overriding Help properties using configureHelp(),
922
+ * or with a subclass of Help by overriding createHelp().
923
+ */
924
+ configureHelp(configuration: HelpConfiguration): this;
925
+ /** Get configuration */
926
+ configureHelp(): HelpConfiguration;
927
+
928
+ /**
929
+ * The default output goes to stdout and stderr. You can customise this for special
930
+ * applications. You can also customise the display of errors by overriding outputError.
931
+ *
932
+ * The configuration properties are all functions:
933
+ * ```
934
+ * // functions to change where being written, stdout and stderr
935
+ * writeOut(str)
936
+ * writeErr(str)
937
+ * // matching functions to specify width for wrapping help
938
+ * getOutHelpWidth()
939
+ * getErrHelpWidth()
940
+ * // functions based on what is being written out
941
+ * outputError(str, write) // used for displaying errors, and not used for displaying help
942
+ * ```
943
+ */
944
+ configureOutput(configuration: OutputConfiguration): this;
945
+ /** Get configuration */
946
+ configureOutput(): OutputConfiguration;
947
+
948
+ /**
949
+ * Copy settings that are useful to have in common across root command and subcommands.
950
+ *
951
+ * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
952
+ */
953
+ copyInheritedSettings(sourceCommand: CommandUnknownOpts): this;
954
+
955
+ /**
956
+ * Display the help or a custom message after an error occurs.
957
+ */
958
+ showHelpAfterError(displayHelp?: boolean | string): this;
959
+
960
+ /**
961
+ * Display suggestion of similar commands for unknown commands, or options for unknown options.
962
+ */
963
+ showSuggestionAfterError(displaySuggestion?: boolean): this;
964
+
965
+ /**
966
+ * Register callback `fn` for the command.
967
+ *
968
+ * @example
969
+ * ```
970
+ * program
971
+ * .command('serve')
972
+ * .description('start service')
973
+ * .action(function() {
974
+ * // do work here
975
+ * });
976
+ * ```
977
+ *
978
+ * @returns `this` command for chaining
979
+ */
980
+ action(
981
+ fn: (this: this, ...args: [...Args, Opts, this]) => void | Promise<void>,
982
+ ): this;
983
+
984
+ /**
985
+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
986
+ *
987
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
988
+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.
989
+ *
990
+ * See the README for more details, and see also addOption() and requiredOption().
991
+ *
992
+ * @example
993
+ *
994
+ * ```js
995
+ * program
996
+ * .option('-p, --pepper', 'add pepper')
997
+ * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
998
+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
999
+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
1000
+ * ```
1001
+ *
1002
+ * @returns `this` command for chaining
1003
+ */
1004
+ option<S extends string>(
1005
+ usage: S,
1006
+ description?: string,
1007
+ ): Command<
1008
+ Args,
1009
+ InferOptions<Opts, S, undefined, undefined, false>,
1010
+ GlobalOpts
1011
+ >;
1012
+ option<S extends string, DefaultT extends string | boolean | string[] | []>(
1013
+ usage: S,
1014
+ description?: string,
1015
+ defaultValue?: DefaultT,
1016
+ ): Command<
1017
+ Args,
1018
+ InferOptions<Opts, S, DefaultT, undefined, false>,
1019
+ GlobalOpts
1020
+ >;
1021
+ option<S extends string, T>(
1022
+ usage: S,
1023
+ description: string,
1024
+ parseArg: (value: string, previous: T) => T,
1025
+ ): Command<Args, InferOptions<Opts, S, undefined, T, false>, GlobalOpts>;
1026
+ option<S extends string, T>(
1027
+ usage: S,
1028
+ description: string,
1029
+ parseArg: (value: string, previous: T) => T,
1030
+ defaultValue?: T,
1031
+ ): Command<Args, InferOptions<Opts, S, T, T, false>, GlobalOpts>;
1032
+
1033
+ /**
1034
+ * Define a required option, which must have a value after parsing. This usually means
1035
+ * the option must be specified on the command line. (Otherwise the same as .option().)
1036
+ *
1037
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
1038
+ */
1039
+ requiredOption<S extends string>(
1040
+ usage: S,
1041
+ description?: string,
1042
+ ): Command<
1043
+ Args,
1044
+ InferOptions<Opts, S, undefined, undefined, true>,
1045
+ GlobalOpts
1046
+ >;
1047
+ requiredOption<
1048
+ S extends string,
1049
+ DefaultT extends string | boolean | string[],
1050
+ >(
1051
+ usage: S,
1052
+ description?: string,
1053
+ defaultValue?: DefaultT,
1054
+ ): Command<
1055
+ Args,
1056
+ InferOptions<Opts, S, DefaultT, undefined, true>,
1057
+ GlobalOpts
1058
+ >;
1059
+ requiredOption<S extends string, T>(
1060
+ usage: S,
1061
+ description: string,
1062
+ parseArg: (value: string, previous: T) => T,
1063
+ ): Command<Args, InferOptions<Opts, S, undefined, T, true>, GlobalOpts>;
1064
+ requiredOption<S extends string, T, D extends T>(
1065
+ usage: S,
1066
+ description: string,
1067
+ parseArg: (value: string, previous: T) => T,
1068
+ defaultValue?: D,
1069
+ ): Command<Args, InferOptions<Opts, S, D, T, true>, GlobalOpts>;
1070
+
1071
+ /**
1072
+ * Factory routine to create a new unattached option.
1073
+ *
1074
+ * See .option() for creating an attached option, which uses this routine to
1075
+ * create the option. You can override createOption to return a custom option.
1076
+ */
1077
+
1078
+ createOption<Usage extends string>(
1079
+ flags: Usage,
1080
+ description?: string,
1081
+ ): Option<Usage>;
1082
+
1083
+ /**
1084
+ * Add a prepared Option.
1085
+ *
1086
+ * See .option() and .requiredOption() for creating and attaching an option in a single call.
1087
+ */
1088
+ addOption<
1089
+ Usage extends string,
1090
+ PresetT,
1091
+ DefaultT,
1092
+ CoerceT,
1093
+ Mandatory extends boolean,
1094
+ ChoicesT,
1095
+ >(
1096
+ option: Option<Usage, PresetT, DefaultT, CoerceT, Mandatory, ChoicesT>,
1097
+ ): Command<
1098
+ Args,
1099
+ InferOptions<Opts, Usage, DefaultT, CoerceT, Mandatory, PresetT, ChoicesT>,
1100
+ GlobalOpts
1101
+ >;
1102
+
1103
+ /**
1104
+ * Whether to store option values as properties on command object,
1105
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
1106
+ *
1107
+ * @returns `this` command for chaining
1108
+ */
1109
+ storeOptionsAsProperties<T extends OptionValues>(): this & T;
1110
+ storeOptionsAsProperties<T extends OptionValues>(
1111
+ storeAsProperties: true,
1112
+ ): this & T;
1113
+ storeOptionsAsProperties(storeAsProperties?: boolean): this;
1114
+
1115
+ /**
1116
+ * Retrieve option value.
1117
+ */
1118
+ getOptionValue<K extends keyof Opts>(key: K): Opts[K];
1119
+ getOptionValue(key: string): unknown;
1120
+
1121
+ /**
1122
+ * Store option value.
1123
+ */
1124
+ setOptionValue<K extends keyof Opts>(key: K, value: unknown): this;
1125
+ setOptionValue(key: string, value: unknown): this;
1126
+
1127
+ /**
1128
+ * Store option value and where the value came from.
1129
+ */
1130
+ setOptionValueWithSource<K extends keyof Opts>(
1131
+ key: K,
1132
+ value: unknown,
1133
+ source: OptionValueSource,
1134
+ ): this;
1135
+ setOptionValueWithSource(
1136
+ key: string,
1137
+ value: unknown,
1138
+ source: OptionValueSource,
1139
+ ): this;
1140
+
1141
+ /**
1142
+ * Get source of option value.
1143
+ */
1144
+ getOptionValueSource<K extends keyof Opts>(
1145
+ key: K,
1146
+ ): OptionValueSource | undefined;
1147
+ getOptionValueSource(key: string): OptionValueSource | undefined;
1148
+
1149
+ /**
1150
+ * Get source of option value. See also .optsWithGlobals().
1151
+ */
1152
+ getOptionValueSourceWithGlobals<K extends keyof (Opts & GlobalOpts)>(
1153
+ key: K,
1154
+ ): OptionValueSource | undefined;
1155
+ getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined;
1156
+
1157
+ /**
1158
+ * Alter parsing of short flags with optional values.
1159
+ *
1160
+ * @example
1161
+ * ```
1162
+ * // for `.option('-f,--flag [value]'):
1163
+ * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
1164
+ * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
1165
+ * ```
1166
+ *
1167
+ * @returns `this` command for chaining
1168
+ */
1169
+ combineFlagAndOptionalValue(combine?: boolean): this;
1170
+
1171
+ /**
1172
+ * Allow unknown options on the command line.
1173
+ *
1174
+ * @returns `this` command for chaining
1175
+ */
1176
+ allowUnknownOption(allowUnknown?: boolean): this;
1177
+
1178
+ /**
1179
+ * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
1180
+ *
1181
+ * @returns `this` command for chaining
1182
+ */
1183
+ allowExcessArguments(allowExcess?: boolean): this;
1184
+
1185
+ /**
1186
+ * Enable positional options. Positional means global options are specified before subcommands which lets
1187
+ * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
1188
+ *
1189
+ * The default behaviour is non-positional and global options may appear anywhere on the command line.
1190
+ *
1191
+ * @returns `this` command for chaining
1192
+ */
1193
+ enablePositionalOptions(positional?: boolean): this;
1194
+
1195
+ /**
1196
+ * Pass through options that come after command-arguments rather than treat them as command-options,
1197
+ * so actual command-options come before command-arguments. Turning this on for a subcommand requires
1198
+ * positional options to have been enabled on the program (parent commands).
1199
+ *
1200
+ * The default behaviour is non-positional and options may appear before or after command-arguments.
1201
+ *
1202
+ * @returns `this` command for chaining
1203
+ */
1204
+ passThroughOptions(passThrough?: boolean): this;
1205
+
1206
+ /**
1207
+ * Parse `argv`, setting options and invoking commands when defined.
1208
+ *
1209
+ * The default expectation is that the arguments are from node and have the application as argv[0]
1210
+ * and the script being run in argv[1], with user parameters after that.
1211
+ *
1212
+ * @example
1213
+ * ```
1214
+ * program.parse(process.argv);
1215
+ * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
1216
+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
1217
+ * ```
1218
+ *
1219
+ * @returns `this` command for chaining
1220
+ */
1221
+ parse(argv?: readonly string[], options?: ParseOptions): this;
1222
+
1223
+ /**
1224
+ * Parse `argv`, setting options and invoking commands when defined.
1225
+ *
1226
+ * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
1227
+ *
1228
+ * The default expectation is that the arguments are from node and have the application as argv[0]
1229
+ * and the script being run in argv[1], with user parameters after that.
1230
+ *
1231
+ * @example
1232
+ * ```
1233
+ * program.parseAsync(process.argv);
1234
+ * program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
1235
+ * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
1236
+ * ```
1237
+ *
1238
+ * @returns Promise
1239
+ */
1240
+ parseAsync(argv?: readonly string[], options?: ParseOptions): Promise<this>;
1241
+
1242
+ /**
1243
+ * Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
1244
+ * Not usually called directly, but available for subclasses to save their custom state.
1245
+ *
1246
+ * This is called in a lazy way. Only commands used in parsing chain will have state saved.
1247
+ */
1248
+ saveStateBeforeParse(): void;
1249
+
1250
+ /**
1251
+ * Restore state before parse for calls after the first.
1252
+ * Not usually called directly, but available for subclasses to save their custom state.
1253
+ *
1254
+ * This is called in a lazy way. Only commands used in parsing chain will have state restored.
1255
+ */
1256
+ restoreStateBeforeParse(): void;
1257
+
1258
+ /**
1259
+ * Parse options from `argv` removing known options,
1260
+ * and return argv split into operands and unknown arguments.
1261
+ *
1262
+ * argv => operands, unknown
1263
+ * --known kkk op => [op], []
1264
+ * op --known kkk => [op], []
1265
+ * sub --unknown uuu op => [sub], [--unknown uuu op]
1266
+ * sub -- --unknown uuu op => [sub --unknown uuu op], []
1267
+ */
1268
+ parseOptions(argv: string[]): ParseOptionsResult;
1269
+
1270
+ /**
1271
+ * Return an object containing local option values as key-value pairs
1272
+ */
1273
+ opts(): Opts;
1274
+
1275
+ /**
1276
+ * Return an object containing merged local and global option values as key-value pairs.
1277
+ */
1278
+ optsWithGlobals(): Resolve<Opts & GlobalOpts>;
1279
+
1280
+ /**
1281
+ * Set the description.
1282
+ *
1283
+ * @returns `this` command for chaining
1284
+ */
1285
+
1286
+ description(str: string): this;
1287
+ /** @deprecated since v8, instead use .argument to add command argument with description */
1288
+ description(str: string, argsDescription: Record<string, string>): this;
1289
+ /**
1290
+ * Get the description.
1291
+ */
1292
+ description(): string;
1293
+
1294
+ /**
1295
+ * Set the summary. Used when listed as subcommand of parent.
1296
+ *
1297
+ * @returns `this` command for chaining
1298
+ */
1299
+
1300
+ summary(str: string): this;
1301
+ /**
1302
+ * Get the summary.
1303
+ */
1304
+ summary(): string;
1305
+
1306
+ /**
1307
+ * Set an alias for the command.
1308
+ *
1309
+ * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
1310
+ *
1311
+ * @returns `this` command for chaining
1312
+ */
1313
+ alias(alias: string): this;
1314
+ /**
1315
+ * Get alias for the command.
1316
+ */
1317
+ alias(): string;
1318
+
1319
+ /**
1320
+ * Set aliases for the command.
1321
+ *
1322
+ * Only the first alias is shown in the auto-generated help.
1323
+ *
1324
+ * @returns `this` command for chaining
1325
+ */
1326
+ aliases(aliases: readonly string[]): this;
1327
+ /**
1328
+ * Get aliases for the command.
1329
+ */
1330
+ aliases(): string[];
1331
+
1332
+ /**
1333
+ * Set the command usage.
1334
+ *
1335
+ * @returns `this` command for chaining
1336
+ */
1337
+ usage(str: string): this;
1338
+ /**
1339
+ * Get the command usage.
1340
+ */
1341
+ usage(): string;
1342
+
1343
+ /**
1344
+ * Set the name of the command.
1345
+ *
1346
+ * @returns `this` command for chaining
1347
+ */
1348
+ name(str: string): this;
1349
+ /**
1350
+ * Get the name of the command.
1351
+ */
1352
+ name(): string;
1353
+
1354
+ /**
1355
+ * Set the name of the command from script filename, such as process.argv[1],
1356
+ * or require.main.filename, or __filename.
1357
+ *
1358
+ * (Used internally and public although not documented in README.)
1359
+ *
1360
+ * @example
1361
+ * ```ts
1362
+ * program.nameFromFilename(require.main.filename);
1363
+ * ```
1364
+ *
1365
+ * @returns `this` command for chaining
1366
+ */
1367
+ nameFromFilename(filename: string): this;
1368
+
1369
+ /**
1370
+ * Set the directory for searching for executable subcommands of this command.
1371
+ *
1372
+ * @example
1373
+ * ```ts
1374
+ * program.executableDir(__dirname);
1375
+ * // or
1376
+ * program.executableDir('subcommands');
1377
+ * ```
1378
+ *
1379
+ * @returns `this` command for chaining
1380
+ */
1381
+ executableDir(path: string): this;
1382
+ /**
1383
+ * Get the executable search directory.
1384
+ */
1385
+ executableDir(): string | null;
1386
+
1387
+ /**
1388
+ * Output help information for this command.
1389
+ *
1390
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
1391
+ *
1392
+ */
1393
+ outputHelp(context?: HelpContext): void;
1394
+ /** @deprecated since v7 */
1395
+ outputHelp(cb?: (str: string) => string): void;
1396
+
1397
+ /**
1398
+ * Return command help documentation.
1399
+ */
1400
+ helpInformation(context?: HelpContext): string;
1401
+
1402
+ /**
1403
+ * You can pass in flags and a description to override the help
1404
+ * flags and help description for your command. Pass in false
1405
+ * to disable the built-in help option.
1406
+ */
1407
+ helpOption(flags?: string | boolean, description?: string): this;
1408
+
1409
+ /**
1410
+ * Supply your own option to use for the built-in help option.
1411
+ * This is an alternative to using helpOption() to customise the flags and description etc.
1412
+ */
1413
+ addHelpOption(option: Option): this;
1414
+
1415
+ /**
1416
+ * Output help information and exit.
1417
+ *
1418
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
1419
+ */
1420
+ help(context?: HelpContext): never;
1421
+ /** @deprecated since v7 */
1422
+ help(cb?: (str: string) => string): never;
1423
+
1424
+ /**
1425
+ * Add additional text to be displayed with the built-in help.
1426
+ *
1427
+ * Position is 'before' or 'after' to affect just this command,
1428
+ * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
1429
+ */
1430
+ addHelpText(position: AddHelpTextPosition, text: string): this;
1431
+ addHelpText(
1432
+ position: AddHelpTextPosition,
1433
+ text: (context: AddHelpTextContext) => string,
1434
+ ): this;
1435
+
1436
+ /**
1437
+ * Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
1438
+ */
1439
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
1440
+ }
1441
+
1442
+ export interface CommandOptions {
1443
+ hidden?: boolean;
1444
+ isDefault?: boolean;
1445
+ /** @deprecated since v7, replaced by hidden */
1446
+ noHelp?: boolean;
1447
+ }
1448
+ export interface ExecutableCommandOptions extends CommandOptions {
1449
+ executableFile?: string;
1450
+ }
1451
+
1452
+ export interface ParseOptionsResult {
1453
+ operands: string[];
1454
+ unknown: string[];
1455
+ }
1456
+
1457
+ export function createCommand(name?: string): Command;
1458
+ export function createOption<Usage extends string>(
1459
+ flags: Usage,
1460
+ description?: string,
1461
+ ): Option<Usage>;
1462
+ export function createArgument<Usage extends string>(
1463
+ name: Usage,
1464
+ description?: string,
1465
+ ): Argument<Usage>;
1466
+
1467
+ export const program: Command;