@bemoje/cli 2.1.3 → 2.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/index.d.ts +926 -28
- package/index.mjs +586 -386
- package/package.json +1 -1
- package/lib/Command.d.ts +0 -149
- package/lib/Help.d.ts +0 -178
- package/lib/helpers/findCommand.d.ts +0 -6
- package/lib/helpers/findOption.d.ts +0 -6
- package/lib/helpers/getCommandAncestors.d.ts +0 -5
- package/lib/helpers/getCommandAndAncestors.d.ts +0 -5
- package/lib/helpers/parseOptionFlags.d.ts +0 -11
- package/lib/internal/collectVariadicOptionValues.d.ts +0 -7
- package/lib/internal/mergeOptionDefaults.d.ts +0 -3
- package/lib/internal/normalizeArgv.d.ts +0 -3
- package/lib/internal/resolveArguments.d.ts +0 -3
- package/lib/internal/validateParsed.d.ts +0 -4
- package/lib/types.d.ts +0 -386
package/package.json
CHANGED
package/lib/Command.d.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import type { ActionHandler } from './types';
|
|
2
|
-
import type { AllowedArgumentUsage } from './types';
|
|
3
|
-
import type { Argument } from './types';
|
|
4
|
-
import type { Arguments } from './types';
|
|
5
|
-
import type { BooleanOptionOptions } from './types';
|
|
6
|
-
import type { CamelCase } from 'type-fest';
|
|
7
|
-
import { Help } from './Help';
|
|
8
|
-
import type { HookActionHandler } from './types';
|
|
9
|
-
import type { HookDefinition } from './types';
|
|
10
|
-
import type { ICommand } from './types';
|
|
11
|
-
import type { InferAddOptionResult } from './types';
|
|
12
|
-
import type { InferAddedArgumentType } from './types';
|
|
13
|
-
import type { Option } from './types';
|
|
14
|
-
import type { OptionalArgumentOptions } from './types';
|
|
15
|
-
import type { OptionalArgumentOptionsWithDefaultValue } from './types';
|
|
16
|
-
import type { OptionalOptionOptions } from './types';
|
|
17
|
-
import type { OptionalVariadicArgumentOptions } from './types';
|
|
18
|
-
import type { OptionalVariadicOptionOptions } from './types';
|
|
19
|
-
import type { Options } from './types';
|
|
20
|
-
import type { ParseArgvResult } from './types';
|
|
21
|
-
import type { RequiredArgumentOptions } from './types';
|
|
22
|
-
import type { RequiredOptionOptions } from './types';
|
|
23
|
-
import type { RequiredVariadicArgumentOptions } from './types';
|
|
24
|
-
import type { RequiredVariadicOptionOptions } from './types';
|
|
25
|
-
import type { SetFieldType } from 'type-fest';
|
|
26
|
-
import type { SetRequired } from 'type-fest';
|
|
27
|
-
import type { Simplify } from 'type-fest';
|
|
28
|
-
import type { SubCommands } from './types';
|
|
29
|
-
/**
|
|
30
|
-
* a type-safe CLI composer that can parse argv and generate help without execution coupling.
|
|
31
|
-
*/
|
|
32
|
-
export declare class Command<A extends Arguments = [], O extends Options = {
|
|
33
|
-
help?: boolean;
|
|
34
|
-
debug?: boolean;
|
|
35
|
-
}, Subs extends SubCommands = SubCommands> implements ICommand {
|
|
36
|
-
/** parent command in the hierarchy, undefined for root command */
|
|
37
|
-
parent?: Command<Arguments, Options & O>;
|
|
38
|
-
/** the command name used to invoke it */
|
|
39
|
-
name: string;
|
|
40
|
-
/** semantic version string displayed by --version flag */
|
|
41
|
-
version?: string;
|
|
42
|
-
/** alternative names for invoking this command */
|
|
43
|
-
aliases: string[];
|
|
44
|
-
/** brief one-line description shown in command lists */
|
|
45
|
-
summary?: string;
|
|
46
|
-
/** full description displayed in help text */
|
|
47
|
-
description: string;
|
|
48
|
-
/** whether to exclude from help listings */
|
|
49
|
-
hidden?: boolean;
|
|
50
|
-
/** category for organizing related commands in help output */
|
|
51
|
-
group?: string;
|
|
52
|
-
/** positional arguments this command accepts */
|
|
53
|
-
arguments: Argument[];
|
|
54
|
-
/** cLI options (flags) this command recognizes */
|
|
55
|
-
options: Option[];
|
|
56
|
-
/** subcommands registered with this command */
|
|
57
|
-
commands: Subs;
|
|
58
|
-
/** main action handler executed when command is invoked */
|
|
59
|
-
protected action?: ActionHandler<A, O, Subs>;
|
|
60
|
-
/** option-driven actions (e.g., --help, --version) executed when their conditions match */
|
|
61
|
-
protected hooks: HookDefinition<Arguments, Options & O>[];
|
|
62
|
-
constructor(name: string, parent?: ICommand);
|
|
63
|
-
protected get help(): Help;
|
|
64
|
-
/** configure how the help is rendered */
|
|
65
|
-
helpConfiguration(cb?: (help: Help) => void): this;
|
|
66
|
-
/** renders formatted help text using provided help definition */
|
|
67
|
-
renderHelp(config?: {
|
|
68
|
-
noColor?: boolean;
|
|
69
|
-
}): string;
|
|
70
|
-
/** sets the command name */
|
|
71
|
-
setName(name: string): void;
|
|
72
|
-
/** sets command aliases, flattening nested arrays */
|
|
73
|
-
setAliases(...aliases: (string | string[])[]): this;
|
|
74
|
-
/** adds aliases to existing ones */
|
|
75
|
-
addAliases(...aliases: (string | string[])[]): this;
|
|
76
|
-
/** sets the command version */
|
|
77
|
-
setVersion(version: string): InferAddOptionResult<A, O, {
|
|
78
|
-
version?: boolean;
|
|
79
|
-
}, Subs>;
|
|
80
|
-
/** sets the command summary */
|
|
81
|
-
setSummary(summary?: string): this;
|
|
82
|
-
/** sets command description, joining variadic lines */
|
|
83
|
-
setDescription(...lines: string[]): this;
|
|
84
|
-
/** sets whether command is hidden from help */
|
|
85
|
-
setHidden(hidden?: boolean | undefined): this;
|
|
86
|
-
/** sets the command group for help organization */
|
|
87
|
-
setGroup(group?: string): this;
|
|
88
|
-
/** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
89
|
-
command<Name extends string, Sub extends Command<any, any, any> = Command<[], O, {}>>(name: Name, cb?: (cmd: Command<[], O, {}>, parent: this) => Sub): Sub;
|
|
90
|
-
/** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
91
|
-
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) & {
|
|
92
|
-
[K in Name]: Sub;
|
|
93
|
-
}>;
|
|
94
|
-
/** add required variadic argument, eg.: `<name...>` */
|
|
95
|
-
addArgument<const Opts extends RequiredVariadicArgumentOptions>(usage: AllowedArgumentUsage<this, `<${string}...>`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
|
|
96
|
-
/** add required argument, eg.: `<name>` */
|
|
97
|
-
addArgument<const Opts extends RequiredArgumentOptions>(usage: AllowedArgumentUsage<this, `<${string}>`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
|
|
98
|
-
/** add optional variadic argument with defaults, eg.: `[name...]` */
|
|
99
|
-
addArgument<const Opts extends OptionalVariadicArgumentOptions>(usage: AllowedArgumentUsage<this, `[${string}...]`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
|
|
100
|
-
/** add optional argument with default, eg.: `[name]` */
|
|
101
|
-
addArgument<const Opts extends OptionalArgumentOptionsWithDefaultValue>(usage: AllowedArgumentUsage<this, `[${string}]`>, options: Opts): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
|
|
102
|
-
/** add optional argument, eg.: `[name]` */
|
|
103
|
-
addArgument<const Opts extends OptionalArgumentOptions>(usage: AllowedArgumentUsage<this, `[${string}]`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts> | undefined], O, Subs>;
|
|
104
|
-
/** add optional string option, eg.: `-o, --output [path]` */
|
|
105
|
-
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}]`, options?: SetFieldType<OptionalOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
|
|
106
|
-
[K in CamelCase<Long>]?: string;
|
|
107
|
-
} & O>, Subs>;
|
|
108
|
-
/** add optional string option with default, eg.: `-o, --output [path]` */
|
|
109
|
-
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}]`, options: SetFieldType<SetRequired<OptionalOptionOptions, 'defaultValue'>, 'defaultValue', string>): Command<A, Simplify<{
|
|
110
|
-
[K in CamelCase<Long>]: string;
|
|
111
|
-
} & O>, Subs>;
|
|
112
|
-
/** add required variadic option, eg.: `-i, --include <patterns...>` */
|
|
113
|
-
addOption<Long extends string>(flags: `-${string}, --${Long} <${string}...>`, options?: RequiredVariadicOptionOptions): Command<A, Simplify<{
|
|
114
|
-
[K in CamelCase<Long>]: string[];
|
|
115
|
-
} & O>, Subs>;
|
|
116
|
-
/** add optional variadic option with defaults, eg.: `-e, --exclude [patterns...]` */
|
|
117
|
-
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}...]`, options?: OptionalVariadicOptionOptions): Command<A, Simplify<{
|
|
118
|
-
[K in CamelCase<Long>]: string[];
|
|
119
|
-
} & O>, Subs>;
|
|
120
|
-
/** add required string option, eg.: `-f, --file <path>` */
|
|
121
|
-
addOption<Long extends string>(flags: `-${string}, --${Long} <${string}>`, options?: RequiredOptionOptions): Command<A, Simplify<{
|
|
122
|
-
[K in CamelCase<Long>]: string;
|
|
123
|
-
} & O>, Subs>;
|
|
124
|
-
/** add boolean flag option with default, eg.: `-v, --verbose` */
|
|
125
|
-
addOption<Long extends string>(flags: `-${string}, --${Long}`, options: SetFieldType<SetRequired<BooleanOptionOptions, 'defaultValue'>, 'defaultValue', boolean>): Command<A, Simplify<{
|
|
126
|
-
[K in CamelCase<Long>]: boolean;
|
|
127
|
-
} & O>, Subs>;
|
|
128
|
-
/** add boolean flag option, eg.: `-v, --verbose` */
|
|
129
|
-
addOption<Long extends string>(flags: `-${string}, --${Long}`, options?: SetFieldType<BooleanOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
|
|
130
|
-
[K in CamelCase<Long>]?: boolean;
|
|
131
|
-
} & O>, Subs>;
|
|
132
|
-
/**
|
|
133
|
-
* register an action to be invoked when an option is set to true or string value.
|
|
134
|
-
*
|
|
135
|
-
* Hooks execute in addition to or instead of the main action handler,
|
|
136
|
-
* allowing for option-driven behavior. For example, `--help` and `--version`
|
|
137
|
-
* are implemented as hooks.
|
|
138
|
-
*/
|
|
139
|
-
addOptionHook(optionName: keyof O, action: HookActionHandler<Arguments, O>): this;
|
|
140
|
-
/** parses command-line arguments with subcommand support and type-safe validation. */
|
|
141
|
-
parseArgv(argv?: string[]): ParseArgvResult<Arguments, Options & O>;
|
|
142
|
-
/**
|
|
143
|
-
* sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
|
|
144
|
-
* The handler receives parsed arguments and options with correct typings.
|
|
145
|
-
*/
|
|
146
|
-
setAction(fn: ActionHandler<A, O, Subs>): this;
|
|
147
|
-
/** returns a new Command instance. Override this method in subclasses. */
|
|
148
|
-
protected createSubcommand(name: string): Command<[], O, {}>;
|
|
149
|
-
}
|
package/lib/Help.d.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import type { Argument } from './types';
|
|
2
|
-
import type { ICommand } from './types';
|
|
3
|
-
import type { IHelp } from './types';
|
|
4
|
-
import type { Option } from './types';
|
|
5
|
-
/**
|
|
6
|
-
* This is a fork of the Help class from the 'commander' npm package. The Help class method names as well as the
|
|
7
|
-
* expected interface of the Command instance to parse, are both similar, but different and not compatible without
|
|
8
|
-
* custom adaptations, @see ICommand
|
|
9
|
-
*/
|
|
10
|
-
export declare class Help implements IHelp {
|
|
11
|
-
protected readonly cmd: ICommand;
|
|
12
|
-
/** output helpWidth, long lines are wrapped to fit */
|
|
13
|
-
helpWidth: number;
|
|
14
|
-
minWidthToWrap: number;
|
|
15
|
-
sortSubcommands: boolean;
|
|
16
|
-
sortOptions: boolean;
|
|
17
|
-
usageDisplayOptionsAs: string;
|
|
18
|
-
usageDisplaySubcommandAs: string;
|
|
19
|
-
constructor(cmd: ICommand);
|
|
20
|
-
/**
|
|
21
|
-
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
22
|
-
*/
|
|
23
|
-
visibleCommands(): ICommand[];
|
|
24
|
-
/**
|
|
25
|
-
* Compare options for sort.
|
|
26
|
-
*/
|
|
27
|
-
compareOptions(a: Option, b: Option): number;
|
|
28
|
-
/**
|
|
29
|
-
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
30
|
-
*/
|
|
31
|
-
visibleOptions(): Option[];
|
|
32
|
-
/**
|
|
33
|
-
* Get an array of the arguments if any have a description.
|
|
34
|
-
*/
|
|
35
|
-
visibleArguments(): Argument[];
|
|
36
|
-
/**
|
|
37
|
-
* Get the command term to show in the list of subcommands.
|
|
38
|
-
*/
|
|
39
|
-
subcommandTerm(sub: ICommand): string;
|
|
40
|
-
/**
|
|
41
|
-
* Get the option term to show in the list of options.
|
|
42
|
-
*/
|
|
43
|
-
optionTerm(option: Option): string;
|
|
44
|
-
/**
|
|
45
|
-
* Get the argument term to show in the list of arguments.
|
|
46
|
-
*/
|
|
47
|
-
argumentTerm(argument: Argument): string;
|
|
48
|
-
/**
|
|
49
|
-
* Get the longest subcommand primary alias length.
|
|
50
|
-
*/
|
|
51
|
-
longestSubcommandAliasLength(): number;
|
|
52
|
-
/**
|
|
53
|
-
* Get the longest subcommand term length.
|
|
54
|
-
*/
|
|
55
|
-
longestSubcommandTermLength(): number;
|
|
56
|
-
/**
|
|
57
|
-
* Get the longest option term length.
|
|
58
|
-
*/
|
|
59
|
-
longestOptionTermLength(): number;
|
|
60
|
-
/**
|
|
61
|
-
* Get the longest argument term length.
|
|
62
|
-
*/
|
|
63
|
-
longestArgumentTermLength(): number;
|
|
64
|
-
/**
|
|
65
|
-
* Get the command usage to be displayed at the top of the built-in help.
|
|
66
|
-
*/
|
|
67
|
-
commandUsage(): string;
|
|
68
|
-
/**
|
|
69
|
-
* Get the description for the command.
|
|
70
|
-
*/
|
|
71
|
-
commandDescription(): string;
|
|
72
|
-
/**
|
|
73
|
-
* Get the subcommand summary to show in the list of subcommands.
|
|
74
|
-
* (Fallback to description for backwards compatibility.)
|
|
75
|
-
*/
|
|
76
|
-
subcommandDescription(sub: ICommand): string;
|
|
77
|
-
/**
|
|
78
|
-
* Get the option description to show in the list of options.
|
|
79
|
-
*/
|
|
80
|
-
optionDescription(option: Option): string;
|
|
81
|
-
/**
|
|
82
|
-
* Get the argument description to show in the list of arguments.
|
|
83
|
-
*/
|
|
84
|
-
argumentDescription(argument: Argument): string;
|
|
85
|
-
/**
|
|
86
|
-
* Format a list of items, given a heading and an array of formatted items.
|
|
87
|
-
*/
|
|
88
|
-
formatItemList(heading: string, items: string[]): string[];
|
|
89
|
-
/**
|
|
90
|
-
* Group items by their help group heading.
|
|
91
|
-
*/
|
|
92
|
-
groupItems<T extends ICommand | Option>(unsortedItems: T[], visibleItems: T[], getGroup: (item: T) => string): Map<string, T[]>;
|
|
93
|
-
/**
|
|
94
|
-
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
95
|
-
*/
|
|
96
|
-
displayWidth(str: string): number;
|
|
97
|
-
/**
|
|
98
|
-
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
99
|
-
*/
|
|
100
|
-
styleTitle(str: string): string;
|
|
101
|
-
/**
|
|
102
|
-
* Style the usage line for displaying in the help. Applies specific styling to different parts like options, commands, and arguments.
|
|
103
|
-
*/
|
|
104
|
-
styleUsage(str: string): string;
|
|
105
|
-
/**
|
|
106
|
-
* Style command descriptions for display in help output.
|
|
107
|
-
*/
|
|
108
|
-
styleCommandDescription(str: string): string;
|
|
109
|
-
/**
|
|
110
|
-
* Style option descriptions for display in help output.
|
|
111
|
-
*/
|
|
112
|
-
styleOptionDescription(str: string): string;
|
|
113
|
-
/**
|
|
114
|
-
* Style subcommand descriptions for display in help output.
|
|
115
|
-
*/
|
|
116
|
-
styleSubcommandDescription(str: string): string;
|
|
117
|
-
/**
|
|
118
|
-
* Style argument descriptions for display in help output.
|
|
119
|
-
*/
|
|
120
|
-
styleArgumentDescription(str: string): string;
|
|
121
|
-
/**
|
|
122
|
-
* Base style used by descriptions. Override in subclass to apply custom formatting.
|
|
123
|
-
*/
|
|
124
|
-
styleDescriptionText(str: string): string;
|
|
125
|
-
/**
|
|
126
|
-
* Style option terms (flags) for display in help output.
|
|
127
|
-
*/
|
|
128
|
-
styleOptionTerm(str: string): string;
|
|
129
|
-
/**
|
|
130
|
-
* Style subcommand terms for display in help output. Applies specific styling to different parts like options and arguments.
|
|
131
|
-
*/
|
|
132
|
-
styleSubcommandTerm(str: string): string;
|
|
133
|
-
/**
|
|
134
|
-
* Style argument terms for display in help output.
|
|
135
|
-
*/
|
|
136
|
-
styleArgumentTerm(str: string): string;
|
|
137
|
-
/**
|
|
138
|
-
* Base style used in terms and usage for options. Override in subclass to apply custom formatting.
|
|
139
|
-
*/
|
|
140
|
-
styleOptionText(str: string): string;
|
|
141
|
-
/**
|
|
142
|
-
* Base style used in terms and usage for arguments. Override in subclass to apply custom formatting.
|
|
143
|
-
*/
|
|
144
|
-
styleArgumentText(str: string): string;
|
|
145
|
-
/**
|
|
146
|
-
* Base style used in terms and usage for subcommands. Override in subclass to apply custom formatting.
|
|
147
|
-
*/
|
|
148
|
-
styleSubcommandText(str: string): string;
|
|
149
|
-
/**
|
|
150
|
-
* Base style used in terms and usage for commands. Override in subclass to apply custom formatting.
|
|
151
|
-
*/
|
|
152
|
-
styleCommandText(str: string): string;
|
|
153
|
-
/**
|
|
154
|
-
* Calculate the pad width from the maximum term length.
|
|
155
|
-
*/
|
|
156
|
-
padWidth(): number;
|
|
157
|
-
/**
|
|
158
|
-
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
159
|
-
*/
|
|
160
|
-
preformatted(str: string): boolean;
|
|
161
|
-
/**
|
|
162
|
-
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
163
|
-
*
|
|
164
|
-
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
165
|
-
* TTT DDD DDDD
|
|
166
|
-
* DD DDD
|
|
167
|
-
*/
|
|
168
|
-
formatItem(term: string, termWidth: number, description: string): string;
|
|
169
|
-
/**
|
|
170
|
-
* Wrap a string at whitespace, preserving existing line breaks.
|
|
171
|
-
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
172
|
-
*/
|
|
173
|
-
boxWrap(str: string, width: number): string;
|
|
174
|
-
/**
|
|
175
|
-
* Generate the built-in help text.
|
|
176
|
-
*/
|
|
177
|
-
render(): string;
|
|
178
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { CamelCase } from 'type-fest';
|
|
2
|
-
import type { OptionUsage } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Parses option flags string into its components
|
|
5
|
-
*/
|
|
6
|
-
export declare function parseOptionFlags<Long extends string>(flags: OptionUsage<Long>): {
|
|
7
|
-
short: string;
|
|
8
|
-
long: Long;
|
|
9
|
-
name: CamelCase<Long>;
|
|
10
|
-
argName: string | undefined;
|
|
11
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Option } from '../types';
|
|
2
|
-
/** Collect consecutive positional tokens into variadic string option values */
|
|
3
|
-
export declare function collectVariadicOptionValues(parsed: {
|
|
4
|
-
tokens: any[];
|
|
5
|
-
values: any;
|
|
6
|
-
positionals: string[];
|
|
7
|
-
}, options: Option[]): void;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Argument } from '../types';
|
|
2
|
-
import type { Option } from '../types';
|
|
3
|
-
/** Validate parsed arguments and option values, returning errors or undefined */
|
|
4
|
-
export declare function validateParsed(args: unknown[], optionValues: Record<string, unknown>, argDefs: Argument[], optionDefs: Option[]): string[] | undefined;
|