@bemoje/cli 3.1.2 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -137
- package/lib/index.cjs +68 -67
- package/lib/index.d.cts +379 -379
- package/lib/index.d.ts +379 -379
- package/lib/index.js +68 -67
- package/package.json +14 -84
package/lib/index.d.ts
CHANGED
|
@@ -1947,83 +1947,13 @@ type CamelCase<Type, Options extends CamelCaseOptions = {}> = Type extends strin
|
|
|
1947
1947
|
>>
|
|
1948
1948
|
: Type;
|
|
1949
1949
|
|
|
1950
|
-
/**
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
error: (...args: unknown[]) => void;
|
|
1958
|
-
debug: (...args: unknown[]) => void;
|
|
1959
|
-
}
|
|
1960
|
-
/** Parsed command-line arguments */
|
|
1961
|
-
type Arguments = (undefined | string | string[])[];
|
|
1962
|
-
/** Parsed command-line options */
|
|
1963
|
-
type Options = Record<string, undefined | boolean | string | string[]>;
|
|
1964
|
-
/** Result of parsing command-line input, including arguments, options, triggered actions, and execution method */
|
|
1965
|
-
type SubCommands = {
|
|
1966
|
-
[name: string]: Command<Arguments, Options, any>;
|
|
1967
|
-
};
|
|
1968
|
-
/** Base descriptor for command-line arguments with shared properties */
|
|
1969
|
-
interface Argument {
|
|
1970
|
-
usage: string;
|
|
1971
|
-
name: string;
|
|
1972
|
-
description?: string;
|
|
1973
|
-
required?: boolean;
|
|
1974
|
-
variadic?: boolean;
|
|
1975
|
-
choices?: string[];
|
|
1976
|
-
defaultValue?: string | string[];
|
|
1977
|
-
defaultValueDescription?: string;
|
|
1978
|
-
}
|
|
1979
|
-
/** Base descriptor for command-line options with shared properties */
|
|
1980
|
-
interface Option {
|
|
1981
|
-
type: 'boolean' | 'string';
|
|
1982
|
-
flags: string;
|
|
1983
|
-
short: string;
|
|
1984
|
-
long: string;
|
|
1985
|
-
name: string;
|
|
1986
|
-
argName?: string;
|
|
1987
|
-
description?: string;
|
|
1988
|
-
required?: boolean;
|
|
1989
|
-
variadic?: boolean;
|
|
1990
|
-
negate?: boolean;
|
|
1991
|
-
defaultValue?: boolean | string | string[];
|
|
1992
|
-
defaultValueDescription?: string;
|
|
1993
|
-
env?: string;
|
|
1994
|
-
hidden?: boolean;
|
|
1995
|
-
choices?: string[];
|
|
1996
|
-
group?: string;
|
|
1997
|
-
}
|
|
1998
|
-
/** Complete command configuration including all properties and substructures */
|
|
1999
|
-
interface ICommand {
|
|
2000
|
-
/** Parent command if this is a subcommand */
|
|
2001
|
-
readonly parent?: ICommand;
|
|
2002
|
-
/** Help configuration and rendering */
|
|
2003
|
-
/** Command name used for invocation */
|
|
2004
|
-
name: string;
|
|
2005
|
-
/** Alternative names for this command */
|
|
2006
|
-
aliases: string[];
|
|
2007
|
-
/** Optional version string */
|
|
2008
|
-
version?: string;
|
|
2009
|
-
/** Full command description */
|
|
2010
|
-
description: string;
|
|
2011
|
-
/** Brief single-line description */
|
|
2012
|
-
summary?: string;
|
|
2013
|
-
/** Whether command should be hidden from help */
|
|
2014
|
-
hidden?: boolean;
|
|
2015
|
-
/** Group name for organizing commands in help */
|
|
2016
|
-
group?: string;
|
|
2017
|
-
/** Positional arguments */
|
|
2018
|
-
arguments: Argument[];
|
|
2019
|
-
/** Named options/flags */
|
|
2020
|
-
options: Option[];
|
|
2021
|
-
/** Child subcommands */
|
|
2022
|
-
commands: {
|
|
2023
|
-
[name: string]: ICommand;
|
|
2024
|
-
};
|
|
2025
|
-
}
|
|
2026
|
-
interface IHelp {
|
|
1950
|
+
/**
|
|
1951
|
+
* This is a fork of the Help class from the 'commander' npm package. The Help class method names as well as the
|
|
1952
|
+
* expected interface of the Command instance to parse, are both similar, but different and not compatible without
|
|
1953
|
+
* custom adaptations, @see ICommand
|
|
1954
|
+
*/
|
|
1955
|
+
declare class Help implements IHelp {
|
|
1956
|
+
protected readonly cmd: ICommand;
|
|
2027
1957
|
/** output helpWidth, long lines are wrapped to fit */
|
|
2028
1958
|
helpWidth: number;
|
|
2029
1959
|
minWidthToWrap: number;
|
|
@@ -2031,6 +1961,7 @@ interface IHelp {
|
|
|
2031
1961
|
sortOptions: boolean;
|
|
2032
1962
|
usageDisplayOptionsAs: string;
|
|
2033
1963
|
usageDisplaySubcommandAs: string;
|
|
1964
|
+
constructor(cmd: ICommand);
|
|
2034
1965
|
/**
|
|
2035
1966
|
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
2036
1967
|
*/
|
|
@@ -2190,179 +2121,233 @@ interface IHelp {
|
|
|
2190
2121
|
*/
|
|
2191
2122
|
render(): string;
|
|
2192
2123
|
}
|
|
2193
|
-
/** Action handler function type, which receives parsed arguments and options as well as metadata about the command execution context. */
|
|
2194
|
-
type ActionHandler<A extends Arguments, O extends Options, Subs extends SubCommands> = (...args: [
|
|
2195
|
-
...A,
|
|
2196
|
-
O,
|
|
2197
|
-
{
|
|
2198
|
-
path: string[];
|
|
2199
|
-
name: string;
|
|
2200
|
-
argv: string[];
|
|
2201
|
-
args: A;
|
|
2202
|
-
opts: O;
|
|
2203
|
-
errors?: string[];
|
|
2204
|
-
cmd: Command<A, O, Subs>;
|
|
2205
|
-
logger: Logger;
|
|
2206
|
-
}
|
|
2207
|
-
]) => Promise<void> | void;
|
|
2208
|
-
/** Predicate function type for hooks, which receives the same metadata as action handlers and returns a boolean indicating whether the hook's action should be executed. */
|
|
2209
|
-
type HookPredicate<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = (data: {
|
|
2210
|
-
path: string[];
|
|
2211
|
-
name: string;
|
|
2212
|
-
argv: string[];
|
|
2213
|
-
args: A;
|
|
2214
|
-
opts: O;
|
|
2215
|
-
errors?: string[];
|
|
2216
|
-
cmd: Command<A, O, Subs>;
|
|
2217
|
-
}) => boolean;
|
|
2218
|
-
/** Action handler function type for hooks, which receives the same metadata as action handlers and is executed when its predicate returns true. Can also throw to indicate an error. */
|
|
2219
|
-
type HookActionHandler<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = (data: {
|
|
2220
|
-
path: string[];
|
|
2221
|
-
name: string;
|
|
2222
|
-
argv: string[];
|
|
2223
|
-
args: A;
|
|
2224
|
-
opts: O;
|
|
2225
|
-
errors?: string[];
|
|
2226
|
-
cmd: Command<A, O, Subs>;
|
|
2227
|
-
}) => Promise<void> | void | never;
|
|
2228
|
-
/** Hook definition type, which includes the option name that triggers the hook, a predicate function to determine when the hook should run, and an action handler to execute when triggered. */
|
|
2229
|
-
type HookDefinition<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = {
|
|
2230
|
-
name: keyof O;
|
|
2231
|
-
predicate: HookPredicate<A, O, Subs>;
|
|
2232
|
-
action: HookActionHandler<A, O, Subs>;
|
|
2233
|
-
};
|
|
2234
|
-
/**
|
|
2235
|
-
* @see Command.prototype.parseArgv
|
|
2236
|
-
*/
|
|
2237
|
-
type ParseArgvResult<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = {
|
|
2238
|
-
/** The command or subcommand instance */
|
|
2239
|
-
get cmd(): Command<A, O, Subs>;
|
|
2240
|
-
/** The part of argv that makes out a subcommand path, or empty array when root command */
|
|
2241
|
-
path: string[];
|
|
2242
|
-
/** Command namer */
|
|
2243
|
-
name: string;
|
|
2244
|
-
/** Original argv array passed in or from process.argv, excluding subcommand path */
|
|
2245
|
-
argv: string[];
|
|
2246
|
-
/** Parsed arguments */
|
|
2247
|
-
args: A;
|
|
2248
|
-
/** Parsed options */
|
|
2249
|
-
opts: O;
|
|
2250
|
-
/** Error messages if parsing failed, otherwise undefined */
|
|
2251
|
-
errors?: string[];
|
|
2252
|
-
/** Names of all triggered hooks whose predicate returned true */
|
|
2253
|
-
hooks: HookDefinition<A, O, Subs>[];
|
|
2254
|
-
/** Calls the action handler with its expected args */
|
|
2255
|
-
execute: () => Promise<void>;
|
|
2256
|
-
};
|
|
2257
|
-
/** required variadic argument */
|
|
2258
|
-
type RequiredVariadicArgumentUsage = `<${string}...>`;
|
|
2259
|
-
/** optional variadic argument */
|
|
2260
|
-
type OptionalVariadicArgumentUsage = `[${string}...]`;
|
|
2261
|
-
/** required argument */
|
|
2262
|
-
type RequiredArgumentUsage = `<${string}>`;
|
|
2263
|
-
/** optional argument */
|
|
2264
|
-
type OptionalArgumentUsage = `[${string}]`;
|
|
2265
|
-
/** Union of all argument usage pattern types */
|
|
2266
|
-
type ArgumentUsage = RequiredVariadicArgumentUsage | OptionalVariadicArgumentUsage | RequiredArgumentUsage | OptionalArgumentUsage;
|
|
2267
|
-
/** Helper type to infer allowed argument usage patterns based on the command's existing argument types */
|
|
2268
|
-
type InferArgumentUsage<T extends Command<any, any, any>> = T extends Command<infer A, any> ? A extends string[] ? ArgumentUsage : A extends (string | (string | undefined))[] ? OptionalArgumentUsage | OptionalVariadicArgumentUsage : never : never;
|
|
2269
|
-
/** Helper type to infer allowed argument usage patterns based on the command's existing argument types */
|
|
2270
|
-
type AllowedArgumentUsage<T extends Command<any, any, any>, Usage extends ArgumentUsage> = Usage extends InferArgumentUsage<T> ? Usage : never;
|
|
2271
|
-
/** Base type for addArgument options, extended by specific required/optional and variadic/non-variadic argument option types */
|
|
2272
|
-
type ArgumentOptionsBase = Omit<Argument, 'name' | 'required' | 'variadic' | 'usage' | 'defaultValue' | 'defaultValueDescription'>;
|
|
2273
|
-
/** Base type for addArgument options, extended by specific required/optional and variadic/non-variadic argument option types */
|
|
2274
|
-
type ExtendArgumentOptionsBase<T extends object = object> = Simplify<ArgumentOptionsBase & T>;
|
|
2275
|
-
/** Required positional argument descriptor. Usage: `<name>` */
|
|
2276
|
-
type RequiredArgumentOptions = ExtendArgumentOptionsBase;
|
|
2277
|
-
/** Optional positional argument with string default. Usage: `[name]` */
|
|
2278
|
-
type OptionalArgumentOptions = ExtendArgumentOptionsBase<{
|
|
2279
|
-
defaultValue?: string;
|
|
2280
|
-
defaultValueDescription?: string;
|
|
2281
|
-
}>;
|
|
2282
|
-
/** Optional positional argument with required string default. Usage: `[name]` */
|
|
2283
|
-
type OptionalArgumentOptionsWithDefaultValue = SetFieldType<SetRequired<OptionalArgumentOptions, 'defaultValue'>, 'defaultValue', string>;
|
|
2284
|
-
/** Required variadic argument accepting variadic values. Usage: `<name...>` */
|
|
2285
|
-
type RequiredVariadicArgumentOptions = ExtendArgumentOptionsBase;
|
|
2286
|
-
/** Optional variadic argument with array default. Usage: `[name...]` */
|
|
2287
|
-
type OptionalVariadicArgumentOptions = ExtendArgumentOptionsBase<{
|
|
2288
|
-
defaultValue?: string[];
|
|
2289
|
-
defaultValueDescription?: string;
|
|
2290
|
-
}>;
|
|
2291
|
-
/** Union of all addArgument options types */
|
|
2292
|
-
type ArgumentOptions = AllUnionFields<RequiredArgumentOptions | OptionalArgumentOptions | OptionalArgumentOptionsWithDefaultValue | RequiredVariadicArgumentOptions | OptionalVariadicArgumentOptions>;
|
|
2293
|
-
/** Helper type for extracting argument name from usage pattern */
|
|
2294
|
-
type InferAddedArgumentType<Opts> = Opts extends {
|
|
2295
|
-
choices: infer C extends string[];
|
|
2296
|
-
} ? C[number] : string;
|
|
2297
|
-
/** Union of all option usage pattern types */
|
|
2298
|
-
type OptionUsage<Long extends string> = `-${string}, --${Long}` | `-${string}, --${Long} <${string}>` | `-${string}, --${Long} [${string}]` | `-${string}, --${Long} <${string}...>` | `-${string}, --${Long} [${string}...]`;
|
|
2299
|
-
/** Base type for addOption options, extended by specific boolean/string and required/optional and variadic/non-variadic option types */
|
|
2300
|
-
type OptionOptionsBase = Omit<Option, 'name' | 'required' | 'variadic' | 'type' | 'argName' | 'short' | 'long' | 'flags'>;
|
|
2301
|
-
/** Helper type to extend base addOption options with specific fields for different option types */
|
|
2302
|
-
type ExtendAddOptionOptionsBase<T extends object = object> = Simplify<OptionOptionsBase & T>;
|
|
2303
|
-
/** Boolean flag option. Usage: `-v, --verbose` */
|
|
2304
|
-
type BooleanOptionOptions = ExtendAddOptionOptionsBase<{
|
|
2305
|
-
defaultValue?: boolean;
|
|
2306
|
-
defaultValueDescription?: string;
|
|
2307
|
-
}>;
|
|
2308
|
-
/** Required string option. Usage: `-f, --file <path>` */
|
|
2309
|
-
type RequiredOptionOptions = ExtendAddOptionOptionsBase<{
|
|
2310
|
-
env?: undefined;
|
|
2311
|
-
}>;
|
|
2312
|
-
/** Optional string option with default. Usage: `-o, --output [path]` */
|
|
2313
|
-
type OptionalOptionOptions = ExtendAddOptionOptionsBase<{
|
|
2314
|
-
defaultValue?: string;
|
|
2315
|
-
defaultValueDescription?: string;
|
|
2316
|
-
}>;
|
|
2317
|
-
/** Required option accepting variadic values. Usage: `-i, --include <patterns...>` */
|
|
2318
|
-
type RequiredVariadicOptionOptions = ExtendAddOptionOptionsBase<{
|
|
2319
|
-
env?: undefined;
|
|
2320
|
-
}>;
|
|
2321
|
-
/** Optional option accepting variadic values with defaults. Usage: `-e, --exclude [patterns...]` */
|
|
2322
|
-
type OptionalVariadicOptionOptions = ExtendAddOptionOptionsBase<{
|
|
2323
|
-
defaultValue?: string[];
|
|
2324
|
-
defaultValueDescription?: string;
|
|
2325
|
-
}>;
|
|
2326
|
-
/** Union of all addOption options types */
|
|
2327
|
-
type OptionOptions = AllUnionFields<BooleanOptionOptions | RequiredOptionOptions | OptionalOptionOptions | RequiredVariadicOptionOptions | OptionalVariadicOptionOptions>;
|
|
2328
|
-
/** Helper type to infer the resulting Command type after adding an option with specific options */
|
|
2329
|
-
type InferAddOptionResult<A extends Arguments, O extends Options, NewOptions extends Options, Subs extends SubCommands> = Command<A, Simplify<O & NewOptions>, Subs>;
|
|
2330
2124
|
|
|
2331
2125
|
/**
|
|
2332
|
-
*
|
|
2333
|
-
* expected interface of the Command instance to parse, are both similar, but different and not compatible without
|
|
2334
|
-
* custom adaptations, @see ICommand
|
|
2126
|
+
* a type-safe CLI composer that can parse argv and generate help without execution coupling.
|
|
2335
2127
|
*/
|
|
2336
|
-
declare class
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
/**
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
/**
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
/**
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
/**
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
/**
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2128
|
+
declare class Command<A extends Arguments = [], O extends Options = {
|
|
2129
|
+
help?: boolean;
|
|
2130
|
+
debug?: boolean;
|
|
2131
|
+
}, Subs extends SubCommands = SubCommands> implements ICommand {
|
|
2132
|
+
/** parent command in the hierarchy, undefined for root command */
|
|
2133
|
+
parent?: Command<Arguments, Options & O>;
|
|
2134
|
+
/** the command name used to invoke it */
|
|
2135
|
+
name: string;
|
|
2136
|
+
/** semantic version string displayed by --version flag */
|
|
2137
|
+
version?: string;
|
|
2138
|
+
/** alternative names for invoking this command */
|
|
2139
|
+
aliases: string[];
|
|
2140
|
+
/** brief one-line description shown in command lists */
|
|
2141
|
+
summary?: string;
|
|
2142
|
+
/** full description displayed in help text */
|
|
2143
|
+
description: string;
|
|
2144
|
+
/** whether to exclude from help listings */
|
|
2145
|
+
hidden?: boolean;
|
|
2146
|
+
/** category for organizing related commands in help output */
|
|
2147
|
+
group?: string;
|
|
2148
|
+
/** positional arguments this command accepts */
|
|
2149
|
+
arguments: Argument[];
|
|
2150
|
+
/** cLI options (flags) this command recognizes */
|
|
2151
|
+
options: Option[];
|
|
2152
|
+
/** subcommands registered with this command */
|
|
2153
|
+
commands: Subs;
|
|
2154
|
+
/** main action handler executed when command is invoked */
|
|
2155
|
+
protected action?: ActionHandler<A, O, Subs>;
|
|
2156
|
+
/** option-driven actions (e.g., --help, --version) executed when their conditions match */
|
|
2157
|
+
protected hooks: HookDefinition<Arguments, Options & O>[];
|
|
2158
|
+
constructor(name: string, parent?: ICommand);
|
|
2159
|
+
protected get help(): Help;
|
|
2160
|
+
/** configure how the help is rendered */
|
|
2161
|
+
helpConfiguration(cb?: (help: Help) => void): this;
|
|
2162
|
+
/** renders formatted help text using provided help definition */
|
|
2163
|
+
renderHelp(config?: {
|
|
2164
|
+
noColor?: boolean;
|
|
2165
|
+
}): string;
|
|
2166
|
+
/** sets the command name */
|
|
2167
|
+
setName(name: string): void;
|
|
2168
|
+
/** sets command aliases, flattening nested arrays */
|
|
2169
|
+
setAliases(...aliases: (string | string[])[]): this;
|
|
2170
|
+
/** adds aliases to existing ones */
|
|
2171
|
+
addAliases(...aliases: (string | string[])[]): this;
|
|
2172
|
+
/** sets the command version */
|
|
2173
|
+
setVersion(version: string): InferAddOptionResult<A, O, {
|
|
2174
|
+
version?: boolean;
|
|
2175
|
+
}, Subs>;
|
|
2176
|
+
/** sets the command summary */
|
|
2177
|
+
setSummary(summary?: string): this;
|
|
2178
|
+
/** sets command description, joining variadic lines */
|
|
2179
|
+
setDescription(...lines: string[]): this;
|
|
2180
|
+
/** sets whether command is hidden from help */
|
|
2181
|
+
setHidden(hidden?: boolean | undefined): this;
|
|
2182
|
+
/** sets the command group for help organization */
|
|
2183
|
+
setGroup(group?: string): this;
|
|
2184
|
+
/** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
2185
|
+
command<Name extends string, Sub extends Command<any, any, any> = Command<[], O, {}>>(name: Name, cb?: (cmd: Command<[], O, {}>, parent: this) => Sub): Sub;
|
|
2186
|
+
/** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
2187
|
+
addCommand<Name extends string, Sub extends Command<any, any, any> = Command<[], O, {}>>(name: Name, cb: (cmd: Command<[], O, {}>, parent: this) => Sub): Command<A, O, (SubCommands extends Subs ? {} : Subs) & {
|
|
2188
|
+
[K in Name]: Sub;
|
|
2189
|
+
}>;
|
|
2190
|
+
/** add required variadic argument, eg.: `<name...>` */
|
|
2191
|
+
addArgument<const Opts extends RequiredVariadicArgumentOptions>(usage: AllowedArgumentUsage<this, `<${string}...>`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
|
|
2192
|
+
/** add required argument, eg.: `<name>` */
|
|
2193
|
+
addArgument<const Opts extends RequiredArgumentOptions>(usage: AllowedArgumentUsage<this, `<${string}>`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
|
|
2194
|
+
/** add optional variadic argument with defaults, eg.: `[name...]` */
|
|
2195
|
+
addArgument<const Opts extends OptionalVariadicArgumentOptions>(usage: AllowedArgumentUsage<this, `[${string}...]`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
|
|
2196
|
+
/** add optional argument with default, eg.: `[name]` */
|
|
2197
|
+
addArgument<const Opts extends OptionalArgumentOptionsWithDefaultValue>(usage: AllowedArgumentUsage<this, `[${string}]`>, options: Opts): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
|
|
2198
|
+
/** add optional argument, eg.: `[name]` */
|
|
2199
|
+
addArgument<const Opts extends OptionalArgumentOptions>(usage: AllowedArgumentUsage<this, `[${string}]`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts> | undefined], O, Subs>;
|
|
2200
|
+
/** add optional string option, eg.: `-o, --output [path]` */
|
|
2201
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}]`, options?: SetFieldType<OptionalOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
|
|
2202
|
+
[K in CamelCase<Long>]?: string;
|
|
2203
|
+
} & O>, Subs>;
|
|
2204
|
+
/** add optional string option with default, eg.: `-o, --output [path]` */
|
|
2205
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}]`, options: SetFieldType<SetRequired<OptionalOptionOptions, 'defaultValue'>, 'defaultValue', string>): Command<A, Simplify<{
|
|
2206
|
+
[K in CamelCase<Long>]: string;
|
|
2207
|
+
} & O>, Subs>;
|
|
2208
|
+
/** add required variadic option, eg.: `-i, --include <patterns...>` */
|
|
2209
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} <${string}...>`, options?: RequiredVariadicOptionOptions): Command<A, Simplify<{
|
|
2210
|
+
[K in CamelCase<Long>]: string[];
|
|
2211
|
+
} & O>, Subs>;
|
|
2212
|
+
/** add optional variadic option with defaults, eg.: `-e, --exclude [patterns...]` */
|
|
2213
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}...]`, options?: OptionalVariadicOptionOptions): Command<A, Simplify<{
|
|
2214
|
+
[K in CamelCase<Long>]: string[];
|
|
2215
|
+
} & O>, Subs>;
|
|
2216
|
+
/** add required string option, eg.: `-f, --file <path>` */
|
|
2217
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} <${string}>`, options?: RequiredOptionOptions): Command<A, Simplify<{
|
|
2218
|
+
[K in CamelCase<Long>]: string;
|
|
2219
|
+
} & O>, Subs>;
|
|
2220
|
+
/** add boolean flag option with default, eg.: `-v, --verbose` */
|
|
2221
|
+
addOption<Long extends string>(flags: `-${string}, --${Long}`, options: SetFieldType<SetRequired<BooleanOptionOptions, 'defaultValue'>, 'defaultValue', boolean>): Command<A, Simplify<{
|
|
2222
|
+
[K in CamelCase<Long>]: boolean;
|
|
2223
|
+
} & O>, Subs>;
|
|
2224
|
+
/** add boolean flag option, eg.: `-v, --verbose` */
|
|
2225
|
+
addOption<Long extends string>(flags: `-${string}, --${Long}`, options?: SetFieldType<BooleanOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
|
|
2226
|
+
[K in CamelCase<Long>]?: boolean;
|
|
2227
|
+
} & O>, Subs>;
|
|
2228
|
+
/**
|
|
2229
|
+
* register an action to be invoked when an option is set to true or string value.
|
|
2230
|
+
*
|
|
2231
|
+
* Hooks execute in addition to or instead of the main action handler,
|
|
2232
|
+
* allowing for option-driven behavior. For example, `--help` and `--version`
|
|
2233
|
+
* are implemented as hooks.
|
|
2234
|
+
*/
|
|
2235
|
+
addOptionHook(optionName: keyof O, action: HookActionHandler<Arguments, O>): this;
|
|
2236
|
+
/** parses command-line arguments with subcommand support and type-safe validation. */
|
|
2237
|
+
parseArgv(argv?: string[]): ParseArgvResult<Arguments, Options & O>;
|
|
2238
|
+
/**
|
|
2239
|
+
* sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
|
|
2240
|
+
* The handler receives parsed arguments and options with correct typings.
|
|
2241
|
+
*/
|
|
2242
|
+
setAction(fn: ActionHandler<A, O, Subs>): this;
|
|
2243
|
+
/** returns a new Command instance. Override this method in subclasses. */
|
|
2244
|
+
protected createSubcommand(name: string): Command<[], O, {}>;
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
/** Logger interface defining methods for different log levels. */
|
|
2248
|
+
interface Logger {
|
|
2249
|
+
start: (...args: unknown[]) => void;
|
|
2250
|
+
done: (...args: unknown[]) => void;
|
|
2251
|
+
info: (...args: unknown[]) => void;
|
|
2252
|
+
log: (...args: unknown[]) => void;
|
|
2253
|
+
warn: (...args: unknown[]) => void;
|
|
2254
|
+
error: (...args: unknown[]) => void;
|
|
2255
|
+
debug: (...args: unknown[]) => void;
|
|
2256
|
+
}
|
|
2257
|
+
/** Parsed command-line arguments */
|
|
2258
|
+
type Arguments = (undefined | string | string[])[];
|
|
2259
|
+
/** Parsed command-line options */
|
|
2260
|
+
type Options = Record<string, undefined | boolean | string | string[]>;
|
|
2261
|
+
/** Result of parsing command-line input, including arguments, options, triggered actions, and execution method */
|
|
2262
|
+
type SubCommands = {
|
|
2263
|
+
[name: string]: Command<Arguments, Options, any>;
|
|
2264
|
+
};
|
|
2265
|
+
/** Base descriptor for command-line arguments with shared properties */
|
|
2266
|
+
interface Argument {
|
|
2267
|
+
usage: string;
|
|
2268
|
+
name: string;
|
|
2269
|
+
description?: string;
|
|
2270
|
+
required?: boolean;
|
|
2271
|
+
variadic?: boolean;
|
|
2272
|
+
choices?: string[];
|
|
2273
|
+
defaultValue?: string | string[];
|
|
2274
|
+
defaultValueDescription?: string;
|
|
2275
|
+
}
|
|
2276
|
+
/** Base descriptor for command-line options with shared properties */
|
|
2277
|
+
interface Option {
|
|
2278
|
+
type: 'boolean' | 'string';
|
|
2279
|
+
flags: string;
|
|
2280
|
+
short: string;
|
|
2281
|
+
long: string;
|
|
2282
|
+
name: string;
|
|
2283
|
+
argName?: string;
|
|
2284
|
+
description?: string;
|
|
2285
|
+
required?: boolean;
|
|
2286
|
+
variadic?: boolean;
|
|
2287
|
+
negate?: boolean;
|
|
2288
|
+
defaultValue?: boolean | string | string[];
|
|
2289
|
+
defaultValueDescription?: string;
|
|
2290
|
+
env?: string;
|
|
2291
|
+
hidden?: boolean;
|
|
2292
|
+
choices?: string[];
|
|
2293
|
+
group?: string;
|
|
2294
|
+
}
|
|
2295
|
+
/** Complete command configuration including all properties and substructures */
|
|
2296
|
+
interface ICommand {
|
|
2297
|
+
/** Parent command if this is a subcommand */
|
|
2298
|
+
readonly parent?: ICommand;
|
|
2299
|
+
/** Help configuration and rendering */
|
|
2300
|
+
/** Command name used for invocation */
|
|
2301
|
+
name: string;
|
|
2302
|
+
/** Alternative names for this command */
|
|
2303
|
+
aliases: string[];
|
|
2304
|
+
/** Optional version string */
|
|
2305
|
+
version?: string;
|
|
2306
|
+
/** Full command description */
|
|
2307
|
+
description: string;
|
|
2308
|
+
/** Brief single-line description */
|
|
2309
|
+
summary?: string;
|
|
2310
|
+
/** Whether command should be hidden from help */
|
|
2311
|
+
hidden?: boolean;
|
|
2312
|
+
/** Group name for organizing commands in help */
|
|
2313
|
+
group?: string;
|
|
2314
|
+
/** Positional arguments */
|
|
2315
|
+
arguments: Argument[];
|
|
2316
|
+
/** Named options/flags */
|
|
2317
|
+
options: Option[];
|
|
2318
|
+
/** Child subcommands */
|
|
2319
|
+
commands: {
|
|
2320
|
+
[name: string]: ICommand;
|
|
2321
|
+
};
|
|
2322
|
+
}
|
|
2323
|
+
interface IHelp {
|
|
2324
|
+
/** output helpWidth, long lines are wrapped to fit */
|
|
2325
|
+
helpWidth: number;
|
|
2326
|
+
minWidthToWrap: number;
|
|
2327
|
+
sortSubcommands: boolean;
|
|
2328
|
+
sortOptions: boolean;
|
|
2329
|
+
usageDisplayOptionsAs: string;
|
|
2330
|
+
usageDisplaySubcommandAs: string;
|
|
2331
|
+
/**
|
|
2332
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
2333
|
+
*/
|
|
2334
|
+
visibleCommands(): ICommand[];
|
|
2335
|
+
/**
|
|
2336
|
+
* Compare options for sort.
|
|
2337
|
+
*/
|
|
2338
|
+
compareOptions(a: Option, b: Option): number;
|
|
2339
|
+
/**
|
|
2340
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
2341
|
+
*/
|
|
2342
|
+
visibleOptions(): Option[];
|
|
2343
|
+
/**
|
|
2344
|
+
* Get an array of the arguments if any have a description.
|
|
2345
|
+
*/
|
|
2346
|
+
visibleArguments(): Argument[];
|
|
2347
|
+
/**
|
|
2348
|
+
* Get the command term to show in the list of subcommands.
|
|
2349
|
+
*/
|
|
2350
|
+
subcommandTerm(sub: ICommand): string;
|
|
2366
2351
|
/**
|
|
2367
2352
|
* Get the option term to show in the list of options.
|
|
2368
2353
|
*/
|
|
@@ -2502,138 +2487,158 @@ declare class Help implements IHelp {
|
|
|
2502
2487
|
*/
|
|
2503
2488
|
render(): string;
|
|
2504
2489
|
}
|
|
2505
|
-
|
|
2490
|
+
/** Action handler function type, which receives parsed arguments and options as well as metadata about the command execution context. */
|
|
2491
|
+
type ActionHandler<A extends Arguments, O extends Options, Subs extends SubCommands> = (...args: [
|
|
2492
|
+
...A,
|
|
2493
|
+
O,
|
|
2494
|
+
{
|
|
2495
|
+
path: string[];
|
|
2496
|
+
name: string;
|
|
2497
|
+
argv: string[];
|
|
2498
|
+
args: A;
|
|
2499
|
+
opts: O;
|
|
2500
|
+
errors?: string[];
|
|
2501
|
+
cmd: Command<A, O, Subs>;
|
|
2502
|
+
logger: Logger;
|
|
2503
|
+
}
|
|
2504
|
+
]) => Promise<void> | void;
|
|
2505
|
+
/** Predicate function type for hooks, which receives the same metadata as action handlers and returns a boolean indicating whether the hook's action should be executed. */
|
|
2506
|
+
type HookPredicate<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = (data: {
|
|
2507
|
+
path: string[];
|
|
2508
|
+
name: string;
|
|
2509
|
+
argv: string[];
|
|
2510
|
+
args: A;
|
|
2511
|
+
opts: O;
|
|
2512
|
+
errors?: string[];
|
|
2513
|
+
cmd: Command<A, O, Subs>;
|
|
2514
|
+
}) => boolean;
|
|
2515
|
+
/** Action handler function type for hooks, which receives the same metadata as action handlers and is executed when its predicate returns true. Can also throw to indicate an error. */
|
|
2516
|
+
type HookActionHandler<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = (data: {
|
|
2517
|
+
path: string[];
|
|
2518
|
+
name: string;
|
|
2519
|
+
argv: string[];
|
|
2520
|
+
args: A;
|
|
2521
|
+
opts: O;
|
|
2522
|
+
errors?: string[];
|
|
2523
|
+
cmd: Command<A, O, Subs>;
|
|
2524
|
+
}) => Promise<void> | void | never;
|
|
2525
|
+
/** Hook definition type, which includes the option name that triggers the hook, a predicate function to determine when the hook should run, and an action handler to execute when triggered. */
|
|
2526
|
+
type HookDefinition<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = {
|
|
2527
|
+
name: keyof O;
|
|
2528
|
+
predicate: HookPredicate<A, O, Subs>;
|
|
2529
|
+
action: HookActionHandler<A, O, Subs>;
|
|
2530
|
+
};
|
|
2506
2531
|
/**
|
|
2507
|
-
*
|
|
2532
|
+
* @see Command.prototype.parseArgv
|
|
2508
2533
|
*/
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
/** the command name used to invoke it */
|
|
2534
|
+
type ParseArgvResult<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = {
|
|
2535
|
+
/** The command or subcommand instance */
|
|
2536
|
+
get cmd(): Command<A, O, Subs>;
|
|
2537
|
+
/** The part of argv that makes out a subcommand path, or empty array when root command */
|
|
2538
|
+
path: string[];
|
|
2539
|
+
/** Command namer */
|
|
2516
2540
|
name: string;
|
|
2517
|
-
/**
|
|
2518
|
-
|
|
2519
|
-
/**
|
|
2520
|
-
|
|
2521
|
-
/**
|
|
2522
|
-
|
|
2523
|
-
/**
|
|
2524
|
-
|
|
2525
|
-
/**
|
|
2526
|
-
|
|
2527
|
-
/**
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
[K in CamelCase<Long>]: boolean;
|
|
2604
|
-
} & O>, Subs>;
|
|
2605
|
-
/** add boolean flag option, eg.: `-v, --verbose` */
|
|
2606
|
-
addOption<Long extends string>(flags: `-${string}, --${Long}`, options?: SetFieldType<BooleanOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
|
|
2607
|
-
[K in CamelCase<Long>]?: boolean;
|
|
2608
|
-
} & O>, Subs>;
|
|
2609
|
-
/**
|
|
2610
|
-
* register an action to be invoked when an option is set to true or string value.
|
|
2611
|
-
*
|
|
2612
|
-
* Hooks execute in addition to or instead of the main action handler,
|
|
2613
|
-
* allowing for option-driven behavior. For example, `--help` and `--version`
|
|
2614
|
-
* are implemented as hooks.
|
|
2615
|
-
*/
|
|
2616
|
-
addOptionHook(optionName: keyof O, action: HookActionHandler<Arguments, O>): this;
|
|
2617
|
-
/** parses command-line arguments with subcommand support and type-safe validation. */
|
|
2618
|
-
parseArgv(argv?: string[]): ParseArgvResult<Arguments, Options & O>;
|
|
2619
|
-
/**
|
|
2620
|
-
* sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
|
|
2621
|
-
* The handler receives parsed arguments and options with correct typings.
|
|
2622
|
-
*/
|
|
2623
|
-
setAction(fn: ActionHandler<A, O, Subs>): this;
|
|
2624
|
-
/** returns a new Command instance. Override this method in subclasses. */
|
|
2625
|
-
protected createSubcommand(name: string): Command<[], O, {}>;
|
|
2626
|
-
}
|
|
2541
|
+
/** Original argv array passed in or from process.argv, excluding subcommand path */
|
|
2542
|
+
argv: string[];
|
|
2543
|
+
/** Parsed arguments */
|
|
2544
|
+
args: A;
|
|
2545
|
+
/** Parsed options */
|
|
2546
|
+
opts: O;
|
|
2547
|
+
/** Error messages if parsing failed, otherwise undefined */
|
|
2548
|
+
errors?: string[];
|
|
2549
|
+
/** Names of all triggered hooks whose predicate returned true */
|
|
2550
|
+
hooks: HookDefinition<A, O, Subs>[];
|
|
2551
|
+
/** Calls the action handler with its expected args */
|
|
2552
|
+
execute: () => Promise<void>;
|
|
2553
|
+
};
|
|
2554
|
+
/** required variadic argument */
|
|
2555
|
+
type RequiredVariadicArgumentUsage = `<${string}...>`;
|
|
2556
|
+
/** optional variadic argument */
|
|
2557
|
+
type OptionalVariadicArgumentUsage = `[${string}...]`;
|
|
2558
|
+
/** required argument */
|
|
2559
|
+
type RequiredArgumentUsage = `<${string}>`;
|
|
2560
|
+
/** optional argument */
|
|
2561
|
+
type OptionalArgumentUsage = `[${string}]`;
|
|
2562
|
+
/** Union of all argument usage pattern types */
|
|
2563
|
+
type ArgumentUsage = RequiredVariadicArgumentUsage | OptionalVariadicArgumentUsage | RequiredArgumentUsage | OptionalArgumentUsage;
|
|
2564
|
+
/** Helper type to infer allowed argument usage patterns based on the command's existing argument types */
|
|
2565
|
+
type InferArgumentUsage<T extends Command<any, any, any>> = T extends Command<infer A, any> ? A extends string[] ? ArgumentUsage : A extends (string | (string | undefined))[] ? OptionalArgumentUsage | OptionalVariadicArgumentUsage : never : never;
|
|
2566
|
+
/** Helper type to infer allowed argument usage patterns based on the command's existing argument types */
|
|
2567
|
+
type AllowedArgumentUsage<T extends Command<any, any, any>, Usage extends ArgumentUsage> = Usage extends InferArgumentUsage<T> ? Usage : never;
|
|
2568
|
+
/** Base type for addArgument options, extended by specific required/optional and variadic/non-variadic argument option types */
|
|
2569
|
+
type ArgumentOptionsBase = Omit<Argument, 'name' | 'required' | 'variadic' | 'usage' | 'defaultValue' | 'defaultValueDescription'>;
|
|
2570
|
+
/** Base type for addArgument options, extended by specific required/optional and variadic/non-variadic argument option types */
|
|
2571
|
+
type ExtendArgumentOptionsBase<T extends object = object> = Simplify<ArgumentOptionsBase & T>;
|
|
2572
|
+
/** Required positional argument descriptor. Usage: `<name>` */
|
|
2573
|
+
type RequiredArgumentOptions = ExtendArgumentOptionsBase;
|
|
2574
|
+
/** Optional positional argument with string default. Usage: `[name]` */
|
|
2575
|
+
type OptionalArgumentOptions = ExtendArgumentOptionsBase<{
|
|
2576
|
+
defaultValue?: string;
|
|
2577
|
+
defaultValueDescription?: string;
|
|
2578
|
+
}>;
|
|
2579
|
+
/** Optional positional argument with required string default. Usage: `[name]` */
|
|
2580
|
+
type OptionalArgumentOptionsWithDefaultValue = SetFieldType<SetRequired<OptionalArgumentOptions, 'defaultValue'>, 'defaultValue', string>;
|
|
2581
|
+
/** Required variadic argument accepting variadic values. Usage: `<name...>` */
|
|
2582
|
+
type RequiredVariadicArgumentOptions = ExtendArgumentOptionsBase;
|
|
2583
|
+
/** Optional variadic argument with array default. Usage: `[name...]` */
|
|
2584
|
+
type OptionalVariadicArgumentOptions = ExtendArgumentOptionsBase<{
|
|
2585
|
+
defaultValue?: string[];
|
|
2586
|
+
defaultValueDescription?: string;
|
|
2587
|
+
}>;
|
|
2588
|
+
/** Union of all addArgument options types */
|
|
2589
|
+
type ArgumentOptions = AllUnionFields<RequiredArgumentOptions | OptionalArgumentOptions | OptionalArgumentOptionsWithDefaultValue | RequiredVariadicArgumentOptions | OptionalVariadicArgumentOptions>;
|
|
2590
|
+
/** Helper type for extracting argument name from usage pattern */
|
|
2591
|
+
type InferAddedArgumentType<Opts> = Opts extends {
|
|
2592
|
+
choices: infer C extends string[];
|
|
2593
|
+
} ? C[number] : string;
|
|
2594
|
+
/** Union of all option usage pattern types */
|
|
2595
|
+
type OptionUsage<Long extends string> = `-${string}, --${Long}` | `-${string}, --${Long} <${string}>` | `-${string}, --${Long} [${string}]` | `-${string}, --${Long} <${string}...>` | `-${string}, --${Long} [${string}...]`;
|
|
2596
|
+
/** Base type for addOption options, extended by specific boolean/string and required/optional and variadic/non-variadic option types */
|
|
2597
|
+
type OptionOptionsBase = Omit<Option, 'name' | 'required' | 'variadic' | 'type' | 'argName' | 'short' | 'long' | 'flags'>;
|
|
2598
|
+
/** Helper type to extend base addOption options with specific fields for different option types */
|
|
2599
|
+
type ExtendAddOptionOptionsBase<T extends object = object> = Simplify<OptionOptionsBase & T>;
|
|
2600
|
+
/** Boolean flag option. Usage: `-v, --verbose` */
|
|
2601
|
+
type BooleanOptionOptions = ExtendAddOptionOptionsBase<{
|
|
2602
|
+
defaultValue?: boolean;
|
|
2603
|
+
defaultValueDescription?: string;
|
|
2604
|
+
}>;
|
|
2605
|
+
/** Required string option. Usage: `-f, --file <path>` */
|
|
2606
|
+
type RequiredOptionOptions = ExtendAddOptionOptionsBase<{
|
|
2607
|
+
env?: undefined;
|
|
2608
|
+
}>;
|
|
2609
|
+
/** Optional string option with default. Usage: `-o, --output [path]` */
|
|
2610
|
+
type OptionalOptionOptions = ExtendAddOptionOptionsBase<{
|
|
2611
|
+
defaultValue?: string;
|
|
2612
|
+
defaultValueDescription?: string;
|
|
2613
|
+
}>;
|
|
2614
|
+
/** Required option accepting variadic values. Usage: `-i, --include <patterns...>` */
|
|
2615
|
+
type RequiredVariadicOptionOptions = ExtendAddOptionOptionsBase<{
|
|
2616
|
+
env?: undefined;
|
|
2617
|
+
}>;
|
|
2618
|
+
/** Optional option accepting variadic values with defaults. Usage: `-e, --exclude [patterns...]` */
|
|
2619
|
+
type OptionalVariadicOptionOptions = ExtendAddOptionOptionsBase<{
|
|
2620
|
+
defaultValue?: string[];
|
|
2621
|
+
defaultValueDescription?: string;
|
|
2622
|
+
}>;
|
|
2623
|
+
/** Union of all addOption options types */
|
|
2624
|
+
type OptionOptions = AllUnionFields<BooleanOptionOptions | RequiredOptionOptions | OptionalOptionOptions | RequiredVariadicOptionOptions | OptionalVariadicOptionOptions>;
|
|
2625
|
+
/** Helper type to infer the resulting Command type after adding an option with specific options */
|
|
2626
|
+
type InferAddOptionResult<A extends Arguments, O extends Options, NewOptions extends Options, Subs extends SubCommands> = Command<A, Simplify<O & NewOptions>, Subs>;
|
|
2627
2627
|
|
|
2628
2628
|
/**
|
|
2629
|
-
*
|
|
2629
|
+
* Parses option flags string into its components
|
|
2630
2630
|
*/
|
|
2631
|
-
declare function
|
|
2631
|
+
declare function parseOptionFlags<Long extends string>(flags: OptionUsage<Long>): {
|
|
2632
|
+
short: string;
|
|
2633
|
+
long: Long;
|
|
2634
|
+
name: CamelCase<Long>;
|
|
2635
|
+
argName: string | undefined;
|
|
2636
|
+
};
|
|
2632
2637
|
|
|
2633
2638
|
/**
|
|
2634
|
-
*
|
|
2639
|
+
* Returns command and all ancestor commands in hierarchy
|
|
2635
2640
|
*/
|
|
2636
|
-
declare function
|
|
2641
|
+
declare function getCommandAndAncestors<C extends ICommand>(cmd: C): [typeof cmd, ...ICommand[]];
|
|
2637
2642
|
|
|
2638
2643
|
/**
|
|
2639
2644
|
* Returns all ancestor commands excluding this command
|
|
@@ -2641,18 +2646,13 @@ declare function findOption<C extends ICommand>(cmd: C, nameOrShortOrLong: strin
|
|
|
2641
2646
|
declare function getCommandAncestors<C extends ICommand>(cmd: C): C[];
|
|
2642
2647
|
|
|
2643
2648
|
/**
|
|
2644
|
-
*
|
|
2649
|
+
* Finds option by name, short name or long name
|
|
2645
2650
|
*/
|
|
2646
|
-
declare function
|
|
2651
|
+
declare function findOption<C extends ICommand>(cmd: C, nameOrShortOrLong: string): Option | undefined;
|
|
2647
2652
|
|
|
2648
2653
|
/**
|
|
2649
|
-
*
|
|
2654
|
+
* Finds subcommand by name or alias
|
|
2650
2655
|
*/
|
|
2651
|
-
declare function
|
|
2652
|
-
short: string;
|
|
2653
|
-
long: Long;
|
|
2654
|
-
name: CamelCase<Long>;
|
|
2655
|
-
argName: string | undefined;
|
|
2656
|
-
};
|
|
2656
|
+
declare function findCommand<C extends Command = Command>(cmd: ICommand, nameOrAlias: string): C | undefined;
|
|
2657
2657
|
|
|
2658
2658
|
export { type ActionHandler, type AllowedArgumentUsage, type Argument, type ArgumentOptions, type ArgumentUsage, type Arguments, type BooleanOptionOptions, Command, Help, type HookActionHandler, type HookDefinition, type HookPredicate, type ICommand, type IHelp, type InferAddOptionResult, type InferAddedArgumentType, type Logger, type Option, type OptionOptions, type OptionUsage, type OptionalArgumentOptions, type OptionalArgumentOptionsWithDefaultValue, type OptionalArgumentUsage, type OptionalOptionOptions, type OptionalVariadicArgumentOptions, type OptionalVariadicArgumentUsage, type OptionalVariadicOptionOptions, type Options, type ParseArgvResult, type RequiredArgumentOptions, type RequiredArgumentUsage, type RequiredOptionOptions, type RequiredVariadicArgumentOptions, type RequiredVariadicArgumentUsage, type RequiredVariadicOptionOptions, type SubCommands, findCommand, findOption, getCommandAncestors, getCommandAndAncestors, parseOptionFlags };
|