cli-api 0.1.1 → 0.2.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 (43) hide show
  1. package/README.md +22 -25
  2. package/dist/index.d.mts +394 -0
  3. package/dist/index.mjs +3 -0
  4. package/dist/interfaces-COq24bNI.mjs +391 -0
  5. package/dist/run-C903J5ca.mjs +1137 -0
  6. package/package.json +37 -37
  7. package/.hgignore +0 -12
  8. package/.idea/$CACHE_FILE$ +0 -6
  9. package/.idea/clap.iml +0 -8
  10. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  11. package/.idea/deployment.xml +0 -63
  12. package/.idea/inspectionProfiles/Project_Default.xml +0 -10
  13. package/.idea/misc.xml +0 -6
  14. package/.idea/modules.xml +0 -8
  15. package/.idea/vcs.xml +0 -6
  16. package/Makefile +0 -14
  17. package/babel.config.json +0 -33
  18. package/dist/cjs/index.js +0 -588
  19. package/dist/cjs/index.js.map +0 -1
  20. package/dist/es/index.mjs +0 -578
  21. package/dist/es/index.mjs.map +0 -1
  22. package/dist/types/app-help.d.ts +0 -3
  23. package/dist/types/commands/command-help.d.ts +0 -2
  24. package/dist/types/commands/version.d.ts +0 -2
  25. package/dist/types/constants.d.ts +0 -4
  26. package/dist/types/index.d.ts +0 -3
  27. package/dist/types/interfaces.d.ts +0 -79
  28. package/dist/types/options.d.ts +0 -7
  29. package/dist/types/print-command-help.d.ts +0 -2
  30. package/dist/types/run.d.ts +0 -2
  31. package/dist/types/utils.d.ts +0 -17
  32. package/rollup.config.js +0 -44
  33. package/src/app-help.ts +0 -34
  34. package/src/commands/command-help.ts +0 -28
  35. package/src/commands/version.ts +0 -11
  36. package/src/constants.ts +0 -4
  37. package/src/index.ts +0 -3
  38. package/src/interfaces.ts +0 -89
  39. package/src/options.ts +0 -266
  40. package/src/print-command-help.ts +0 -78
  41. package/src/run.ts +0 -45
  42. package/src/utils.ts +0 -86
  43. package/tsconfig.json +0 -32
package/README.md CHANGED
@@ -5,36 +5,33 @@ Easily create a CLI app.
5
5
  ## Usage
6
6
 
7
7
  ```ts
8
- import run from "cli-api";
8
+ import {App, Command} from 'cli-api'
9
9
  import * as pkg from '../package.json'
10
- import commands from './commands'
11
10
 
12
- run({
13
- name: "hello",
14
- version: pkg.version,
15
- argv0: pkg.name,
16
- commands: [
17
- {
18
- name: "world",
19
- alias: 'w',
20
- description: 'Prints "Hello World".',
21
- async execute(opts, args) {
22
- console.log(`Hello ${opts.name}`)
23
- },
24
- options: [
25
- {
26
- name: 'name',
27
- alias: 'n',
28
- description: "Person you want to greet",
29
- required: true,
30
- },
31
- ]
11
+ const world = new Command('world')
12
+ .describe('Prints a greeting.')
13
+ .flag('verbose', {
14
+ alias: 'v',
15
+ description: 'Print more info',
16
+ })
17
+ .arg('name', {
18
+ description: 'Person you want to greet',
19
+ required: true,
20
+ })
21
+ .run((args, kwargs) => {
22
+ if (kwargs.verbose) {
23
+ console.log('Preparing greeting...')
32
24
  }
33
- ]
34
- })
25
+ console.log(`Hello ${kwargs.name}`)
26
+ })
27
+
28
+ await new App('hello')
29
+ .meta({version: pkg.version, argv0: pkg.name})
30
+ .command(world)
31
+ .execute()
35
32
  ```
36
33
 
37
34
  ```shell
38
- $ hello world -n Mark
35
+ $ hello world Mark
39
36
  Hello Mark
40
37
  ```
@@ -0,0 +1,394 @@
1
+ import { ChalkInstance, ColorSupportLevel } from "chalk";
2
+
3
+ //#region src/color.d.ts
4
+ type ColorMode = 'always' | 'auto' | 'never';
5
+ //#endregion
6
+ //#region src/interfaces.d.ts
7
+ type U2I<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
8
+ type OptionalKeys<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? K : never }[keyof T];
9
+ type RequiredKeys<T> = Exclude<keyof T, OptionalKeys<T>>;
10
+ type Flatten<T> = { [K in keyof T]: T[K] } & {};
11
+ type Simplify<T> = { [K in RequiredKeys<T>]: T[K] } & { [K in OptionalKeys<T>]?: Exclude<T[K], undefined> };
12
+ type PrimitiveOfOptType<T extends AnyOptType | undefined> = T extends undefined ? string : T extends OptType.STRING ? string : T extends OptType.BOOL ? boolean : T extends OptType.INT | OptType.FLOAT ? number : T extends OptType.INPUT_FILE | OptType.INPUT_DIRECTORY | OptType.OUTPUT_FILE | OptType.OUTPUT_DIRECTORY | OptType.EMPTY_DIRECTORY ? string : T extends readonly (infer L)[] ? (L extends string ? L : string) : string;
13
+ type KeyOfItem<I> = I extends {
14
+ key: infer K extends string;
15
+ } ? K : I extends {
16
+ name: infer N extends string;
17
+ } ? N : never;
18
+ type TypeOfItem<I> = I extends {
19
+ type: infer T extends AnyOptType;
20
+ } ? T : undefined;
21
+ type IsRepeatable<I> = I extends {
22
+ repeatable: true | number;
23
+ } ? true : false;
24
+ type IsRequired<I> = I extends {
25
+ required: true | number;
26
+ } ? true : false;
27
+ type IsAlwaysPresent<I> = IsRepeatable<I> extends true ? true : IsRequired<I>;
28
+ type ValueOfOption<O extends Option> = IsRepeatable<O> extends true ? PrimitiveOfOptType<TypeOfItem<O>>[] : PrimitiveOfOptType<TypeOfItem<O>>;
29
+ type OptionPropMap<I extends Option> = { [K in KeyOfItem<I>]: ValueOfOption<I> };
30
+ type FlagPropMap<F extends Flag> = { [K in KeyOfItem<F>]: boolean };
31
+ type MergeOptionProps<IU extends Option> = U2I<IU extends any ? OptionPropMap<IU> : never>;
32
+ type MergeFlagProps<FU extends Flag> = U2I<FU extends any ? FlagPropMap<FU> : never>;
33
+ type RequiredOptions<I extends Option> = I extends any ? (IsAlwaysPresent<I> extends true ? I : never) : never;
34
+ type OptionalOptions<I extends Option> = Exclude<I, RequiredOptions<I>>;
35
+ type OptionsOf<Opts extends readonly Option[] | undefined, Flags extends readonly Flag[] | undefined> = (Opts extends readonly any[] ? (MergeOptionProps<RequiredOptions<Opts[number]>> & Partial<MergeOptionProps<OptionalOptions<Opts[number]>>>) : {}) & (Flags extends readonly any[] ? Partial<MergeFlagProps<Flags[number]>> : {});
36
+ type ValueOfArg<A$1 extends Argument> = IsRepeatable<A$1> extends true ? PrimitiveOfOptType<TypeOfItem<A$1>>[] : PrimitiveOfOptType<TypeOfItem<A$1>>;
37
+ type _ArgsFixed<As extends readonly Argument[], Acc extends unknown[] = []> = As extends readonly [infer A, ...infer R] ? A extends Argument ? IsRepeatable<A> extends true ? Acc : _ArgsFixed<R & readonly Argument[], [...Acc, ValueOfArg<A>]> : Acc : Acc;
38
+ type _ArgsTailRepeat<As extends readonly Argument[]> = As extends readonly [...infer _, infer L] ? L extends Argument ? (IsRepeatable<L> extends true ? PrimitiveOfOptType<TypeOfItem<L>> : never) : never : never;
39
+ type ArgumentPropMap<I extends Argument> = { [K in KeyOfItem<I>]: ValueOfArg<I> };
40
+ type MergeArgumentProps<IU extends Argument> = U2I<IU extends any ? ArgumentPropMap<IU> : never>;
41
+ type RequiredArguments<I extends Argument> = I extends any ? (IsAlwaysPresent<I> extends true ? I : never) : never;
42
+ type OptionalArguments<I extends Argument> = Exclude<I, RequiredArguments<I>>;
43
+ type ArgsOf<As extends readonly Argument[] | undefined> = As extends readonly Argument[] ? _ArgsTailRepeat<As> extends never ? _ArgsFixed<As> : [..._ArgsFixed<As>, ..._ArgsTailRepeat<As>[]] : unknown[];
44
+ type OptsOf<Opts extends readonly Option[] | undefined, Flags extends readonly Flag[] | undefined, As extends readonly Argument[] | undefined> = Simplify<OptionsOf<Opts, Flags> & (As extends readonly any[] ? (MergeArgumentProps<RequiredArguments<As[number]>> & Partial<MergeArgumentProps<OptionalArguments<As[number]>>>) : {})>;
45
+ type MaybePromise<V> = V | PromiseLike<V>;
46
+ declare enum OptType {
47
+ STRING = 0,
48
+ BOOL = 1,
49
+ INT = 2,
50
+ FLOAT = 3,
51
+ /** A string, truncated and converted to lowercase. */
52
+ ENUM = 4,
53
+ /** File must be readable. Single dash will be converted to STDIN. */
54
+ INPUT_FILE = 5,
55
+ /** Directory must be readable. */
56
+ INPUT_DIRECTORY = 6,
57
+ /** File's directory must exist and be writeable. Single dash will be converted to STDOUT. */
58
+ OUTPUT_FILE = 7,
59
+ OUTPUT_DIRECTORY = 8,
60
+ /** An empty or non-existent directory. */
61
+ EMPTY_DIRECTORY = 9,
62
+ }
63
+ interface ArgumentOrOptionOrFlag {
64
+ /** Name of the option to display in help. */
65
+ name: string;
66
+ /** Alternative name for this option. */
67
+ alias?: string | string[];
68
+ /** Description of the option. */
69
+ description?: string;
70
+ /** Default value to display in help. */
71
+ defaultValueText?: string;
72
+ /** Property name to use in `run()` opts. */
73
+ key?: string;
74
+ }
75
+ type AnyOptType = OptType | readonly string[];
76
+ interface ArgumentOrOption extends ArgumentOrOptionOrFlag {
77
+ /** Type to coerce the option value to. */
78
+ type?: AnyOptType;
79
+ /** Allowed values for `OptType.ENUM`. */
80
+ enumValues?: readonly string[];
81
+ /** Option or positional may be provided more than once. When set to a number, that number is the maximum count. */
82
+ repeatable?: boolean | number;
83
+ /** Option or positional is required. For repeatable positionals, a number means the minimum count required. */
84
+ required?: boolean | number;
85
+ /** Default value if not provided. */
86
+ defaultValue?: any | (() => any);
87
+ }
88
+ /** Same as options, but the type is bool and a value is not required. */
89
+ interface Flag extends ArgumentOrOptionOrFlag, OptionOrFlag {
90
+ valueNotRequired?: true;
91
+ /** Default value if not provided. */
92
+ defaultValue?: boolean | (() => boolean);
93
+ }
94
+ /** Positional argument. */
95
+ interface Argument extends ArgumentOrOption {}
96
+ interface OptionOrFlag {
97
+ /** Add a `--no-${name}` long-form alias that uses `valueIfNoPrefix` or `false`. */
98
+ noPrefix?: boolean;
99
+ /** Value to use when the option is present without an explicit value. */
100
+ valueIfSet?: any | (() => any);
101
+ /** Value to use when the `--no-${name}` form is provided. */
102
+ valueIfNoPrefix?: any | (() => any);
103
+ }
104
+ /** Option with value. */
105
+ interface Option extends ArgumentOrOption, OptionOrFlag {
106
+ /** Placeholder value to use in help. */
107
+ valuePlaceholder?: string;
108
+ /** Caller may specify a value (`--opt=value`), but it's not required. When omitted, `valueIfSet` is used. */
109
+ valueNotRequired?: boolean;
110
+ }
111
+ type CommandBase = {
112
+ name: string;
113
+ alias?: string | string[];
114
+ description?: string;
115
+ longDescription?: string;
116
+ };
117
+ type AnyApp = App<any, any, any, any, any>;
118
+ type LeafCommand<Opts extends readonly Option[] | undefined = undefined, Flags extends readonly Flag[] | undefined = undefined, As extends readonly Argument[] | undefined = undefined> = LeafCommandInput<Opts, Flags, As>;
119
+ type BranchCommand<Cs extends CommandChildren = CommandChildren> = BranchCommandInput<Cs>;
120
+ type CommandShape<Opts extends readonly Option[] | undefined = undefined, Flags extends readonly Flag[] | undefined = undefined, As extends readonly Argument[] | undefined = undefined, Cs extends CommandChildren = CommandChildren> = LeafCommand<Opts, Flags, As> | BranchCommand<Cs>;
121
+ type CommandChildren = readonly CommandShape<any, any, any, any>[];
122
+ interface ExecutableInput<Opts extends readonly Option[] | undefined, Flags extends readonly Flag[] | undefined, As extends readonly Argument[] | undefined> {
123
+ options?: Opts;
124
+ flags?: Flags;
125
+ positonals?: As;
126
+ execute(opts: OptsOf<Opts, Flags, As>, args: ArgsOf<As>, context: ExecutionContext): MaybePromise<number | void>;
127
+ }
128
+ interface LeafCommandInput<Opts extends readonly Option[] | undefined, Flags extends readonly Flag[] | undefined, As extends readonly Argument[] | undefined> extends CommandBase, ExecutableInput<Opts, Flags, As> {
129
+ subCommands?: never;
130
+ }
131
+ interface BranchCommandInput<Cs extends CommandChildren> extends CommandBase {
132
+ subCommands: Cs;
133
+ options?: never;
134
+ flags?: never;
135
+ positonals?: never;
136
+ execute?: never;
137
+ }
138
+ /**
139
+ * Per-invocation execution state exposed to command handlers.
140
+ */
141
+ declare class ExecutionContext {
142
+ private readonly _app;
143
+ private readonly _commandPath;
144
+ private readonly _chalk;
145
+ /**
146
+ * Creates a context for a single CLI invocation.
147
+ *
148
+ * @param app The root app being executed.
149
+ * @param colorMode The resolved color mode for the current invocation.
150
+ * @param path The resolved command path for the current invocation.
151
+ */
152
+ constructor(app: AnyApp, colorMode?: ColorMode, path?: readonly string[]);
153
+ /**
154
+ * Gets the root app for the current invocation.
155
+ *
156
+ * @returns The app definition being executed.
157
+ */
158
+ get app(): AnyApp;
159
+ /**
160
+ * Gets the resolved command path for the current invocation.
161
+ *
162
+ * @returns The command names from the app root to the executing command.
163
+ */
164
+ get commandPath(): readonly string[];
165
+ /**
166
+ * Gets the chalk instance configured for the current invocation.
167
+ *
168
+ * @returns The active chalk instance after built-in color flags such as `--color` and `--no-color` have been applied.
169
+ */
170
+ get chalk(): ChalkInstance;
171
+ /**
172
+ * Gets the resolved color support level configured for the current invocation.
173
+ *
174
+ * @returns The active color level from `0` to `3`.
175
+ */
176
+ get colorLevel(): ColorSupportLevel;
177
+ }
178
+ interface AnyLeafCommand extends CommandBase {
179
+ options?: readonly Option[] | undefined;
180
+ flags?: readonly Flag[] | undefined;
181
+ positonals?: readonly Argument[] | undefined;
182
+ execute(opts: Record<string, any>, args: any[], context: ExecutionContext): MaybePromise<number | void>;
183
+ subCommands?: never | undefined;
184
+ }
185
+ interface AnyBranchCommand extends CommandBase {
186
+ subCommands: readonly AnyCmd[];
187
+ options?: never | undefined;
188
+ flags?: never | undefined;
189
+ positonals?: never | undefined;
190
+ execute?: never | undefined;
191
+ }
192
+ type AnyCmd = AnyLeafCommand | AnyBranchCommand;
193
+ type FlagConfigInput = Omit<Flag, 'name' | 'valueNotRequired'>;
194
+ type OptionConfigInput = Omit<Option, 'name'>;
195
+ type ArgumentConfigInput = Omit<Argument, 'name'>;
196
+ type BuildFlag<Name extends string, Config extends FlagConfigInput | undefined> = Flatten<{
197
+ name: Name;
198
+ } & (Config extends undefined ? {} : Config)>;
199
+ type BuildOption<Name extends string, Config extends OptionConfigInput | undefined> = Flatten<{
200
+ name: Name;
201
+ } & (Config extends undefined ? {} : Config)>;
202
+ type BuildArgument<Name extends string, Config extends ArgumentConfigInput | undefined> = Flatten<{
203
+ name: Name;
204
+ } & (Config extends undefined ? {} : Config)>;
205
+ type RunHandler<Opts extends readonly Option[] | undefined, Flags extends readonly Flag[] | undefined, As extends readonly Argument[] | undefined> = (args: ArgsOf<As>, opts: OptsOf<Opts, Flags, As>, context: ExecutionContext) => MaybePromise<number | void>;
206
+ type ExecuteHandler<Opts extends readonly Option[] | undefined, Flags extends readonly Flag[] | undefined, As extends readonly Argument[] | undefined> = ExecutableInput<Opts, Flags, As>['execute'];
207
+ type AppMetaConfig = {
208
+ bin?: string;
209
+ version?: string;
210
+ author?: string;
211
+ description?: string;
212
+ longDescription?: string;
213
+ };
214
+ declare class Command<Opts extends readonly Option[] = [], Flags extends readonly Flag[] = [], As extends readonly Argument[] = [], Cs extends CommandChildren = [], Executable extends boolean = false> {
215
+ private readonly _name;
216
+ private _alias?;
217
+ private _description?;
218
+ private _longDescription?;
219
+ private _options?;
220
+ private _positonals?;
221
+ private _subCommands?;
222
+ protected _handler?: ExecuteHandler<Opts, Flags, As>;
223
+ constructor(name: string);
224
+ get name(): string;
225
+ get alias(): string | string[] | undefined;
226
+ get description(): string | undefined;
227
+ get longDescription(): string | undefined;
228
+ get options(): Option[] | undefined;
229
+ get positonals(): Argument[] | undefined;
230
+ get subCommands(): AnyCmd[] | undefined;
231
+ get handler(): ExecuteHandler<Opts, Flags, As> | undefined;
232
+ protected setLongDescription(longDescription: string): void;
233
+ /**
234
+ * Sets one or more aliases for this command.
235
+ *
236
+ * @param aliases Alternative names that should resolve to this command.
237
+ * @returns The same fluent command builder with the aliases applied.
238
+ */
239
+ aliases(...aliases: string[]): this;
240
+ /**
241
+ * Sets the short and long descriptions used in generated help output.
242
+ *
243
+ * @param description The one-line description shown in summaries.
244
+ * @param longDescription Additional help text shown in detailed command help.
245
+ * @returns The same fluent command builder with updated descriptions.
246
+ */
247
+ describe(description: string, longDescription?: string): this;
248
+ /**
249
+ * Adds a boolean flag to this command.
250
+ *
251
+ * @param name The CLI flag name without leading dashes.
252
+ * @param config Optional metadata such as aliases and descriptions.
253
+ * @returns A fluent command builder whose inferred option shape includes the new flag.
254
+ */
255
+ flag<const Name extends string, const Config extends FlagConfigInput | undefined = undefined>(name: Name, config?: Config): Command<Opts, [...Flags, BuildFlag<Name, Config>], As, Cs, Executable>;
256
+ /**
257
+ * Adds an option that accepts a value to this command.
258
+ *
259
+ * @param name The CLI option name without leading dashes.
260
+ * @param config Optional metadata such as aliases, descriptions, and coercion rules.
261
+ * @returns A fluent command builder whose inferred option shape includes the new option.
262
+ */
263
+ opt<const Name extends string, const Config extends OptionConfigInput | undefined = undefined>(name: Name, config?: Config): Command<[...Opts, BuildOption<Name, Config>], Flags, As, Cs, Executable>;
264
+ /**
265
+ * Adds a positional argument to this command.
266
+ *
267
+ * @param name The positional argument name used in help output and inferred opts.
268
+ * @param config Optional metadata such as coercion and requiredness.
269
+ * @returns A fluent command builder whose inferred positional tuple includes the new argument.
270
+ */
271
+ arg<const Name extends string, const Config extends ArgumentConfigInput | undefined = undefined>(name: Name, config?: Config): Command<Opts, Flags, [...As, BuildArgument<Name, Config>], Cs, Executable>;
272
+ /**
273
+ * Adds a nested sub-command to this command.
274
+ *
275
+ * @param subCommand The child command to register.
276
+ * @returns A fluent command builder that is now treated as a branch command.
277
+ */
278
+ command(this: Command<Opts, Flags, As, Cs, false>, subCommand: AnyCmd | Command<any, any, any, any, any>): Command<Opts, Flags, As, CommandChildren, false>;
279
+ /**
280
+ * Marks this command as executable and registers the handler invoked after parsing.
281
+ *
282
+ * @param handler The function that receives parsed positional arguments, parsed option values, and the current [`ExecutionContext`]{@link ExecutionContext}.
283
+ * @returns A fluent command builder that is now treated as executable.
284
+ */
285
+ run(this: Command<Opts, Flags, As, [], false>, handler: RunHandler<Opts, Flags, As>): Command<Opts, Flags, As, [], true>;
286
+ }
287
+ declare class App<Opts extends readonly Option[] = [], Flags extends readonly Flag[] = [], As extends readonly Argument[] = [], Cs extends CommandChildren = [], Executable extends boolean = false> extends Command<Opts, Flags, As, Cs, Executable> {
288
+ /** @internal */
289
+ _bin?: string;
290
+ /** @internal */
291
+ _version?: string;
292
+ /** @internal */
293
+ _author?: string;
294
+ /** @internal */
295
+ _globalOptions?: Option[];
296
+ /**
297
+ * Applies metadata to the root app in one call.
298
+ *
299
+ * @param config Metadata for the app, including version, author, argv0, and descriptions.
300
+ * @returns The same fluent app builder with the metadata applied.
301
+ */
302
+ meta(config: AppMetaConfig): this;
303
+ /**
304
+ * Sets the program name shown in help and generated messages.
305
+ *
306
+ * @param binaryName The display name for the CLI binary.
307
+ * @returns The same fluent app builder with the updated program name.
308
+ */
309
+ bin(binaryName: string): this;
310
+ /**
311
+ * Sets the application version surfaced by the built-in version command.
312
+ *
313
+ * @param version The version string to display.
314
+ * @returns The same fluent app builder with the version applied.
315
+ */
316
+ version(version: string): this;
317
+ /**
318
+ * Sets the application author surfaced by root help output.
319
+ *
320
+ * @param author The author string to display in app help.
321
+ * @returns The same fluent app builder with the author applied.
322
+ */
323
+ author(author: string): this;
324
+ /**
325
+ * Adds one or more aliases for the root command while preserving the `App` builder type.
326
+ *
327
+ * @param aliases Alternative names that should resolve to the root app.
328
+ * @returns The same fluent app builder with the aliases applied.
329
+ */
330
+ aliases(...aliases: string[]): this;
331
+ /**
332
+ * Sets the short and long descriptions used in generated help output while preserving the `App` builder type.
333
+ *
334
+ * @param description The one-line description shown in summaries.
335
+ * @param longDescription Additional help text shown in detailed help.
336
+ * @returns The same fluent app builder with updated descriptions.
337
+ */
338
+ describe(description: string, longDescription?: string): this;
339
+ /**
340
+ * Adds a boolean flag to the root app while preserving the `App` builder type.
341
+ *
342
+ * @param name The CLI flag name without leading dashes.
343
+ * @param config Optional metadata such as aliases and descriptions.
344
+ * @returns A fluent app builder whose inferred option shape includes the new flag.
345
+ */
346
+ flag<const Name extends string, const Config extends FlagConfigInput | undefined = undefined>(name: Name, config?: Config): App<Opts, [...Flags, BuildFlag<Name, Config>], As, Cs, Executable>;
347
+ /**
348
+ * Adds a valued option to the root app while preserving the `App` builder type.
349
+ *
350
+ * @param name The CLI option name without leading dashes.
351
+ * @param config Optional metadata such as aliases, descriptions, and coercion rules.
352
+ * @returns A fluent app builder whose inferred option shape includes the new option.
353
+ */
354
+ opt<const Name extends string, const Config extends OptionConfigInput | undefined = undefined>(name: Name, config?: Config): App<[...Opts, BuildOption<Name, Config>], Flags, As, Cs, Executable>;
355
+ /**
356
+ * Adds a valued option that is available to the root app and every sub-command.
357
+ *
358
+ * @param name The CLI option name without leading dashes.
359
+ * @param config Optional metadata such as aliases, descriptions, and coercion rules.
360
+ * @returns A fluent app builder whose global option shape includes the new option.
361
+ */
362
+ globalOpt<const Name extends string, const Config extends OptionConfigInput | undefined = undefined>(name: Name, config?: Config): this;
363
+ /**
364
+ * Adds a positional argument to the root app while preserving the `App` builder type.
365
+ *
366
+ * @param name The positional argument name used in help output and inferred opts.
367
+ * @param config Optional metadata such as coercion and requiredness.
368
+ * @returns A fluent app builder whose inferred positional tuple includes the new argument.
369
+ */
370
+ arg<const Name extends string, const Config extends ArgumentConfigInput | undefined = undefined>(name: Name, config?: Config): App<Opts, Flags, [...As, BuildArgument<Name, Config>], Cs, Executable>;
371
+ /**
372
+ * Adds a nested sub-command to the root app while preserving the `App` builder type.
373
+ *
374
+ * @param subCommand The child command to register.
375
+ * @returns A fluent app builder that is now treated as a branch app.
376
+ */
377
+ command(this: App<Opts, Flags, As, Cs, false>, subCommand: AnyCmd | Command<any, any, any, any, any>): App<Opts, Flags, As, CommandChildren, false>;
378
+ /**
379
+ * Marks the root app as executable by registering the handler invoked after parsing.
380
+ *
381
+ * @param handler The function that receives parsed positional arguments, parsed option values including custom global options, and the current [`ExecutionContext`]{@link ExecutionContext}.
382
+ * @returns A fluent app builder that is now treated as executable.
383
+ */
384
+ run(this: App<Opts, Flags, As, [], false>, handler: RunHandler<Opts, Flags, As>): App<Opts, Flags, As, [], true>;
385
+ /**
386
+ * Parses CLI arguments and executes the matching root command or sub-command.
387
+ *
388
+ * @param args The raw CLI arguments to parse. Defaults to `process.argv.slice(2)`.
389
+ * @returns The numeric exit code returned by the resolved command handler, or `0` when the handler does not return one.
390
+ */
391
+ execute(args?: string[]): Promise<number>;
392
+ }
393
+ //#endregion
394
+ export { type AnyOptType, App, type ArgsOf, type Argument, Command, ExecutionContext, type Flag, OptType, type Option, type OptionsOf, type OptsOf, type RunHandler };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { i as OptType, n as Command, r as ExecutionContext, t as App } from "./interfaces-COq24bNI.mjs";
2
+
3
+ export { App, Command, ExecutionContext, OptType };