@rzl-zone/build-tools 0.0.5
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/LICENSE +21 -0
- package/dist/.references/index.d.cts +18 -0
- package/dist/.references/index.d.ts +18 -0
- package/dist/bundler/rolldown.cjs +32 -0
- package/dist/bundler/rolldown.cjs.map +1 -0
- package/dist/bundler/rolldown.d.cts +162 -0
- package/dist/bundler/rolldown.d.ts +162 -0
- package/dist/bundler/rolldown.js +25 -0
- package/dist/bundler/rolldown.js.map +1 -0
- package/dist/bundler/tsdown.cjs +132 -0
- package/dist/bundler/tsdown.cjs.map +1 -0
- package/dist/bundler/tsdown.d.cts +1165 -0
- package/dist/bundler/tsdown.d.ts +1165 -0
- package/dist/bundler/tsdown.js +124 -0
- package/dist/bundler/tsdown.js.map +1 -0
- package/dist/bundler/utils.cjs +24 -0
- package/dist/bundler/utils.cjs.map +1 -0
- package/dist/bundler/utils.d.cts +40 -0
- package/dist/bundler/utils.d.ts +40 -0
- package/dist/bundler/utils.js +21 -0
- package/dist/bundler/utils.js.map +1 -0
- package/dist/client-XhkdKJ4d.js +160 -0
- package/dist/client-XhkdKJ4d.js.map +1 -0
- package/dist/client-u8yLSxEI.cjs +221 -0
- package/dist/client-u8yLSxEI.cjs.map +1 -0
- package/dist/commander-kit/index.cjs +569 -0
- package/dist/commander-kit/index.cjs.map +1 -0
- package/dist/commander-kit/index.d.cts +1383 -0
- package/dist/commander-kit/index.d.ts +1383 -0
- package/dist/commander-kit/index.js +550 -0
- package/dist/commander-kit/index.js.map +1 -0
- package/dist/extra-CVuXMpEw.d.ts +994 -0
- package/dist/extra-CxDwtQEy.d.cts +994 -0
- package/dist/fast-globe-options-6r2aj6UC.d.ts +126 -0
- package/dist/fast-globe-options-BFt__e__.d.cts +126 -0
- package/dist/helper-BdjaR8Yv.js +215 -0
- package/dist/helper-BdjaR8Yv.js.map +1 -0
- package/dist/helper-DorgNsB9.cjs +377 -0
- package/dist/helper-DorgNsB9.cjs.map +1 -0
- package/dist/identity-BJ0QX7AJ.js +88 -0
- package/dist/identity-BJ0QX7AJ.js.map +1 -0
- package/dist/identity-CxR9DRMh.cjs +100 -0
- package/dist/identity-CxR9DRMh.cjs.map +1 -0
- package/dist/index-B-NeF7PU.d.cts +670 -0
- package/dist/index-CzxZta4Z.d.ts +356 -0
- package/dist/index-Idak1iwg.d.cts +356 -0
- package/dist/index-PXsb85LI.d.ts +670 -0
- package/dist/index.cjs +1689 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2193 -0
- package/dist/index.d.ts +2193 -0
- package/dist/index.js +1641 -0
- package/dist/index.js.map +1 -0
- package/dist/package-banner-6RzEf-mV.cjs +54 -0
- package/dist/package-banner-6RzEf-mV.cjs.map +1 -0
- package/dist/package-banner-BzheZbxy.js +41 -0
- package/dist/package-banner-BzheZbxy.js.map +1 -0
- package/dist/server-B2hBoGDR.cjs +181 -0
- package/dist/server-B2hBoGDR.cjs.map +1 -0
- package/dist/server-CWrDd29Y.js +142 -0
- package/dist/server-CWrDd29Y.js.map +1 -0
- package/dist/utils/client.cjs +23 -0
- package/dist/utils/client.d.cts +887 -0
- package/dist/utils/client.d.ts +887 -0
- package/dist/utils/client.js +12 -0
- package/dist/utils/server.cjs +17 -0
- package/dist/utils/server.d.cts +124 -0
- package/dist/utils/server.d.ts +124 -0
- package/dist/utils/server.js +12 -0
- package/package.json +151 -0
|
@@ -0,0 +1,1383 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/build-tools
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `0.0.5`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky1998@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/build-tools`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { t as AnyString } from "../extra-CxDwtQEy.cjs";
|
|
12
|
+
import { t as CommandIdentity } from "../index-Idak1iwg.cjs";
|
|
13
|
+
import { AddHelpTextContext, AddHelpTextPosition, Argument, Command, CommandOptions, CommanderError, ErrorOptions, ExecutableCommandOptions, Help, HelpConfiguration, HelpContext, HookEvent, InvalidArgumentError, InvalidOptionArgumentError, Option, OptionValueSource, OptionValues, OutputConfiguration, ParseOptions, ParseOptionsResult } from "commander";
|
|
14
|
+
|
|
15
|
+
/** ----------------------------------------------------------------
|
|
16
|
+
* * ***CLI command definition class.***
|
|
17
|
+
* ----------------------------------------------------------------
|
|
18
|
+
*
|
|
19
|
+
* Primary building block used to define CLI programs and
|
|
20
|
+
* subcommands.
|
|
21
|
+
*
|
|
22
|
+
* This class extends Commander’s {@link Command | **`Command`**} class and
|
|
23
|
+
* adds additional behavior and type safety used by
|
|
24
|
+
* this library.
|
|
25
|
+
*
|
|
26
|
+
* Importing this class from this module ensures that
|
|
27
|
+
* the additional type definitions and helpers provided
|
|
28
|
+
* by this library are available.
|
|
29
|
+
*
|
|
30
|
+
* ----------------------------------------------------------------
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { CliCommand } from "@rzl-zone/build-tools/commander-kit";
|
|
35
|
+
*
|
|
36
|
+
* const program = new CliCommand();
|
|
37
|
+
*
|
|
38
|
+
* program
|
|
39
|
+
* .name("my-cli")
|
|
40
|
+
* .description("Example CLI program");
|
|
41
|
+
*
|
|
42
|
+
* program.parse();
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare class CliCommand extends Command {
|
|
46
|
+
/** ----------------------------------------------------------------
|
|
47
|
+
* * ***Create a new CLI command instance.***
|
|
48
|
+
* ----------------------------------------------------------------
|
|
49
|
+
*
|
|
50
|
+
* @param name Optional command name.
|
|
51
|
+
*
|
|
52
|
+
* If the provided value is not a non-empty string,
|
|
53
|
+
* the command will be created without an explicit name.
|
|
54
|
+
*/
|
|
55
|
+
constructor(name?: string);
|
|
56
|
+
/** Set or disable the command usage string.
|
|
57
|
+
*
|
|
58
|
+
* This overrides the default usage generated from the command
|
|
59
|
+
* metadata (such as the command name, arguments, and options).
|
|
60
|
+
*
|
|
61
|
+
* - Passing a **non-empty string** sets a custom usage value.
|
|
62
|
+
* - Passing **`false`** disables usage output entirely for this
|
|
63
|
+
* command (including help and error rendering when supported
|
|
64
|
+
* by the CLI framework integration).
|
|
65
|
+
*
|
|
66
|
+
* An **empty string is not allowed** and will cause a configuration
|
|
67
|
+
* error to be thrown.
|
|
68
|
+
*
|
|
69
|
+
* @param str A non-empty custom usage string, or `false`
|
|
70
|
+
* to disable usage output.
|
|
71
|
+
*
|
|
72
|
+
* @returns The current command instance for chaining.
|
|
73
|
+
*
|
|
74
|
+
* @throws Thrown if the provided usage value is an empty string or
|
|
75
|
+
* not a valid non-empty string.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* program.usage("build [options]");
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* program.usage(false);
|
|
82
|
+
*/
|
|
83
|
+
override usage(str: string | false): this;
|
|
84
|
+
/** Get the resolved command usage string.
|
|
85
|
+
*
|
|
86
|
+
* If a custom usage was previously set using {@link Command.usage | `usage`},
|
|
87
|
+
* that value will be returned. Otherwise the usage string
|
|
88
|
+
* generated by Commander will be returned.
|
|
89
|
+
*
|
|
90
|
+
* @returns The current usage string for this command.
|
|
91
|
+
*/
|
|
92
|
+
override usage(): string;
|
|
93
|
+
/** Set or disable the program version.
|
|
94
|
+
*
|
|
95
|
+
* This method configures the version value for the CLI program and
|
|
96
|
+
* automatically registers the `"-v, --version"` flag which prints
|
|
97
|
+
* the version when invoked.
|
|
98
|
+
*
|
|
99
|
+
* Behavior depends on the value passed:
|
|
100
|
+
*
|
|
101
|
+
* - Passing a **non-empty string** sets the program version.
|
|
102
|
+
* - Passing **`false`** disables the version flag entirely.
|
|
103
|
+
*
|
|
104
|
+
* When providing custom `flags` or `description`, they must also be
|
|
105
|
+
* **non-empty strings**.
|
|
106
|
+
*
|
|
107
|
+
* An **empty string is not allowed** and will cause a configuration
|
|
108
|
+
* error to be thrown.
|
|
109
|
+
*
|
|
110
|
+
* @param str A non-empty version string, or `false` to disable
|
|
111
|
+
* the version flag.
|
|
112
|
+
*
|
|
113
|
+
* @param flags Optional custom version flags (e.g. `"-V, --version"`).
|
|
114
|
+
*
|
|
115
|
+
* @param description Optional description for the version flag.
|
|
116
|
+
*
|
|
117
|
+
* @returns The current program instance for chaining.
|
|
118
|
+
*
|
|
119
|
+
* @throws Thrown if `str`, `flags`, or `description` are provided
|
|
120
|
+
* as empty strings or invalid values.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* program.version("1.0.0");
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* program.version("1.0.0", "-V, --version", "print version");
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* program.version(false);
|
|
130
|
+
*/
|
|
131
|
+
override version(str: string, flags?: string, description?: string): this;
|
|
132
|
+
/** Set or disable the program version.
|
|
133
|
+
*
|
|
134
|
+
* This method configures the version value for the CLI program and
|
|
135
|
+
* automatically registers the `"-v, --version"` flag which prints
|
|
136
|
+
* the version when invoked.
|
|
137
|
+
*
|
|
138
|
+
* Behavior depends on the value passed:
|
|
139
|
+
*
|
|
140
|
+
* - Passing a **non-empty string** sets the program version.
|
|
141
|
+
* - Passing **`false`** disables the version flag entirely.
|
|
142
|
+
*
|
|
143
|
+
* When providing custom `flags` or `description`, they must also be
|
|
144
|
+
* **non-empty strings**.
|
|
145
|
+
*
|
|
146
|
+
* An **empty string is not allowed** and will cause a configuration
|
|
147
|
+
* error to be thrown.
|
|
148
|
+
*
|
|
149
|
+
* @param str A non-empty version string, or `false` to disable
|
|
150
|
+
* the version flag.
|
|
151
|
+
*
|
|
152
|
+
* @param flags Optional custom version flags (e.g. `"-V, --version"`).
|
|
153
|
+
*
|
|
154
|
+
* @param description Optional description for the version flag.
|
|
155
|
+
*
|
|
156
|
+
* @returns The current program instance for chaining.
|
|
157
|
+
*
|
|
158
|
+
* @throws Thrown if `str`, `flags`, or `description` are provided
|
|
159
|
+
* as empty strings or invalid values.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* program.version("1.0.0");
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* program.version("1.0.0", "-V, --version", "print version");
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* program.version(false);
|
|
169
|
+
*/
|
|
170
|
+
override version(str: false): this;
|
|
171
|
+
/** Set or disable the program version.
|
|
172
|
+
*
|
|
173
|
+
* This method configures the version value for the CLI program and
|
|
174
|
+
* automatically registers the `"-v, --version"` flag which prints
|
|
175
|
+
* the version when invoked.
|
|
176
|
+
*
|
|
177
|
+
* Behavior depends on the value passed:
|
|
178
|
+
*
|
|
179
|
+
* - Passing a **non-empty string** sets the program version.
|
|
180
|
+
* - Passing **`false`** disables the version flag entirely.
|
|
181
|
+
*
|
|
182
|
+
* When providing custom `flags` or `description`, they must also be
|
|
183
|
+
* **non-empty strings**.
|
|
184
|
+
*
|
|
185
|
+
* An **empty string is not allowed** and will cause a configuration
|
|
186
|
+
* error to be thrown.
|
|
187
|
+
*
|
|
188
|
+
* @param str A non-empty version string, or `false` to disable
|
|
189
|
+
* the version flag.
|
|
190
|
+
*
|
|
191
|
+
* @param flags Optional custom version flags (e.g. `"-V, --version"`).
|
|
192
|
+
*
|
|
193
|
+
* @param description Optional description for the version flag.
|
|
194
|
+
*
|
|
195
|
+
* @returns The current program instance for chaining.
|
|
196
|
+
*
|
|
197
|
+
* @throws Thrown if `str`, `flags`, or `description` are provided
|
|
198
|
+
* as empty strings or invalid values.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* program.version("1.0.0");
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* program.version("1.0.0", "-V, --version", "print version");
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* program.version(false);
|
|
208
|
+
*/
|
|
209
|
+
override version(str: false, flags?: never): this;
|
|
210
|
+
/** Set or disable the program version.
|
|
211
|
+
*
|
|
212
|
+
* This method configures the version value for the CLI program and
|
|
213
|
+
* automatically registers the `"-v, --version"` flag which prints
|
|
214
|
+
* the version when invoked.
|
|
215
|
+
*
|
|
216
|
+
* Behavior depends on the value passed:
|
|
217
|
+
*
|
|
218
|
+
* - Passing a **non-empty string** sets the program version.
|
|
219
|
+
* - Passing **`false`** disables the version flag entirely.
|
|
220
|
+
*
|
|
221
|
+
* When providing custom `flags` or `description`, they must also be
|
|
222
|
+
* **non-empty strings**.
|
|
223
|
+
*
|
|
224
|
+
* An **empty string is not allowed** and will cause a configuration
|
|
225
|
+
* error to be thrown.
|
|
226
|
+
*
|
|
227
|
+
* @param str A non-empty version string, or `false` to disable
|
|
228
|
+
* the version flag.
|
|
229
|
+
*
|
|
230
|
+
* @param flags Optional custom version flags (e.g. `"-V, --version"`).
|
|
231
|
+
*
|
|
232
|
+
* @param description Optional description for the version flag.
|
|
233
|
+
*
|
|
234
|
+
* @returns The current program instance for chaining.
|
|
235
|
+
*
|
|
236
|
+
* @throws Thrown if `str`, `flags`, or `description` are provided
|
|
237
|
+
* as empty strings or invalid values.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* program.version("1.0.0");
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* program.version("1.0.0", "-V, --version", "print version");
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* program.version(false);
|
|
247
|
+
*/
|
|
248
|
+
override version(str: false, flags?: never, description?: never): this;
|
|
249
|
+
/** Get the program version.
|
|
250
|
+
*
|
|
251
|
+
* Returns the currently configured version string.
|
|
252
|
+
*
|
|
253
|
+
* If the version was disabled using {@link Command.version | `version(false)`},
|
|
254
|
+
* this method returns `undefined`.
|
|
255
|
+
*
|
|
256
|
+
* @returns The current program version string if set.
|
|
257
|
+
*/
|
|
258
|
+
override version(): string | undefined;
|
|
259
|
+
}
|
|
260
|
+
/** ----------------------------------------------------------------
|
|
261
|
+
* * ***Internal base program implementation.***
|
|
262
|
+
* ----------------------------------------------------------------
|
|
263
|
+
*
|
|
264
|
+
* Internal extension of {@link CliCommand | `CliCommand`}
|
|
265
|
+
* used by {@link createBaseProgram | `createBaseProgram()`}.
|
|
266
|
+
*
|
|
267
|
+
* This class stores additional internal state required
|
|
268
|
+
* for UI formatting, version injection, and command
|
|
269
|
+
* lifecycle behavior.
|
|
270
|
+
*/
|
|
271
|
+
declare class CommandBaseProgram extends CliCommand {
|
|
272
|
+
constructor(name?: string);
|
|
273
|
+
override createCommand(name?: string): CommandBaseProgram;
|
|
274
|
+
}
|
|
275
|
+
/** ----------------------------------------------------------------
|
|
276
|
+
* * ***Configuration options for `createBaseProgram()`.***
|
|
277
|
+
* ----------------------------------------------------------------
|
|
278
|
+
*
|
|
279
|
+
* Defines the bootstrap configuration used when creating
|
|
280
|
+
* a pre-configured Commander program instance.
|
|
281
|
+
*
|
|
282
|
+
* - ***This type supports:***
|
|
283
|
+
* - direct property overrides.
|
|
284
|
+
* - centralized configuration via
|
|
285
|
+
* {@link CommandIdentity | `CommandIdentity`}.
|
|
286
|
+
* - optional CLI UI customization.
|
|
287
|
+
*
|
|
288
|
+
* ----------------------------------------------------------------
|
|
289
|
+
* #### Resolution Priority.
|
|
290
|
+
* ----------------------------------------------------------------
|
|
291
|
+
*
|
|
292
|
+
* When both explicit fields and `commandIdentity` are provided,
|
|
293
|
+
* values are resolved in the following order:
|
|
294
|
+
*
|
|
295
|
+
* * `explicit option` ➔ {@link CreateBaseProgramOptions.commandIdentity |`commandIdentity`} ➔ `internal defaults`.
|
|
296
|
+
*
|
|
297
|
+
* This ensures predictable override behavior.
|
|
298
|
+
*
|
|
299
|
+
* ----------------------------------------------------------------
|
|
300
|
+
*/
|
|
301
|
+
type CreateBaseProgramOptions = {
|
|
302
|
+
/** ----------------------------------------------------------------
|
|
303
|
+
* * ***CLI program name.***
|
|
304
|
+
* ----------------------------------------------------------------
|
|
305
|
+
*
|
|
306
|
+
* Name assigned to the Commander instance.
|
|
307
|
+
*
|
|
308
|
+
* Overrides {@link CommandIdentity.commandName | `commandIdentity.commandName`} when provided.
|
|
309
|
+
*
|
|
310
|
+
* ----------------------------------------------------------------
|
|
311
|
+
*/
|
|
312
|
+
cliName?: string;
|
|
313
|
+
/** ----------------------------------------------------------------
|
|
314
|
+
* * ***Package name.***
|
|
315
|
+
* ----------------------------------------------------------------
|
|
316
|
+
*
|
|
317
|
+
* Package name displayed in the version description.
|
|
318
|
+
*
|
|
319
|
+
* Overrides {@link CommandIdentity.packageName | `commandIdentity.packageName`} when provided.
|
|
320
|
+
*
|
|
321
|
+
* Defaults to the internally resolved package name
|
|
322
|
+
* when omitted.
|
|
323
|
+
*
|
|
324
|
+
* ----------------------------------------------------------------
|
|
325
|
+
*/
|
|
326
|
+
packageName?: string;
|
|
327
|
+
/** ----------------------------------------------------------------
|
|
328
|
+
* * ***Package version.***
|
|
329
|
+
* ----------------------------------------------------------------
|
|
330
|
+
*
|
|
331
|
+
* Version string passed to {@link CliCommand.version `.version()`}.
|
|
332
|
+
*
|
|
333
|
+
* Overrides {@link CommandIdentity.version | `commandIdentity.version`} when provided.
|
|
334
|
+
*
|
|
335
|
+
* Defaults to the internally resolved package version
|
|
336
|
+
* when omitted.
|
|
337
|
+
*
|
|
338
|
+
* ----------------------------------------------------------------
|
|
339
|
+
*/
|
|
340
|
+
packageVersion?: string;
|
|
341
|
+
/** ----------------------------------------------------------------
|
|
342
|
+
* * ***Commander UI configuration.***
|
|
343
|
+
* ----------------------------------------------------------------
|
|
344
|
+
*
|
|
345
|
+
* Inline UI configuration via `ui` option.
|
|
346
|
+
*
|
|
347
|
+
* UI initialization is resolved using the following priority:
|
|
348
|
+
*
|
|
349
|
+
* 1. When `ui.usage` is defined,
|
|
350
|
+
* full UI customization is triggered and strict validation is enforced.
|
|
351
|
+
*
|
|
352
|
+
* 2. Otherwise, if {@link CommandIdentity | `commandIdentity`} is provided,
|
|
353
|
+
* UI is initialized using the identity title.
|
|
354
|
+
*
|
|
355
|
+
* 3. Otherwise, if `ui.title` is defined and valid,
|
|
356
|
+
* UI is initialized using the provided title only.
|
|
357
|
+
*
|
|
358
|
+
* When full UI customization is triggered (case #1),
|
|
359
|
+
* the following validations are enforced:
|
|
360
|
+
*
|
|
361
|
+
* - The UI object must be non-null.
|
|
362
|
+
* - `title` must be a non-empty string when provided.
|
|
363
|
+
* - `usage` must be a non-empty string when provided.
|
|
364
|
+
*
|
|
365
|
+
* In partial initialization cases (#2 and #3),
|
|
366
|
+
* usage falls back to {@link CliCommand | `CliCommand`} default resolution.
|
|
367
|
+
*
|
|
368
|
+
* @note
|
|
369
|
+
* ⚠️ If validation fails, a structured configuration error may be thrown.
|
|
370
|
+
*
|
|
371
|
+
* ----------------------------------------------------------------
|
|
372
|
+
*/
|
|
373
|
+
ui?: CommanderUiOptions;
|
|
374
|
+
/** ----------------------------------------------------------------
|
|
375
|
+
* * ***Command identity source.***
|
|
376
|
+
* ----------------------------------------------------------------
|
|
377
|
+
*
|
|
378
|
+
* Optional {@link CommandIdentity | `CommandIdentity`} instance used as a centralized
|
|
379
|
+
* configuration source for:
|
|
380
|
+
*
|
|
381
|
+
* - Command name.
|
|
382
|
+
* - Package name.
|
|
383
|
+
* - Version metadata.
|
|
384
|
+
*
|
|
385
|
+
* When provided, this identity may also participate in UI initialization.
|
|
386
|
+
*
|
|
387
|
+
* If full UI configuration is not supplied via `ui`,
|
|
388
|
+
* the identity title may be used to bootstrap
|
|
389
|
+
* {@link applyCommanderUi | `applyCommanderUi()`}.
|
|
390
|
+
*
|
|
391
|
+
* This reduces the need for manual property mapping
|
|
392
|
+
* and provides a consistent identity-driven configuration pattern.
|
|
393
|
+
*
|
|
394
|
+
* @throws {TypeError}
|
|
395
|
+
* Thrown if the provided value is not an instance of
|
|
396
|
+
* {@link CommandIdentity | `CommandIdentity`}.
|
|
397
|
+
*
|
|
398
|
+
* ----------------------------------------------------------------
|
|
399
|
+
*/
|
|
400
|
+
commandIdentity?: CommandIdentity;
|
|
401
|
+
};
|
|
402
|
+
/** ----------------------------------------------------------------
|
|
403
|
+
* * ***Creates a pre-configured Commander.js program instance.***
|
|
404
|
+
* ----------------------------------------------------------------
|
|
405
|
+
*
|
|
406
|
+
* Factory function that returns a fresh {@link CliCommand | `CliCommand`} instance
|
|
407
|
+
* with shared base configuration applied.
|
|
408
|
+
*
|
|
409
|
+
* - *This helper centralizes common CLI setup to ensure:*
|
|
410
|
+
* - Consistent version formatting.
|
|
411
|
+
* - Standardized exit behavior.
|
|
412
|
+
* - No shared mutable state between entry points.
|
|
413
|
+
*
|
|
414
|
+
* The returned {@link CliCommand | `CliCommand`} instance is stateful and fully mutable.
|
|
415
|
+
*
|
|
416
|
+
* *Additional configuration (including UI customization) may be applied after creation.*
|
|
417
|
+
*
|
|
418
|
+
* ----------------------------------------------------------------
|
|
419
|
+
* #### Configuration Resolution.
|
|
420
|
+
* ----------------------------------------------------------------
|
|
421
|
+
*
|
|
422
|
+
* When both explicit options and {@link CommandIdentity | `CommandIdentity`} are provided,
|
|
423
|
+
* values are resolved using the following priority:
|
|
424
|
+
*
|
|
425
|
+
* * `explicit option` ➔ `commandIdentity` ➔ `internal defaults`.
|
|
426
|
+
*
|
|
427
|
+
* This allows granular overrides while still supporting
|
|
428
|
+
* {@link CommandIdentity | `CommandIdentity`} as a single source of truth.
|
|
429
|
+
*
|
|
430
|
+
* ----------------------------------------------------------------
|
|
431
|
+
* #### UI Configuration.
|
|
432
|
+
* ----------------------------------------------------------------
|
|
433
|
+
*
|
|
434
|
+
* UI customization can be applied using two approaches:
|
|
435
|
+
*
|
|
436
|
+
* 1. Inline via the `ui` option.
|
|
437
|
+
* - During initialization, {@link applyCommanderUi | `applyCommanderUi()`}
|
|
438
|
+
* may be invoked automatically using the following priority:
|
|
439
|
+
* - Full UI override when `options.ui.usage` is defined.
|
|
440
|
+
* - Fallback to {@link CommandIdentity | `commandIdentity`} when provided.
|
|
441
|
+
* - Fallback to `options.ui.title` when provided or valid.
|
|
442
|
+
*
|
|
443
|
+
* - In partial initialization cases, usage falls back to
|
|
444
|
+
* {@link CliCommand | `CliCommand`} default resolution.
|
|
445
|
+
*
|
|
446
|
+
* 2. Manually after creation.
|
|
447
|
+
* - You may call {@link applyCommanderUi | `applyCommanderUi()`}
|
|
448
|
+
* explicitly to override or apply custom UI behavior.
|
|
449
|
+
*
|
|
450
|
+
* - Calling {@link applyCommanderUi | `applyCommanderUi()`} manually after initialization will
|
|
451
|
+
* override any previously applied UI configuration.
|
|
452
|
+
*
|
|
453
|
+
* ----------------------------------------------------------------
|
|
454
|
+
*
|
|
455
|
+
* @param options Optional bootstrap configuration.
|
|
456
|
+
*
|
|
457
|
+
* @returns A configured {@link CliCommand | `CliCommand`} instance with version,
|
|
458
|
+
* exit override, and optional UI behavior applied.
|
|
459
|
+
*
|
|
460
|
+
* ----------------------------------------------------------------
|
|
461
|
+
* @example
|
|
462
|
+
*
|
|
463
|
+
* **Using commandIdentity as primary source ***(recommended)***:**
|
|
464
|
+
*
|
|
465
|
+
* ```ts
|
|
466
|
+
* import { joinInline, picocolors } from "@rzl-zone/build-tools/utils";
|
|
467
|
+
* import { createBaseProgram, CommandIdentity } from "@rzl-zone/build-tools/utils/server";
|
|
468
|
+
*
|
|
469
|
+
* const identity = new CommandIdentity({
|
|
470
|
+
* defaultCommandName: "my-command-cli"
|
|
471
|
+
* })
|
|
472
|
+
* // override to your-package-name, e.g:
|
|
473
|
+
* .setPackageName("your-package-name")
|
|
474
|
+
* // override to your-package-version, e.g:
|
|
475
|
+
* .setVersion("1.1.1");
|
|
476
|
+
*
|
|
477
|
+
* const program = createBaseProgram({
|
|
478
|
+
* commandIdentity: identity,
|
|
479
|
+
* ui: {
|
|
480
|
+
* title: identity.cli(),
|
|
481
|
+
* usage: joinInline(
|
|
482
|
+
* picocolors.cyan(identity.commandName),
|
|
483
|
+
* picocolors.gray("<glob...>"),
|
|
484
|
+
* picocolors.blueBright("[options]")
|
|
485
|
+
* )
|
|
486
|
+
* }
|
|
487
|
+
* });
|
|
488
|
+
*
|
|
489
|
+
* program.parse();
|
|
490
|
+
* ```
|
|
491
|
+
* ----------------------------------------------------------------
|
|
492
|
+
* @example
|
|
493
|
+
*
|
|
494
|
+
* **Automatic UI configuration ***(manual mapping)***:**
|
|
495
|
+
*
|
|
496
|
+
* ```ts
|
|
497
|
+
* import { joinInline, picocolors } from "@rzl-zone/build-tools/utils";
|
|
498
|
+
* import { createBaseProgram, CommandIdentity } from "@rzl-zone/build-tools/utils/server";
|
|
499
|
+
*
|
|
500
|
+
* const commandTitle = new CommandIdentity({
|
|
501
|
+
* defaultCommandName: "clean-js-build-artifacts"
|
|
502
|
+
* })
|
|
503
|
+
* // override to your-package-name, e.g:
|
|
504
|
+
* .setPackageName("your-package-name")
|
|
505
|
+
* // override to your-package-version, e.g:
|
|
506
|
+
* .setVersion("1.1.1");
|
|
507
|
+
*
|
|
508
|
+
* const program = createBaseProgram({
|
|
509
|
+
* cliName: commandTitle.commandName,
|
|
510
|
+
* packageName: commandTitle.packageName,
|
|
511
|
+
* packageVersion: commandTitle.version,
|
|
512
|
+
* ui: {
|
|
513
|
+
* title: commandTitle.cli(),
|
|
514
|
+
* usage: joinInline(
|
|
515
|
+
* picocolors.cyan(commandTitle.commandName),
|
|
516
|
+
* picocolors.gray("<glob...>"),
|
|
517
|
+
* picocolors.blueBright("[options]")
|
|
518
|
+
* )
|
|
519
|
+
* }
|
|
520
|
+
* });
|
|
521
|
+
*
|
|
522
|
+
* program.parse();
|
|
523
|
+
* ```
|
|
524
|
+
* ----------------------------------------------------------------
|
|
525
|
+
* @example
|
|
526
|
+
*
|
|
527
|
+
* **Manual UI override after creation:**
|
|
528
|
+
*
|
|
529
|
+
* ```ts
|
|
530
|
+
* import { joinInline, picocolors } from "@rzl-zone/build-tools/utils";
|
|
531
|
+
* import { createBaseProgram, CommandIdentity } from "@rzl-zone/build-tools/utils/server";
|
|
532
|
+
*
|
|
533
|
+
* const identity = new CommandIdentity({
|
|
534
|
+
* defaultCommandName: "my-command-cli"
|
|
535
|
+
* });
|
|
536
|
+
*
|
|
537
|
+
* const baseProgram = createBaseProgram({
|
|
538
|
+
* commandIdentity: identity
|
|
539
|
+
* });
|
|
540
|
+
*
|
|
541
|
+
* const program = applyCommanderUi(baseProgram, {
|
|
542
|
+
* title: identity.cli(),
|
|
543
|
+
* usage: joinInline(
|
|
544
|
+
* picocolors.cyan(identity.commandName),
|
|
545
|
+
* picocolors.gray("<glob...>"),
|
|
546
|
+
* picocolors.blueBright("[options]")
|
|
547
|
+
* )
|
|
548
|
+
* });
|
|
549
|
+
*
|
|
550
|
+
* program.parse();
|
|
551
|
+
* ```
|
|
552
|
+
* ----------------------------------------------------------------
|
|
553
|
+
*/
|
|
554
|
+
declare function createBaseProgram(options?: CreateBaseProgramOptions): CommandBaseProgram;
|
|
555
|
+
/** ----------------------------------------------------------------
|
|
556
|
+
* * ***Commander UI options.***
|
|
557
|
+
* ----------------------------------------------------------------
|
|
558
|
+
*
|
|
559
|
+
* Configuration object consumed by {@link applyCommanderUi | `applyCommanderUi()`}.
|
|
560
|
+
*
|
|
561
|
+
* Both `title`, `usage`, `packageName`, and `version` are optional at the type level, but
|
|
562
|
+
* at runtime, values must be non-empty strings to be considered valid if provided.
|
|
563
|
+
*
|
|
564
|
+
* If either field is missing or fails the non-empty string constraint,
|
|
565
|
+
* UI customization will be ignored silently and default.
|
|
566
|
+
*
|
|
567
|
+
* No runtime error is thrown for invalid values to preserve CLI execution flow.
|
|
568
|
+
*/
|
|
569
|
+
type CommanderUiOptions = {
|
|
570
|
+
/** ----------------------------------------------------------------
|
|
571
|
+
* * ***UI title.***
|
|
572
|
+
* ----------------------------------------------------------------
|
|
573
|
+
*
|
|
574
|
+
* Title displayed in the CLI header output.
|
|
575
|
+
*
|
|
576
|
+
* Must be a non-empty string when provided, otherwise will return default.
|
|
577
|
+
*
|
|
578
|
+
* ----------------------------------------------------------------
|
|
579
|
+
*/
|
|
580
|
+
title?: string;
|
|
581
|
+
/** ----------------------------------------------------------------
|
|
582
|
+
* * ***Usage description.***
|
|
583
|
+
* ----------------------------------------------------------------
|
|
584
|
+
*
|
|
585
|
+
* Usage information displayed in the help output, this optional, but when
|
|
586
|
+
* provided, the value must be a non-empty string.
|
|
587
|
+
*
|
|
588
|
+
* - *If omitted or invalid, the usage string is resolved using the following priority:*
|
|
589
|
+
* 1. A manually defined {@link CliCommand.usage | `.usage()`} override (if any),
|
|
590
|
+
* 2. Commander’s default usage resolution behavior.
|
|
591
|
+
* ----------------------------------------------------------------
|
|
592
|
+
* @note
|
|
593
|
+
* Calling {@link CliCommand.usage | `.usage("")`} or with empty-string, is treated as an invalid
|
|
594
|
+
* override and will throw a configuration error.
|
|
595
|
+
*/
|
|
596
|
+
usage?: string;
|
|
597
|
+
/** ----------------------------------------------------------------
|
|
598
|
+
* * ***Package version.***
|
|
599
|
+
* ----------------------------------------------------------------
|
|
600
|
+
*
|
|
601
|
+
* Usage information displayed in the version package output, this
|
|
602
|
+
* property is optional, but when provided, the value must be a
|
|
603
|
+
* non-empty string.
|
|
604
|
+
*
|
|
605
|
+
* - *If omitted or invalid, the version string is resolved using the
|
|
606
|
+
* following priority:*
|
|
607
|
+
* 1. A manually defined {@link CliCommand.version | `.version()`} override (if any).
|
|
608
|
+
* 2. Defaults to the internally resolved package version.
|
|
609
|
+
*
|
|
610
|
+
* ----------------------------------------------------------------
|
|
611
|
+
* #### ⚠️ Behavior Scope.
|
|
612
|
+
* ----------------------------------------------------------------
|
|
613
|
+
*
|
|
614
|
+
* This property is **ONLY RESPECTED** when using a native Commander
|
|
615
|
+
* instance (i.e., created directly via `new Command()` or an imported `program` singleton).
|
|
616
|
+
*
|
|
617
|
+
* If the program instance is created via `createBaseProgram()`,
|
|
618
|
+
* this property is intentionally ignored, since version resolution
|
|
619
|
+
* is fully managed by the base program factory lifecycle.
|
|
620
|
+
*
|
|
621
|
+
* ----------------------------------------------------------------
|
|
622
|
+
* @note
|
|
623
|
+
* Calling {@link CliCommand.version | `.version("")`} or providing an
|
|
624
|
+
* empty string is treated as an invalid override and will throw a
|
|
625
|
+
* configuration error.
|
|
626
|
+
*/
|
|
627
|
+
version?: string;
|
|
628
|
+
/** ----------------------------------------------------------------
|
|
629
|
+
* * ***Package name.***
|
|
630
|
+
* ----------------------------------------------------------------
|
|
631
|
+
*
|
|
632
|
+
* Package name displayed as part of the CLI version output, when version
|
|
633
|
+
* information is printed, this value is rendered alongside the version string.
|
|
634
|
+
*
|
|
635
|
+
* This property is optional, but when provided,
|
|
636
|
+
* the value must be a non-empty string.
|
|
637
|
+
*
|
|
638
|
+
* *If omitted or invalid, the package name string is resolved using the
|
|
639
|
+
* defaults internally resolved package name.*
|
|
640
|
+
*
|
|
641
|
+
* ----------------------------------------------------------------
|
|
642
|
+
* #### ⚠️ Behavior Scope.
|
|
643
|
+
* ----------------------------------------------------------------
|
|
644
|
+
*
|
|
645
|
+
* This property is **ONLY RESPECTED** when using a native Commander
|
|
646
|
+
* instance (i.e., created directly via `new Command()` or an imported `program` singleton).
|
|
647
|
+
*
|
|
648
|
+
* If the program instance is created via `createBaseProgram()`,
|
|
649
|
+
* this property is intentionally ignored, since `packageName` resolution
|
|
650
|
+
* is fully managed by the base program factory lifecycle.
|
|
651
|
+
*/
|
|
652
|
+
packageName?: string;
|
|
653
|
+
};
|
|
654
|
+
/** ----------------------------------------------------------------
|
|
655
|
+
* * ***Commander Error Code.***
|
|
656
|
+
* ----------------------------------------------------------------
|
|
657
|
+
*
|
|
658
|
+
* Union type representing known error codes emitted by
|
|
659
|
+
* {@link CommanderError | `CommanderError`} instances.
|
|
660
|
+
*
|
|
661
|
+
* The union includes all standard error identifiers produced by
|
|
662
|
+
* Commander during command parsing, validation, and execution.
|
|
663
|
+
*
|
|
664
|
+
* The type also allows additional string values through
|
|
665
|
+
* {@link AnyString | `AnyString`} to support custom error codes
|
|
666
|
+
* defined by integrations, plugins, or higher-level frameworks.
|
|
667
|
+
*
|
|
668
|
+
* ----------------------------------------------------------------
|
|
669
|
+
* #### Purpose
|
|
670
|
+
* ----------------------------------------------------------------
|
|
671
|
+
*
|
|
672
|
+
* - Provides autocomplete for built-in Commander error codes.
|
|
673
|
+
* - Enables safer error handling logic.
|
|
674
|
+
* - Allows custom framework-specific error codes without
|
|
675
|
+
* restricting the type to a closed union.
|
|
676
|
+
*
|
|
677
|
+
* ----------------------------------------------------------------
|
|
678
|
+
*/
|
|
679
|
+
type CommanderErrorCode = "commander.help" | "commander.helpDisplayed" | "commander.version" | "commander.executeSubCommandAsync" | "commander.invalidArgument" | "commander.error" | "commander.missingArgument" | "commander.optionMissingArgument" | "commander.missingMandatoryOptionValue" | "commander.conflictingOption" | "commander.unknownOption" | "commander.excessArguments" | "commander.unknownCommand" | AnyString;
|
|
680
|
+
/** ----------------------------------------------------------------
|
|
681
|
+
* * ***Typed Commander Error.***
|
|
682
|
+
* ----------------------------------------------------------------
|
|
683
|
+
*
|
|
684
|
+
* Strongly-typed variant of {@link CommanderError | `CommanderError`}
|
|
685
|
+
* with a refined `code` property.
|
|
686
|
+
*
|
|
687
|
+
* This type replaces the original `string`-based `code` field with
|
|
688
|
+
* {@link CommanderErrorCode | `CommanderErrorCode`}, providing
|
|
689
|
+
* improved type safety and autocomplete when working with
|
|
690
|
+
* Commander error handling logic.
|
|
691
|
+
*
|
|
692
|
+
* The error code union includes all known Commander error identifiers
|
|
693
|
+
* while still allowing additional custom string codes defined by
|
|
694
|
+
* integrations or higher-level frameworks.
|
|
695
|
+
*
|
|
696
|
+
* ----------------------------------------------------------------
|
|
697
|
+
* #### Purpose
|
|
698
|
+
* ----------------------------------------------------------------
|
|
699
|
+
*
|
|
700
|
+
* - Provides autocomplete for standard Commander error codes.
|
|
701
|
+
* - Improves type safety when inspecting `CommanderError` values.
|
|
702
|
+
* - Allows custom error codes without restricting extensibility.
|
|
703
|
+
*
|
|
704
|
+
* This type is typically used when intercepting, transforming,
|
|
705
|
+
* or re-throwing errors emitted by Commander.
|
|
706
|
+
*
|
|
707
|
+
* ----------------------------------------------------------------
|
|
708
|
+
*/
|
|
709
|
+
type TypedCommanderError = Omit<CommanderError, "code"> & {
|
|
710
|
+
/** Typed Commander error identifier. */code: CommanderErrorCode;
|
|
711
|
+
};
|
|
712
|
+
/** ----------------------------------------------------------------
|
|
713
|
+
* * ***Command Execution Context Type.***
|
|
714
|
+
* ----------------------------------------------------------------
|
|
715
|
+
*
|
|
716
|
+
* Alias type representing the runtime command instance used as
|
|
717
|
+
* the execution context during command handling.
|
|
718
|
+
*
|
|
719
|
+
* This abstraction standardizes command typing across the codebase
|
|
720
|
+
* while avoiding tight coupling to a specific Commander class.
|
|
721
|
+
*
|
|
722
|
+
* The type includes all supported command-like instances used by
|
|
723
|
+
* the framework:
|
|
724
|
+
*
|
|
725
|
+
* - {@link CliCommand | `CliCommand`}
|
|
726
|
+
* - {@link Command | `Command`}
|
|
727
|
+
* - {@link CommandBaseProgram | `CommandBaseProgram`}
|
|
728
|
+
*
|
|
729
|
+
* These values represent **instantiated command objects**
|
|
730
|
+
* (for example `new Command()`), not constructor types.
|
|
731
|
+
*
|
|
732
|
+
* ----------------------------------------------------------------
|
|
733
|
+
*
|
|
734
|
+
* #### Purpose
|
|
735
|
+
*
|
|
736
|
+
* - Provides a common command instance type for utilities.
|
|
737
|
+
* - Improves semantic clarity in function signatures.
|
|
738
|
+
* - Avoids repeating union types across the codebase.
|
|
739
|
+
*/
|
|
740
|
+
type CommandContext = CliCommand | Command | CommandBaseProgram;
|
|
741
|
+
/** ------------------------------------------------------------------------
|
|
742
|
+
* * Runtime type guard for {@link CommanderError | `CommanderError`}.
|
|
743
|
+
* ------------------------------------------------------------------------
|
|
744
|
+
*
|
|
745
|
+
* Determines whether a given unknown value is an instance of
|
|
746
|
+
* {@link CommanderError | `CommanderError`} and **narrows the `code` property** to the
|
|
747
|
+
* library-specific {@link CommanderErrorCode | `CommanderErrorCode`} union type.
|
|
748
|
+
*
|
|
749
|
+
* This helper exists because the upstream Commander type defines
|
|
750
|
+
* `CommanderError.code` as a plain `string`.
|
|
751
|
+
*
|
|
752
|
+
* As a result, TypeScript cannot automatically infer the narrowed error code type when using
|
|
753
|
+
* `instanceof CommanderError`.
|
|
754
|
+
*
|
|
755
|
+
* By using this guard, consumers can safely treat the error as a
|
|
756
|
+
* `CommanderError` with a strongly typed `code` value.
|
|
757
|
+
*
|
|
758
|
+
* ------------------------------------------------------------------------
|
|
759
|
+
* #### Behavior
|
|
760
|
+
* ------------------------------------------------------------------------
|
|
761
|
+
*
|
|
762
|
+
* - Returns **`true`** if `err` is an instance of {@link CommanderError | `CommanderError`}.
|
|
763
|
+
* - When `true`, the value is narrowed to:
|
|
764
|
+
* `CommanderError & { code: CommanderErrorCode }`
|
|
765
|
+
*
|
|
766
|
+
* - Returns **`false`** for all other values.
|
|
767
|
+
*
|
|
768
|
+
* This enables safe access to `err.code` with the expected
|
|
769
|
+
* {@link CommanderErrorCode | `CommanderErrorCode`} union type.
|
|
770
|
+
*
|
|
771
|
+
* ------------------------------------------------------------------------
|
|
772
|
+
* @param err - The value to test.
|
|
773
|
+
*
|
|
774
|
+
* @returns `true` if the value is a {@link CommanderError | `CommanderError`}; otherwise `false`.
|
|
775
|
+
*
|
|
776
|
+
* ------------------------------------------------------------------------
|
|
777
|
+
* @example
|
|
778
|
+
* ```ts
|
|
779
|
+
* try {
|
|
780
|
+
* program.parse();
|
|
781
|
+
* } catch (err) {
|
|
782
|
+
* if (isCommanderError(err)) {
|
|
783
|
+
* // err.code is now typed as CommanderErrorCode
|
|
784
|
+
* return err.code;
|
|
785
|
+
* }
|
|
786
|
+
*
|
|
787
|
+
* console.error(String(err));
|
|
788
|
+
* process.exit(1);
|
|
789
|
+
* }
|
|
790
|
+
* ```
|
|
791
|
+
*/
|
|
792
|
+
declare function isCommanderError(err: unknown): err is TypedCommanderError;
|
|
793
|
+
/** ------------------------------------------------------------------------
|
|
794
|
+
* * Formats a Commander error into a human-readable message.
|
|
795
|
+
* ------------------------------------------------------------------------
|
|
796
|
+
*
|
|
797
|
+
* Converts an unknown error value into a formatted CLI-friendly
|
|
798
|
+
* message string.
|
|
799
|
+
*
|
|
800
|
+
* If the value is a {@link CommanderError | `CommanderError`}, the message is extracted
|
|
801
|
+
* directly from the error instance. Otherwise, the value is converted
|
|
802
|
+
* to a string representation.
|
|
803
|
+
*
|
|
804
|
+
* This helper is typically used when rendering CLI error output before
|
|
805
|
+
* terminating the process.
|
|
806
|
+
*
|
|
807
|
+
* ------------------------------------------------------------------------
|
|
808
|
+
* #### Behavior
|
|
809
|
+
* ------------------------------------------------------------------------
|
|
810
|
+
*
|
|
811
|
+
* - If the value is a {@link CommanderError | `CommanderError`}, returns `err.message`.
|
|
812
|
+
* - Otherwise returns `String(err)`.
|
|
813
|
+
*
|
|
814
|
+
* ------------------------------------------------------------------------
|
|
815
|
+
* @param err - The error value to format.
|
|
816
|
+
*
|
|
817
|
+
* @returns A human-readable message string.
|
|
818
|
+
*
|
|
819
|
+
* ------------------------------------------------------------------------
|
|
820
|
+
* @example
|
|
821
|
+
* ```ts
|
|
822
|
+
* console.error(formatCommanderError(err));
|
|
823
|
+
* process.exit(1);
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
declare function formatCommanderError(err: unknown): string;
|
|
827
|
+
/** ------------------------------------------------------------------------
|
|
828
|
+
* * Extracts the Commander error code from an unknown value.
|
|
829
|
+
* ------------------------------------------------------------------------
|
|
830
|
+
*
|
|
831
|
+
* Safely resolves the {@link CommanderErrorCode | `CommanderErrorCode`} from a value that may
|
|
832
|
+
* or may not be a {@link CommanderError | `CommanderError`}.
|
|
833
|
+
*
|
|
834
|
+
* This helper is useful when handling errors originating from the
|
|
835
|
+
* Commander CLI runtime, where the error code indicates the type of
|
|
836
|
+
* internal CLI condition (for example help display or version output).
|
|
837
|
+
*
|
|
838
|
+
* If the provided value is not a {@link CommanderError | `CommanderError`}, `null`
|
|
839
|
+
* is returned.
|
|
840
|
+
*
|
|
841
|
+
* ------------------------------------------------------------------------
|
|
842
|
+
* #### Behavior
|
|
843
|
+
* ------------------------------------------------------------------------
|
|
844
|
+
*
|
|
845
|
+
* - Returns the narrowed {@link CommanderErrorCode | `CommanderErrorCode`} if the value is a
|
|
846
|
+
* {@link CommanderError | `CommanderError`}.
|
|
847
|
+
* - Returns `null` for all other values.
|
|
848
|
+
*
|
|
849
|
+
* ------------------------------------------------------------------------
|
|
850
|
+
* @param err - The value to inspect.
|
|
851
|
+
*
|
|
852
|
+
* @returns The resolved {@link CommanderErrorCode | `CommanderErrorCode`}, or `null`
|
|
853
|
+
* if the value is not a {@link CommanderError | `CommanderError`}.
|
|
854
|
+
*
|
|
855
|
+
* ------------------------------------------------------------------------
|
|
856
|
+
* @example
|
|
857
|
+
* ```ts
|
|
858
|
+
* const code = getCommanderErrorCode(err);
|
|
859
|
+
*
|
|
860
|
+
* if (code) {
|
|
861
|
+
* return code;
|
|
862
|
+
* }
|
|
863
|
+
* ```
|
|
864
|
+
*/
|
|
865
|
+
declare function getCommanderErrorCode(err: unknown): CommanderErrorCode | null;
|
|
866
|
+
/** ----------------------------------------------------------------
|
|
867
|
+
* * ***Centralized exit handler for Commander.js ({@link CliCommand.exitOverride | `exitOverride`}).***
|
|
868
|
+
* ----------------------------------------------------------------
|
|
869
|
+
*
|
|
870
|
+
* Handles all process termination logic when using Commander’s {@link CliCommand.exitOverride | `.exitOverride()`} method.
|
|
871
|
+
*
|
|
872
|
+
* This helper normalizes Commander’s exception-based control flow
|
|
873
|
+
* into predictable and user-friendly CLI behavior.
|
|
874
|
+
*
|
|
875
|
+
* ----------------------------------------------------------------
|
|
876
|
+
* - *Behavior:*
|
|
877
|
+
* - Exits the process with code `0` when:
|
|
878
|
+
* - Commander triggers `helpDisplayed`.
|
|
879
|
+
* - Commander triggers `version`.
|
|
880
|
+
* - Prints error messages for real CLI or runtime failures.
|
|
881
|
+
* - Ensures correct and consistent exit codes.
|
|
882
|
+
* ----------------------------------------------------------------
|
|
883
|
+
* - *This prevents:*
|
|
884
|
+
* - Duplicate output (e.g. version printed twice).
|
|
885
|
+
* - Treating help/version as fatal errors.
|
|
886
|
+
* - Copy-pasted exit logic across multiple CLI entry points.
|
|
887
|
+
* ----------------------------------------------------------------
|
|
888
|
+
* - ⚠️ **Important:**
|
|
889
|
+
* - This function **always terminates the process**.
|
|
890
|
+
* - Intended to be passed directly into `program.exitOverride`.
|
|
891
|
+
* - Should NOT be used outside a CLI execution context.
|
|
892
|
+
* ----------------------------------------------------------------
|
|
893
|
+
*
|
|
894
|
+
* @param err - The error object thrown by Commander or runtime logic.
|
|
895
|
+
*
|
|
896
|
+
* ----------------------------------------------------------------
|
|
897
|
+
* @example
|
|
898
|
+
* Using existing commander program instance:
|
|
899
|
+
* ```ts
|
|
900
|
+
* import { Command, program } from "commander"
|
|
901
|
+
*
|
|
902
|
+
* program.exitOverride(handleCommanderExit);
|
|
903
|
+
* program.parse(process.argv);
|
|
904
|
+
* ```
|
|
905
|
+
*
|
|
906
|
+
* @example
|
|
907
|
+
* Using manually created command instance:
|
|
908
|
+
* ```ts
|
|
909
|
+
* import { Command } from "commander"
|
|
910
|
+
*
|
|
911
|
+
* const cmd = new Command();
|
|
912
|
+
* cmd.exitOverride(handleCommanderExit);
|
|
913
|
+
* cmd.parse(process.argv);
|
|
914
|
+
* ```
|
|
915
|
+
* @example
|
|
916
|
+
* Using factory helper:
|
|
917
|
+
* ```ts
|
|
918
|
+
* import { createBaseProgram } from "@rzl-zone/build-tools/commander-kit";
|
|
919
|
+
*
|
|
920
|
+
* // Recommended usage (factory pattern)
|
|
921
|
+
* const program = createBaseProgram();
|
|
922
|
+
* program.parse(process.argv);
|
|
923
|
+
* ```
|
|
924
|
+
*/
|
|
925
|
+
declare function handleCommanderExit(err: unknown): never;
|
|
926
|
+
/** ------------------------------------------------------------------------
|
|
927
|
+
* * Applies a structured UI layer to a Commander.js program instance.
|
|
928
|
+
* ------------------------------------------------------------------------
|
|
929
|
+
*
|
|
930
|
+
* Enhances a Commander program by installing a standardized UI layer
|
|
931
|
+
* for error rendering and presentation formatting.
|
|
932
|
+
*
|
|
933
|
+
* This function is primarily intended for native
|
|
934
|
+
* {@link Command | `Command`} instances created directly
|
|
935
|
+
* from Commander (e.g. `new Command()` or an imported `program` singleton).
|
|
936
|
+
*
|
|
937
|
+
* Programs created via
|
|
938
|
+
* {@link createBaseProgram | `createBaseProgram()`}
|
|
939
|
+
* already include the structured UI layer by default, in such cases, calling
|
|
940
|
+
* this function is typically unnecessary and **redundant interception** also
|
|
941
|
+
* is **not recommended**.
|
|
942
|
+
*
|
|
943
|
+
* ------------------------------------------------------------------------
|
|
944
|
+
* #### Supported Program Types.
|
|
945
|
+
* ------------------------------------------------------------------------
|
|
946
|
+
*
|
|
947
|
+
* **1.** Factory-based:
|
|
948
|
+
* ```ts
|
|
949
|
+
* import {
|
|
950
|
+
* applyCommanderUi,
|
|
951
|
+
* createBaseProgram
|
|
952
|
+
* } from "@rzl-zone/build-tools/commander-kit";
|
|
953
|
+
*
|
|
954
|
+
* const programFactory = createBaseProgram();
|
|
955
|
+
* const program = applyCommanderUi(programFactory);
|
|
956
|
+
* ```
|
|
957
|
+
*
|
|
958
|
+
* **2.** Native Commander instance:
|
|
959
|
+
* ```ts
|
|
960
|
+
* import { Command } from "commander"
|
|
961
|
+
* import { applyCommanderUi } from "@rzl-zone/build-tools/commander-kit";
|
|
962
|
+
*
|
|
963
|
+
* const nativeProgram = new Command();
|
|
964
|
+
* const program = applyCommanderUi(nativeProgram);
|
|
965
|
+
* ```
|
|
966
|
+
*
|
|
967
|
+
* When used with {@link createBaseProgram | `createBaseProgram`}, certain
|
|
968
|
+
* interception steps are skipped because the factory already installs baseline
|
|
969
|
+
* behavior and internal state wiring.
|
|
970
|
+
*
|
|
971
|
+
* When used with a plain {@link Command | `Command`} instance created directly
|
|
972
|
+
* from Commander (e.g. `new Command()` or an imported `program` singleton), this
|
|
973
|
+
* function installs all required interception and metadata tracking layers.
|
|
974
|
+
*
|
|
975
|
+
* - *In short:*
|
|
976
|
+
* - Programs created via `createBaseProgram()` already include
|
|
977
|
+
* foundational behavior.
|
|
978
|
+
* - Native Commander instances are fully instrumented by this function.
|
|
979
|
+
*
|
|
980
|
+
* ------------------------------------------------------------------------
|
|
981
|
+
* #### Factory Integration.
|
|
982
|
+
* ------------------------------------------------------------------------
|
|
983
|
+
*
|
|
984
|
+
* Programs created via {@link createBaseProgram | `createBaseProgram()`}
|
|
985
|
+
* already include the structured UI layer by default.
|
|
986
|
+
*
|
|
987
|
+
* In such cases, calling `applyCommanderUi()` manually is unnecessary
|
|
988
|
+
* and generally not recommended.
|
|
989
|
+
*
|
|
990
|
+
* - ***The factory installs:***
|
|
991
|
+
* - Internal state wiring.
|
|
992
|
+
* - Error interception.
|
|
993
|
+
* - Help customization.
|
|
994
|
+
* - Version handling lifecycle.
|
|
995
|
+
*
|
|
996
|
+
* ***`applyCommanderUi()` primarily exists to instrument native
|
|
997
|
+
* {@link Command | `Command`}, or {@link CliCommand | `CliCommand`}
|
|
998
|
+
* instances that were not created through the factory.***
|
|
999
|
+
*
|
|
1000
|
+
* If the program instance was created via **`createBaseProgram()`**,
|
|
1001
|
+
* the **UI layer** is **already installed**, **reapplying** this function may
|
|
1002
|
+
* result in **redundant interception** and is **not recommended**.
|
|
1003
|
+
*
|
|
1004
|
+
* ------------------------------------------------------------------------
|
|
1005
|
+
* #### Installed UI Layer.
|
|
1006
|
+
* ------------------------------------------------------------------------
|
|
1007
|
+
*
|
|
1008
|
+
* This function standardizes:
|
|
1009
|
+
*
|
|
1010
|
+
* - Error message formatting.
|
|
1011
|
+
* - Header rendering.
|
|
1012
|
+
* - Usage resolution.
|
|
1013
|
+
* - Help hint presentation.
|
|
1014
|
+
* - Version interception.
|
|
1015
|
+
*
|
|
1016
|
+
* The goal is to provide a consistent, styled CLI output surface
|
|
1017
|
+
* independent of Commander’s default formatting.
|
|
1018
|
+
*
|
|
1019
|
+
* ------------------------------------------------------------------------
|
|
1020
|
+
* #### Internal Mutations.
|
|
1021
|
+
* ------------------------------------------------------------------------
|
|
1022
|
+
*
|
|
1023
|
+
* This function performs the following mutations on the provided
|
|
1024
|
+
* `program` instance:
|
|
1025
|
+
*
|
|
1026
|
+
* - Overrides `.error()`.
|
|
1027
|
+
* - Installs `.exitOverride()`.
|
|
1028
|
+
* - Replaces `.createHelp()`.
|
|
1029
|
+
* - Intercepts manual:
|
|
1030
|
+
* - `.usage()` calls.
|
|
1031
|
+
* - `.helpOption()` calls.
|
|
1032
|
+
* - `.version()` calls.
|
|
1033
|
+
*
|
|
1034
|
+
* These interceptions allow internal metadata tracking without
|
|
1035
|
+
* relying on Commander private properties.
|
|
1036
|
+
*
|
|
1037
|
+
* ------------------------------------------------------------------------
|
|
1038
|
+
* #### Usage Resolution Order.
|
|
1039
|
+
* ------------------------------------------------------------------------
|
|
1040
|
+
*
|
|
1041
|
+
* When rendering usage inside error output, the value is resolved
|
|
1042
|
+
* in the following priority:
|
|
1043
|
+
*
|
|
1044
|
+
* 1. Manual `.usage()` override (intercepted internally).
|
|
1045
|
+
* 2. UI `options.usage`.
|
|
1046
|
+
* 3. Commander default usage string.
|
|
1047
|
+
*
|
|
1048
|
+
* ------------------------------------------------------------------------
|
|
1049
|
+
* #### ℹ️ Help Hint Handling.
|
|
1050
|
+
* ------------------------------------------------------------------------
|
|
1051
|
+
*
|
|
1052
|
+
* If `.helpOption(false)` is used, the help hint line
|
|
1053
|
+
* (`Run -h, --help`) will not be displayed.
|
|
1054
|
+
*
|
|
1055
|
+
* Help metadata is internally tracked and does not depend on
|
|
1056
|
+
* Commander private state.
|
|
1057
|
+
*
|
|
1058
|
+
* ------------------------------------------------------------------------
|
|
1059
|
+
* #### ⚠️ Important Behavior Notes.
|
|
1060
|
+
* ------------------------------------------------------------------------
|
|
1061
|
+
*
|
|
1062
|
+
* - This function **mutates** the provided program instance.
|
|
1063
|
+
* - It replaces Commander’s default error handler.
|
|
1064
|
+
* - The process exits with code `1` after rendering an error.
|
|
1065
|
+
* - The function is not strictly idempotent and should only be
|
|
1066
|
+
* applied once per program instance.
|
|
1067
|
+
*
|
|
1068
|
+
* ------------------------------------------------------------------------
|
|
1069
|
+
*
|
|
1070
|
+
* @param program - A Commander program instance, this can be either:
|
|
1071
|
+
* - A program created via {@link createBaseProgram | `createBaseProgram`}, or
|
|
1072
|
+
* - A native {@link Command | `Command`}, or {@link CliCommand | `CliCommand`} instance (e.g. `new Command()`. `new CliCommand()` or an imported `program`/`cliProgram` singleton).
|
|
1073
|
+
*
|
|
1074
|
+
* @param options - Optional UI configuration.
|
|
1075
|
+
*
|
|
1076
|
+
* @throws {ConfigurationError}
|
|
1077
|
+
* Thrown when `program` is not a valid Commander program instance.
|
|
1078
|
+
*
|
|
1079
|
+
* ------------------------------------------------------------------------
|
|
1080
|
+
*
|
|
1081
|
+
* @example
|
|
1082
|
+
* Using a native Commander instance (manual installation required):
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* import { Command } from "commander"
|
|
1085
|
+
* import { applyCommanderUi } from "@rzl-zone/build-tools/commander-kit";
|
|
1086
|
+
*
|
|
1087
|
+
* const nativeProgram = new Command();
|
|
1088
|
+
*
|
|
1089
|
+
* const program = applyCommanderUi(nativeProgram, {
|
|
1090
|
+
* title: "Custom CLI",
|
|
1091
|
+
* version: "1.1.0",
|
|
1092
|
+
* packageName: "my-package-name"
|
|
1093
|
+
* });
|
|
1094
|
+
*
|
|
1095
|
+
* program.parse();
|
|
1096
|
+
* ```
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* Using the factory (UI layer already installed):
|
|
1100
|
+
* ```ts
|
|
1101
|
+
* import { createBaseProgram } from "@rzl-zone/build-tools/commander-kit";
|
|
1102
|
+
*
|
|
1103
|
+
* const program = createBaseProgram({
|
|
1104
|
+
* commandIdentity: identity,
|
|
1105
|
+
* ui: {
|
|
1106
|
+
* title: "My CLI Tool",
|
|
1107
|
+
* usage: "my-cli <command> [options]"
|
|
1108
|
+
* }
|
|
1109
|
+
* });
|
|
1110
|
+
*
|
|
1111
|
+
* program.parse();
|
|
1112
|
+
* ```
|
|
1113
|
+
*
|
|
1114
|
+
* @example
|
|
1115
|
+
* Manual usage override takes priority:
|
|
1116
|
+
* ```ts
|
|
1117
|
+
* import { CliCommand, applyCommanderUi } from "@rzl-zone/build-tools/commander-kit";
|
|
1118
|
+
*
|
|
1119
|
+
* const programCli = new CliCommand();
|
|
1120
|
+
*
|
|
1121
|
+
* programCli
|
|
1122
|
+
* .name("my-cli")
|
|
1123
|
+
* .usage("<input> [options]");
|
|
1124
|
+
*
|
|
1125
|
+
* // Apply default UI helpers
|
|
1126
|
+
* const program = applyCommanderUi(programCli, {
|
|
1127
|
+
* usage: "fallback usage (will NOT be used)",
|
|
1128
|
+
* });
|
|
1129
|
+
*
|
|
1130
|
+
* // Rendered usage will be:
|
|
1131
|
+
* // my-cli <input> [options]
|
|
1132
|
+
*
|
|
1133
|
+
* // In this case the manual `.usage()` call defined before
|
|
1134
|
+
* // `applyCommanderUi()` takes precedence.
|
|
1135
|
+
*
|
|
1136
|
+
* // The usage string provided to `applyCommanderUi()` will
|
|
1137
|
+
* // be ignored if a custom usage has already been configured.
|
|
1138
|
+
* ```
|
|
1139
|
+
*
|
|
1140
|
+
* @example
|
|
1141
|
+
* Disable help hint line:
|
|
1142
|
+
* ```ts
|
|
1143
|
+
* import { Command } from "commander"
|
|
1144
|
+
* import { applyCommanderUi } from "@rzl-zone/build-tools/commander-kit";
|
|
1145
|
+
*
|
|
1146
|
+
* const nativeProgram = new Command();
|
|
1147
|
+
*
|
|
1148
|
+
* const program = applyCommanderUi(nativeProgram);
|
|
1149
|
+
*
|
|
1150
|
+
* program.helpOption(false);
|
|
1151
|
+
* // Disables the help option and prevents the "Run -h, --help" hint
|
|
1152
|
+
* // from appearing in error messages.
|
|
1153
|
+
*
|
|
1154
|
+
* program.version(false);
|
|
1155
|
+
* // Disables the version command automatically configured by
|
|
1156
|
+
* // `applyCommanderUi()` or `createBaseProgram()`.
|
|
1157
|
+
* ```
|
|
1158
|
+
*
|
|
1159
|
+
* @example
|
|
1160
|
+
* Minimal setup for native Commander:
|
|
1161
|
+
* ```ts
|
|
1162
|
+
* import { Command } from "commander"
|
|
1163
|
+
* import { applyCommanderUi } from "@rzl-zone/build-tools/commander-kit";
|
|
1164
|
+
*
|
|
1165
|
+
* const nativeProgram = new Command();
|
|
1166
|
+
* const program = applyCommanderUi(nativeProgram);
|
|
1167
|
+
*
|
|
1168
|
+
* program.parse();
|
|
1169
|
+
* ```
|
|
1170
|
+
*/
|
|
1171
|
+
declare function applyCommanderUi(program: CommandBaseProgram, options: CommanderUiOptions): CommandBaseProgram;
|
|
1172
|
+
declare function applyCommanderUi(program: CliCommand | Command, options: CommanderUiOptions): CliCommand;
|
|
1173
|
+
declare function applyCommanderUi(program: unknown, options: CommanderUiOptions): never;
|
|
1174
|
+
/** ----------------------------------------------------------------
|
|
1175
|
+
* * ***Command-line argument definition class.***
|
|
1176
|
+
* ----------------------------------------------------------------
|
|
1177
|
+
*
|
|
1178
|
+
* Represents a positional CLI argument definition.
|
|
1179
|
+
*
|
|
1180
|
+
* This class extends Commander’s {@link Argument | **`Argument`**}
|
|
1181
|
+
* and is provided to ensure compatibility with the
|
|
1182
|
+
* additional types and utilities exposed by this library.
|
|
1183
|
+
*/
|
|
1184
|
+
declare class CliArgument extends Argument {
|
|
1185
|
+
constructor(arg: string, description?: string);
|
|
1186
|
+
}
|
|
1187
|
+
/** ----------------------------------------------------------------
|
|
1188
|
+
* * ***Commander help system class.***
|
|
1189
|
+
* ----------------------------------------------------------------
|
|
1190
|
+
*
|
|
1191
|
+
* Extends Commander’s {@link Help | **`Help`**} class
|
|
1192
|
+
* and allows customization of CLI help output,
|
|
1193
|
+
* formatting behavior, and command listing.
|
|
1194
|
+
*
|
|
1195
|
+
* This class can be used to override the default
|
|
1196
|
+
* help renderer used by {@link CliCommand | `CliCommand`}.
|
|
1197
|
+
*/
|
|
1198
|
+
declare class CliHelp extends Help {
|
|
1199
|
+
constructor();
|
|
1200
|
+
}
|
|
1201
|
+
/** ----------------------------------------------------------------
|
|
1202
|
+
* * ***Command-line option definition class.***
|
|
1203
|
+
* ----------------------------------------------------------------
|
|
1204
|
+
*
|
|
1205
|
+
* Represents a CLI option or flag definition.
|
|
1206
|
+
*
|
|
1207
|
+
* This class extends Commander’s {@link Option | **`Option`**}
|
|
1208
|
+
* and provides the standard option behavior used
|
|
1209
|
+
* by {@link CliCommand | `CliCommand`}.
|
|
1210
|
+
*
|
|
1211
|
+
* - ***Supports:***
|
|
1212
|
+
* - short and long flags.
|
|
1213
|
+
* - default values.
|
|
1214
|
+
* - variadic arguments.
|
|
1215
|
+
* - custom parsing logic.
|
|
1216
|
+
*/
|
|
1217
|
+
declare class CliOption extends Option {
|
|
1218
|
+
constructor(arg: string, description?: string);
|
|
1219
|
+
}
|
|
1220
|
+
/** ----------------------------------------------------------------
|
|
1221
|
+
* * ***Default CLI program instance.***
|
|
1222
|
+
* ----------------------------------------------------------------
|
|
1223
|
+
*
|
|
1224
|
+
* Shared CLI program instance created from
|
|
1225
|
+
* {@link CliCommand | **`CliCommand`**}.
|
|
1226
|
+
*
|
|
1227
|
+
* This module-level singleton provides a convenient
|
|
1228
|
+
* default program object for simple CLI tools without
|
|
1229
|
+
* manually creating a command instance.
|
|
1230
|
+
*
|
|
1231
|
+
* ----------------------------------------------------------------
|
|
1232
|
+
*
|
|
1233
|
+
* Equivalent to:
|
|
1234
|
+
*
|
|
1235
|
+
* ```ts
|
|
1236
|
+
* import { CliCommand } from "@rzl-zone/build-tools/commander-kit";
|
|
1237
|
+
*
|
|
1238
|
+
* const cliProgram = new CliCommand();
|
|
1239
|
+
* ```
|
|
1240
|
+
*/
|
|
1241
|
+
declare const cliProgram: CliCommand;
|
|
1242
|
+
/** ----------------------------------------------------------------
|
|
1243
|
+
* * ***Commander base error class.***
|
|
1244
|
+
* ----------------------------------------------------------------
|
|
1245
|
+
*
|
|
1246
|
+
* Base error thrown internally by Commander when CLI
|
|
1247
|
+
* parsing or execution fails.
|
|
1248
|
+
*/
|
|
1249
|
+
declare class CliCommanderError extends CommanderError {
|
|
1250
|
+
constructor(exitCode: number, code: CommanderErrorCode, message: string);
|
|
1251
|
+
}
|
|
1252
|
+
/** ----------------------------------------------------------------
|
|
1253
|
+
* * ***Error thrown when an argument fails validation.***
|
|
1254
|
+
* ----------------------------------------------------------------
|
|
1255
|
+
*/
|
|
1256
|
+
declare class CliInvalidArgumentError extends InvalidArgumentError {
|
|
1257
|
+
constructor(message: string);
|
|
1258
|
+
}
|
|
1259
|
+
/** ----------------------------------------------------------------
|
|
1260
|
+
* * ***Error thrown when an option argument fails validation.***
|
|
1261
|
+
* ----------------------------------------------------------------
|
|
1262
|
+
*/
|
|
1263
|
+
declare class CliInvalidOptionArgumentError extends InvalidOptionArgumentError {
|
|
1264
|
+
constructor(message: string);
|
|
1265
|
+
}
|
|
1266
|
+
/** ----------------------------------------------------------------
|
|
1267
|
+
* * ***CLI Argument Factory.***
|
|
1268
|
+
* ----------------------------------------------------------------
|
|
1269
|
+
*
|
|
1270
|
+
* Creates a new {@link CliArgument | **`CliArgument`**} instance.
|
|
1271
|
+
*
|
|
1272
|
+
* This helper constructs a CLI argument definition compatible with
|
|
1273
|
+
* Commander argument parsing while providing a consistent creation
|
|
1274
|
+
* entry point within the framework.
|
|
1275
|
+
*
|
|
1276
|
+
* @param name Argument definition string (e.g. `<file>` or `[dir]`).
|
|
1277
|
+
* @param description Optional argument description used in help output.
|
|
1278
|
+
*
|
|
1279
|
+
* @returns A newly created {@link CliArgument | **`CliArgument`**} instance.
|
|
1280
|
+
*/
|
|
1281
|
+
declare const cliCreateArgument: (name: string, description?: string) => CliArgument;
|
|
1282
|
+
/** ----------------------------------------------------------------
|
|
1283
|
+
* * ***CLI Command Factory.***
|
|
1284
|
+
* ----------------------------------------------------------------
|
|
1285
|
+
*
|
|
1286
|
+
* Creates a new {@link CliCommand | **`CliCommand`**} instance.
|
|
1287
|
+
*
|
|
1288
|
+
* This helper acts as a small factory for constructing command
|
|
1289
|
+
* objects used by the CLI framework. It ensures all commands are
|
|
1290
|
+
* created through the same entry point, which allows future
|
|
1291
|
+
* extensions (such as internal metadata attachment or lifecycle
|
|
1292
|
+
* hooks) without changing call sites.
|
|
1293
|
+
*
|
|
1294
|
+
* @param name Optional command name.
|
|
1295
|
+
*
|
|
1296
|
+
* @returns A newly created {@link CliCommand | **`CliCommand`**} instance.
|
|
1297
|
+
*/
|
|
1298
|
+
declare const cliCreateCommand: (name?: string) => CliCommand;
|
|
1299
|
+
/** ----------------------------------------------------------------
|
|
1300
|
+
* * ***CLI Option Factory.***
|
|
1301
|
+
* ----------------------------------------------------------------
|
|
1302
|
+
*
|
|
1303
|
+
* Creates a new {@link CliOption | **`CliOption`**} instance.
|
|
1304
|
+
*
|
|
1305
|
+
* This helper constructs a CLI option definition compatible with
|
|
1306
|
+
* Commander option parsing while ensuring a consistent factory
|
|
1307
|
+
* entry point for option creation within the framework.
|
|
1308
|
+
*
|
|
1309
|
+
* @param arg Option flags definition
|
|
1310
|
+
* (e.g. `"-p, --port <number>"`).
|
|
1311
|
+
*
|
|
1312
|
+
* @param description Optional description displayed in help output.
|
|
1313
|
+
*
|
|
1314
|
+
* @returns A newly created {@link CliOption | **`CliOption`**} instance.
|
|
1315
|
+
*/
|
|
1316
|
+
declare const cliCreateOption: (arg: string, description?: string) => CliOption;
|
|
1317
|
+
/** ----------------------------------------------------------------
|
|
1318
|
+
* * ***Context object provided when injecting custom help text.***
|
|
1319
|
+
* ----------------------------------------------------------------
|
|
1320
|
+
*/
|
|
1321
|
+
interface CliAddHelpTextContext extends AddHelpTextContext {}
|
|
1322
|
+
/** ----------------------------------------------------------------
|
|
1323
|
+
* * ***Position where custom help text should be injected.***
|
|
1324
|
+
* ----------------------------------------------------------------
|
|
1325
|
+
*/
|
|
1326
|
+
type CliAddHelpTextPosition = AddHelpTextPosition;
|
|
1327
|
+
/** ----------------------------------------------------------------
|
|
1328
|
+
* * ***Configuration options for a CLI command.***
|
|
1329
|
+
* ----------------------------------------------------------------
|
|
1330
|
+
*/
|
|
1331
|
+
interface CliCommandOptions extends CommandOptions {}
|
|
1332
|
+
/** ----------------------------------------------------------------
|
|
1333
|
+
* * ***Additional options attached to Commander errors.***
|
|
1334
|
+
* ----------------------------------------------------------------
|
|
1335
|
+
*/
|
|
1336
|
+
interface CliErrorOptions extends ErrorOptions {}
|
|
1337
|
+
/** ----------------------------------------------------------------
|
|
1338
|
+
* * ***Configuration for executable subcommands.***
|
|
1339
|
+
* ----------------------------------------------------------------
|
|
1340
|
+
*/
|
|
1341
|
+
interface CliExecutableCommandOptions extends ExecutableCommandOptions {}
|
|
1342
|
+
/** ----------------------------------------------------------------
|
|
1343
|
+
* * ***Configuration options for the Commander help system.***
|
|
1344
|
+
* ----------------------------------------------------------------
|
|
1345
|
+
*/
|
|
1346
|
+
type CliHelpConfiguration = HelpConfiguration;
|
|
1347
|
+
/** ----------------------------------------------------------------
|
|
1348
|
+
* * ***Context information available during help rendering.***
|
|
1349
|
+
* ----------------------------------------------------------------
|
|
1350
|
+
*/
|
|
1351
|
+
interface CliHelpContext extends HelpContext {}
|
|
1352
|
+
/** ----------------------------------------------------------------
|
|
1353
|
+
* * ***Lifecycle hook event names supported by Commander.***
|
|
1354
|
+
* ----------------------------------------------------------------
|
|
1355
|
+
*/
|
|
1356
|
+
type CliHookEvent = HookEvent;
|
|
1357
|
+
/** ----------------------------------------------------------------
|
|
1358
|
+
* * ***Indicates where an option value originated from.***
|
|
1359
|
+
* ----------------------------------------------------------------
|
|
1360
|
+
*/
|
|
1361
|
+
type CliOptionValueSource = OptionValueSource;
|
|
1362
|
+
/** ----------------------------------------------------------------
|
|
1363
|
+
* * ***Resolved option values object.***
|
|
1364
|
+
* ----------------------------------------------------------------
|
|
1365
|
+
*/
|
|
1366
|
+
type CliOptionValues = OptionValues;
|
|
1367
|
+
/** ----------------------------------------------------------------
|
|
1368
|
+
* * ***Configuration controlling Commander output behavior.***
|
|
1369
|
+
* ----------------------------------------------------------------
|
|
1370
|
+
*/
|
|
1371
|
+
interface CliOutputConfiguration extends OutputConfiguration {}
|
|
1372
|
+
/** ----------------------------------------------------------------
|
|
1373
|
+
* * ***Options controlling the parsing behavior.***
|
|
1374
|
+
* ----------------------------------------------------------------
|
|
1375
|
+
*/
|
|
1376
|
+
interface CliParseOptions extends ParseOptions {}
|
|
1377
|
+
/** ----------------------------------------------------------------
|
|
1378
|
+
* * ***Result object returned when parsing arguments manually.***
|
|
1379
|
+
* ----------------------------------------------------------------
|
|
1380
|
+
*/
|
|
1381
|
+
interface CliParseOptionsResult extends ParseOptionsResult {}
|
|
1382
|
+
export { type CliAddHelpTextContext, type CliAddHelpTextPosition, CliArgument, CliCommand, type CliCommandOptions, CliCommanderError, type CliErrorOptions, type CliExecutableCommandOptions, CliHelp, type CliHelpConfiguration, type CliHelpContext, type CliHookEvent, CliInvalidArgumentError, CliInvalidOptionArgumentError, CliOption, type CliOptionValueSource, type CliOptionValues, type CliOutputConfiguration, type CliParseOptions, type CliParseOptionsResult, type CommandContext, CommandIdentity, type CommanderErrorCode, type CommanderUiOptions, type CreateBaseProgramOptions, type TypedCommanderError, applyCommanderUi, cliCreateArgument, cliCreateCommand, cliCreateOption, cliProgram, createBaseProgram, formatCommanderError, getCommanderErrorCode, handleCommanderExit, isCommanderError };
|
|
1383
|
+
//# sourceMappingURL=index.d.cts.map
|