inray 0.0.3 → 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.md +28 -27
- package/README.md +158 -52
- package/dist/async/abortable.d.ts +2 -2
- package/dist/async/abortable.d.ts.map +1 -1
- package/dist/async/abortable.js.map +1 -1
- package/dist/cli/mod.d.ts +2 -0
- package/dist/cli/mod.d.ts.map +1 -0
- package/dist/cli/mod.js +2 -0
- package/dist/cli/mod.js.map +1 -0
- package/dist/cli/src/index.d.ts +25 -0
- package/dist/cli/src/index.d.ts.map +1 -0
- package/dist/cli/src/index.js +25 -0
- package/dist/cli/src/index.js.map +1 -0
- package/dist/cli/src/lib/argument.d.ts +82 -0
- package/dist/cli/src/lib/argument.d.ts.map +1 -0
- package/dist/cli/src/lib/argument.js +143 -0
- package/dist/cli/src/lib/argument.js.map +1 -0
- package/dist/cli/src/lib/command.d.ts +1051 -0
- package/dist/cli/src/lib/command.d.ts.map +1 -0
- package/dist/cli/src/lib/command.js +2208 -0
- package/dist/cli/src/lib/command.js.map +1 -0
- package/dist/cli/src/lib/error.d.ts +35 -0
- package/dist/cli/src/lib/error.d.ts.map +1 -0
- package/dist/cli/src/lib/error.js +49 -0
- package/dist/cli/src/lib/error.js.map +1 -0
- package/dist/cli/src/lib/help.d.ts +250 -0
- package/dist/cli/src/lib/help.d.ts.map +1 -0
- package/dist/cli/src/lib/help.js +583 -0
- package/dist/cli/src/lib/help.js.map +1 -0
- package/dist/cli/src/lib/option.d.ts +189 -0
- package/dist/cli/src/lib/option.d.ts.map +1 -0
- package/dist/cli/src/lib/option.js +364 -0
- package/dist/cli/src/lib/option.js.map +1 -0
- package/dist/cli/src/lib/suggestSimilar.d.ts +18 -0
- package/dist/cli/src/lib/suggestSimilar.d.ts.map +1 -0
- package/dist/cli/src/lib/suggestSimilar.js +99 -0
- package/dist/cli/src/lib/suggestSimilar.js.map +1 -0
- package/dist/logtape/logtape/level.d.ts +1 -2
- package/dist/logtape/logtape/level.d.ts.map +1 -1
- package/dist/logtape/logtape/level.js +1 -1
- package/dist/logtape/logtape/level.js.map +1 -1
- package/dist/logtape/logtape/mod.d.ts +1 -1
- package/dist/logtape/logtape/mod.d.ts.map +1 -1
- package/dist/logtape/logtape/mod.js +1 -1
- package/dist/logtape/logtape/mod.js.map +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.d.ts.map +1 -1
- package/dist/utils/mod.js.map +1 -1
- package/dist/utils/validation/inRangeOfMaxInt32.d.ts +2 -0
- package/dist/utils/validation/inRangeOfMaxInt32.d.ts.map +1 -0
- package/dist/utils/validation/inRangeOfMaxInt32.js +4 -0
- package/dist/utils/validation/inRangeOfMaxInt32.js.map +1 -0
- package/dist/utils/validation/isEmail.d.ts +2 -0
- package/dist/utils/validation/isEmail.d.ts.map +1 -0
- package/dist/utils/validation/isEmail.js +7 -0
- package/dist/utils/validation/isEmail.js.map +1 -0
- package/dist/utils/validation/isEmptyObject.d.ts +9 -0
- package/dist/utils/validation/isEmptyObject.d.ts.map +1 -0
- package/dist/utils/validation/isEmptyObject.js +16 -0
- package/dist/utils/validation/isEmptyObject.js.map +1 -0
- package/dist/utils/validation/isNotEmptyString.d.ts +7 -0
- package/dist/utils/validation/isNotEmptyString.d.ts.map +1 -0
- package/dist/utils/validation/isNotEmptyString.js +17 -0
- package/dist/utils/validation/isNotEmptyString.js.map +1 -0
- package/dist/utils/validation/isPositiveInteger.d.ts +2 -0
- package/dist/utils/validation/isPositiveInteger.d.ts.map +1 -0
- package/dist/utils/validation/isPositiveInteger.js +7 -0
- package/dist/utils/validation/isPositiveInteger.js.map +1 -0
- package/dist/utils/validation/isUuid.d.ts +2 -0
- package/dist/utils/validation/isUuid.d.ts.map +1 -0
- package/dist/utils/validation/isUuid.js +7 -0
- package/dist/utils/validation/isUuid.js.map +1 -0
- package/dist/utils/validation/isUuidArray.d.ts +2 -0
- package/dist/utils/validation/isUuidArray.d.ts.map +1 -0
- package/dist/utils/validation/isUuidArray.js +7 -0
- package/dist/utils/validation/isUuidArray.js.map +1 -0
- package/dist/utils/validation/isValidFileName.d.ts +2 -0
- package/dist/utils/validation/isValidFileName.d.ts.map +1 -0
- package/dist/utils/validation/isValidFileName.js +33 -0
- package/dist/utils/validation/isValidFileName.js.map +1 -0
- package/dist/utils/validation/isValidUrlLike.d.ts +6 -0
- package/dist/utils/validation/isValidUrlLike.d.ts.map +1 -0
- package/dist/utils/validation/isValidUrlLike.js +8 -0
- package/dist/utils/validation/isValidUrlLike.js.map +1 -0
- package/dist/utils/validation/mod.d.ts +21 -0
- package/dist/utils/validation/mod.d.ts.map +1 -0
- package/dist/utils/validation/mod.js +21 -0
- package/dist/utils/validation/mod.js.map +1 -0
- package/dist/utils/validation/vEnvBoolean.d.ts +3 -0
- package/dist/utils/validation/vEnvBoolean.d.ts.map +1 -0
- package/dist/utils/validation/vEnvBoolean.js +5 -0
- package/dist/utils/validation/vEnvBoolean.js.map +1 -0
- package/dist/utils/validation/vEnvBooleanOrUndefined.d.ts +3 -0
- package/dist/utils/validation/vEnvBooleanOrUndefined.d.ts.map +1 -0
- package/dist/utils/validation/vEnvBooleanOrUndefined.js +5 -0
- package/dist/utils/validation/vEnvBooleanOrUndefined.js.map +1 -0
- package/dist/utils/validation/vEnvLogLevel.d.ts +4 -0
- package/dist/utils/validation/vEnvLogLevel.d.ts.map +1 -0
- package/dist/utils/validation/vEnvLogLevel.js +6 -0
- package/dist/utils/validation/vEnvLogLevel.js.map +1 -0
- package/dist/utils/validation/vFileName.d.ts +4 -0
- package/dist/utils/validation/vFileName.d.ts.map +1 -0
- package/dist/utils/validation/vFileName.js +21 -0
- package/dist/utils/validation/vFileName.js.map +1 -0
- package/dist/utils/validation/vISO8601DateTime.d.ts +5 -0
- package/dist/utils/validation/vISO8601DateTime.d.ts.map +1 -0
- package/dist/utils/validation/vISO8601DateTime.js +37 -0
- package/dist/utils/validation/vISO8601DateTime.js.map +1 -0
- package/dist/utils/validation/vLatinInput.d.ts +3 -0
- package/dist/utils/validation/vLatinInput.d.ts.map +1 -0
- package/dist/utils/validation/vLatinInput.js +3 -0
- package/dist/utils/validation/vLatinInput.js.map +1 -0
- package/dist/utils/validation/vOmniBoolean.d.ts +3 -0
- package/dist/utils/validation/vOmniBoolean.d.ts.map +1 -0
- package/dist/utils/validation/vOmniBoolean.js +10 -0
- package/dist/utils/validation/vOmniBoolean.js.map +1 -0
- package/dist/utils/validation/vQueryBoolean.d.ts +3 -0
- package/dist/utils/validation/vQueryBoolean.d.ts.map +1 -0
- package/dist/utils/validation/vQueryBoolean.js +7 -0
- package/dist/utils/validation/vQueryBoolean.js.map +1 -0
- package/dist/utils/validation/vQueryEmailArray.d.ts +9 -0
- package/dist/utils/validation/vQueryEmailArray.d.ts.map +1 -0
- package/dist/utils/validation/vQueryEmailArray.js +29 -0
- package/dist/utils/validation/vQueryEmailArray.js.map +1 -0
- package/dist/utils/validation/vQueryNumberArray.d.ts +10 -0
- package/dist/utils/validation/vQueryNumberArray.d.ts.map +1 -0
- package/dist/utils/validation/vQueryNumberArray.js +32 -0
- package/dist/utils/validation/vQueryNumberArray.js.map +1 -0
- package/dist/utils/validation/vQueryStringifiedEnumArray.d.ts +3 -0
- package/dist/utils/validation/vQueryStringifiedEnumArray.d.ts.map +1 -0
- package/dist/utils/validation/vQueryStringifiedEnumArray.js +25 -0
- package/dist/utils/validation/vQueryStringifiedEnumArray.js.map +1 -0
- package/dist/utils/validation/vQueryUuidArray.d.ts +9 -0
- package/dist/utils/validation/vQueryUuidArray.d.ts.map +1 -0
- package/dist/utils/validation/vQueryUuidArray.js +27 -0
- package/dist/utils/validation/vQueryUuidArray.js.map +1 -0
- package/package.json +15 -2
|
@@ -0,0 +1,1051 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Original library: commander.js (v15.0.0)
|
|
3
|
+
* - Copyright (c) 2011 TJ Holowaychuk
|
|
4
|
+
* - Copyright (c) John Gee and "commander.js" authors
|
|
5
|
+
*
|
|
6
|
+
* Modified and integrated in "Inray":
|
|
7
|
+
* - Evgeniy Bushin
|
|
8
|
+
*/
|
|
9
|
+
/***/
|
|
10
|
+
import { EventEmitter } from 'node:events';
|
|
11
|
+
import { Argument, type ArgumentParseFunction } from './argument.ts';
|
|
12
|
+
import { CommanderError } from './error.ts';
|
|
13
|
+
import { Help } from './help.ts';
|
|
14
|
+
import { Option } from './option.ts';
|
|
15
|
+
export interface CommandOptions {
|
|
16
|
+
hidden?: boolean;
|
|
17
|
+
isDefault?: boolean;
|
|
18
|
+
/** @deprecated old name for hidden */
|
|
19
|
+
noHelp?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ExecutableCommandOptions extends CommandOptions {
|
|
22
|
+
executableFile?: string;
|
|
23
|
+
}
|
|
24
|
+
type LiteralUnion<LiteralType, BaseType extends string | number> = LiteralType | (BaseType & Record<never, never>);
|
|
25
|
+
export type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';
|
|
26
|
+
export type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';
|
|
27
|
+
export type HookListener = (thisCommand: Command, actionCommand: Command) => void | Promise<void>;
|
|
28
|
+
export type OptionValueSource = LiteralUnion<'default' | 'config' | 'env' | 'cli' | 'implied', string> | undefined;
|
|
29
|
+
export type OptionValues = Record<string, any>;
|
|
30
|
+
export type HelpConfiguration = Partial<Help>;
|
|
31
|
+
export interface ParseOptions {
|
|
32
|
+
from: 'node' | 'electron' | 'user' | 'eval';
|
|
33
|
+
}
|
|
34
|
+
export interface HelpContext {
|
|
35
|
+
error?: boolean;
|
|
36
|
+
helpWidth?: number;
|
|
37
|
+
hasColors?: boolean;
|
|
38
|
+
write?: (str: string) => void;
|
|
39
|
+
}
|
|
40
|
+
export interface AddHelpTextContext {
|
|
41
|
+
error: boolean;
|
|
42
|
+
command: Command;
|
|
43
|
+
}
|
|
44
|
+
export interface OutputConfiguration {
|
|
45
|
+
writeOut(str: string): void;
|
|
46
|
+
writeErr(str: string): void;
|
|
47
|
+
outputError(str: string, write: (str: string) => void): void;
|
|
48
|
+
getOutHelpWidth(): number | undefined;
|
|
49
|
+
getErrHelpWidth(): number | undefined;
|
|
50
|
+
getOutHasColors(): boolean | undefined;
|
|
51
|
+
getErrHasColors(): boolean | undefined;
|
|
52
|
+
stripColor(str: string): string;
|
|
53
|
+
}
|
|
54
|
+
export interface ErrorOptions {
|
|
55
|
+
code?: string;
|
|
56
|
+
exitCode?: number;
|
|
57
|
+
}
|
|
58
|
+
export interface ParseOptionsResult {
|
|
59
|
+
operands: string[];
|
|
60
|
+
unknown: string[];
|
|
61
|
+
}
|
|
62
|
+
type SavedState = {
|
|
63
|
+
_name: string;
|
|
64
|
+
_optionValues: OptionValues;
|
|
65
|
+
_optionValueSources: Record<string, OptionValueSource>;
|
|
66
|
+
};
|
|
67
|
+
export declare class Command extends EventEmitter {
|
|
68
|
+
args: string[];
|
|
69
|
+
processedArgs: any[];
|
|
70
|
+
commands: Command[];
|
|
71
|
+
options: Option[];
|
|
72
|
+
registeredArguments: Argument[];
|
|
73
|
+
parent: Command | null;
|
|
74
|
+
_allowUnknownOption: boolean;
|
|
75
|
+
_allowExcessArguments: boolean;
|
|
76
|
+
_args: Argument[];
|
|
77
|
+
rawArgs: string[];
|
|
78
|
+
_version: string | undefined;
|
|
79
|
+
_scriptPath: string | null;
|
|
80
|
+
_name: string;
|
|
81
|
+
_optionValues: OptionValues;
|
|
82
|
+
_optionValueSources: Record<string, OptionValueSource>;
|
|
83
|
+
_storeOptionsAsProperties: boolean;
|
|
84
|
+
_actionHandler: ((args: any) => void | Promise<void>) | null;
|
|
85
|
+
_executableHandler: boolean;
|
|
86
|
+
_executableFile: string | null;
|
|
87
|
+
_executableDir: string | null;
|
|
88
|
+
_defaultCommandName: string | null;
|
|
89
|
+
_exitCallback: ((err: CommanderError) => never | void) | null;
|
|
90
|
+
_aliases: string[];
|
|
91
|
+
_combineFlagAndOptionalValue: boolean;
|
|
92
|
+
_description: string;
|
|
93
|
+
_summary: string;
|
|
94
|
+
_argsDescription?: Record<string, string>;
|
|
95
|
+
_enablePositionalOptions: boolean;
|
|
96
|
+
_passThroughOptions: boolean;
|
|
97
|
+
_lifeCycleHooks: Record<string, HookListener[]>;
|
|
98
|
+
_showHelpAfterError: boolean | string;
|
|
99
|
+
_showSuggestionAfterError: boolean;
|
|
100
|
+
_savedState: SavedState | null;
|
|
101
|
+
_outputConfiguration: OutputConfiguration;
|
|
102
|
+
_hidden: boolean;
|
|
103
|
+
_helpOption?: Option | null;
|
|
104
|
+
_addImplicitHelpCommand?: boolean;
|
|
105
|
+
_helpCommand?: Command;
|
|
106
|
+
_helpConfiguration: HelpConfiguration;
|
|
107
|
+
_helpGroupHeading?: string;
|
|
108
|
+
_defaultCommandGroup?: string;
|
|
109
|
+
_defaultOptionGroup?: string;
|
|
110
|
+
_usage?: string;
|
|
111
|
+
_versionOptionName?: string;
|
|
112
|
+
runningCommand?: any;
|
|
113
|
+
/**
|
|
114
|
+
* Initialize a new `Command`.
|
|
115
|
+
*
|
|
116
|
+
* @param {string} [name]
|
|
117
|
+
*/
|
|
118
|
+
constructor(name?: string);
|
|
119
|
+
/**
|
|
120
|
+
* Copy settings that are useful to have in common across root command and subcommands.
|
|
121
|
+
*
|
|
122
|
+
* (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
|
|
123
|
+
*
|
|
124
|
+
* @param {Command} sourceCommand
|
|
125
|
+
* @return {Command} `this` command for chaining
|
|
126
|
+
*/
|
|
127
|
+
copyInheritedSettings(sourceCommand: Command): this;
|
|
128
|
+
/**
|
|
129
|
+
* @returns {Command[]}
|
|
130
|
+
* @private
|
|
131
|
+
*/
|
|
132
|
+
private _getCommandAndAncestors;
|
|
133
|
+
/**
|
|
134
|
+
* Define a command.
|
|
135
|
+
*
|
|
136
|
+
* There are two styles of command: pay attention to where to put the description.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* // Command implemented using action handler (description is supplied separately to `.command`)
|
|
140
|
+
* program
|
|
141
|
+
* .command('clone <source> [destination]')
|
|
142
|
+
* .description('clone a repository into a newly created directory')
|
|
143
|
+
* .action((source, destination) => {
|
|
144
|
+
* console.log('clone command called');
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* // Command implemented using separate executable file (description is second parameter to `.command`)
|
|
148
|
+
* program
|
|
149
|
+
* .command('start <service>', 'start named service')
|
|
150
|
+
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
|
151
|
+
*
|
|
152
|
+
* @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
153
|
+
* @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
|
|
154
|
+
* @param {object} [execOpts] - configuration options (for executable)
|
|
155
|
+
* @return {Command} returns new command for action handler, or `this` for executable command
|
|
156
|
+
*/
|
|
157
|
+
command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>;
|
|
158
|
+
command(nameAndArgs: string, description: string, opts?: ExecutableCommandOptions): this;
|
|
159
|
+
/**
|
|
160
|
+
* Factory routine to create a new unattached command.
|
|
161
|
+
*
|
|
162
|
+
* See .command() for creating an attached subcommand, which uses this routine to
|
|
163
|
+
* create the command. You can override createCommand to customise subcommands.
|
|
164
|
+
*
|
|
165
|
+
* @param {string} [name]
|
|
166
|
+
* @return {Command} new command
|
|
167
|
+
*/
|
|
168
|
+
createCommand(name?: string): Command;
|
|
169
|
+
/**
|
|
170
|
+
* You can customise the help with a subclass of Help by overriding createHelp,
|
|
171
|
+
* or by overriding Help properties using configureHelp().
|
|
172
|
+
*
|
|
173
|
+
* @return {Help}
|
|
174
|
+
*/
|
|
175
|
+
createHelp(): Help;
|
|
176
|
+
/**
|
|
177
|
+
* You can customise the help by overriding Help properties using configureHelp(),
|
|
178
|
+
* or with a subclass of Help by overriding createHelp().
|
|
179
|
+
*
|
|
180
|
+
* @param {object} [configuration] - configuration options
|
|
181
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
182
|
+
*/
|
|
183
|
+
configureHelp(): HelpConfiguration;
|
|
184
|
+
configureHelp(configuration: HelpConfiguration): this;
|
|
185
|
+
/**
|
|
186
|
+
* The default output goes to stdout and stderr. You can customise this for special
|
|
187
|
+
* applications. You can also customise the display of errors by overriding outputError.
|
|
188
|
+
*
|
|
189
|
+
* The configuration properties are all functions:
|
|
190
|
+
*
|
|
191
|
+
* // change how output being written, defaults to stdout and stderr
|
|
192
|
+
* writeOut(str)
|
|
193
|
+
* writeErr(str)
|
|
194
|
+
* // change how output being written for errors, defaults to writeErr
|
|
195
|
+
* outputError(str, write) // used for displaying errors and not used for displaying help
|
|
196
|
+
* // specify width for wrapping help
|
|
197
|
+
* getOutHelpWidth()
|
|
198
|
+
* getErrHelpWidth()
|
|
199
|
+
* // color support, currently only used with Help
|
|
200
|
+
* getOutHasColors()
|
|
201
|
+
* getErrHasColors()
|
|
202
|
+
* stripColor() // used to remove ANSI escape codes if output does not have colors
|
|
203
|
+
*
|
|
204
|
+
* @param {object} [configuration] - configuration options
|
|
205
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
206
|
+
*/
|
|
207
|
+
configureOutput(): OutputConfiguration;
|
|
208
|
+
configureOutput(configuration: Partial<OutputConfiguration>): this;
|
|
209
|
+
/**
|
|
210
|
+
* Display the help or a custom message after an error occurs.
|
|
211
|
+
*
|
|
212
|
+
* @param {(boolean|string)} [displayHelp]
|
|
213
|
+
* @return {Command} `this` command for chaining
|
|
214
|
+
*/
|
|
215
|
+
showHelpAfterError(displayHelp?: boolean | string): this;
|
|
216
|
+
/**
|
|
217
|
+
* Display suggestion of similar commands for unknown commands, or options for unknown options.
|
|
218
|
+
*
|
|
219
|
+
* @param {boolean} [displaySuggestion]
|
|
220
|
+
* @return {Command} `this` command for chaining
|
|
221
|
+
*/
|
|
222
|
+
showSuggestionAfterError(displaySuggestion?: boolean): this;
|
|
223
|
+
/**
|
|
224
|
+
* Add a prepared subcommand.
|
|
225
|
+
*
|
|
226
|
+
* See .command() for creating an attached subcommand which inherits settings from its parent.
|
|
227
|
+
*
|
|
228
|
+
* @param {Command} cmd - new subcommand
|
|
229
|
+
* @param {object} [opts] - configuration options
|
|
230
|
+
* @return {Command} `this` command for chaining
|
|
231
|
+
*/
|
|
232
|
+
addCommand(cmd: Command, opts?: CommandOptions): this;
|
|
233
|
+
/**
|
|
234
|
+
* Factory routine to create a new unattached argument.
|
|
235
|
+
*
|
|
236
|
+
* See .argument() for creating an attached argument, which uses this routine to
|
|
237
|
+
* create the argument. You can override createArgument to return a custom argument.
|
|
238
|
+
*
|
|
239
|
+
* @param {string} name
|
|
240
|
+
* @param {string} [description]
|
|
241
|
+
* @return {Argument} new argument
|
|
242
|
+
*/
|
|
243
|
+
createArgument(name: string, description?: string): Argument;
|
|
244
|
+
/**
|
|
245
|
+
* Define argument syntax for command.
|
|
246
|
+
*
|
|
247
|
+
* The default is that the argument is required, and you can explicitly
|
|
248
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* program.argument('<input-file>');
|
|
252
|
+
* program.argument('[output-file]');
|
|
253
|
+
*
|
|
254
|
+
* @return {Command} `this` command for chaining
|
|
255
|
+
*/
|
|
256
|
+
argument<T>(name: string, description?: string, parseArg?: ArgumentParseFunction | unknown, defaultValue?: T): this;
|
|
257
|
+
/**
|
|
258
|
+
* Define argument syntax for command, adding multiple at once (without descriptions).
|
|
259
|
+
*
|
|
260
|
+
* See also .argument().
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* program.arguments('<cmd> [env]');
|
|
264
|
+
*
|
|
265
|
+
* @param {string} names
|
|
266
|
+
* @return {Command} `this` command for chaining
|
|
267
|
+
*/
|
|
268
|
+
arguments(names: string): this;
|
|
269
|
+
/**
|
|
270
|
+
* Define argument syntax for command, adding a prepared argument.
|
|
271
|
+
*
|
|
272
|
+
* @param {Argument} argument
|
|
273
|
+
* @return {Command} `this` command for chaining
|
|
274
|
+
*/
|
|
275
|
+
addArgument(argument: Argument): this;
|
|
276
|
+
/**
|
|
277
|
+
* Customise or override default help command. By default a help command is automatically added if your command has subcommands.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* program.helpCommand('help [cmd]');
|
|
281
|
+
* program.helpCommand('help [cmd]', 'show help');
|
|
282
|
+
* program.helpCommand(false); // suppress default help command
|
|
283
|
+
* program.helpCommand(true); // add help command even if no subcommands
|
|
284
|
+
*
|
|
285
|
+
* @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
|
|
286
|
+
* @param {string} [description] - custom description
|
|
287
|
+
* @return {Command} `this` command for chaining
|
|
288
|
+
*/
|
|
289
|
+
helpCommand(nameAndArgs: string, description?: string): this;
|
|
290
|
+
helpCommand(enable?: boolean): this;
|
|
291
|
+
/**
|
|
292
|
+
* Add prepared custom help command.
|
|
293
|
+
*
|
|
294
|
+
* @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
|
|
295
|
+
* @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
|
|
296
|
+
* @return {Command} `this` command for chaining
|
|
297
|
+
*/
|
|
298
|
+
addHelpCommand(cmd: Command): this;
|
|
299
|
+
addHelpCommand(nameAndArgs: string, description?: string): this;
|
|
300
|
+
addHelpCommand(enable?: boolean): this;
|
|
301
|
+
/**
|
|
302
|
+
* Lazy create help command.
|
|
303
|
+
*
|
|
304
|
+
* @return {(Command|null)}
|
|
305
|
+
* @package
|
|
306
|
+
*/
|
|
307
|
+
_getHelpCommand(): Command | null;
|
|
308
|
+
/**
|
|
309
|
+
* Add hook for life cycle event.
|
|
310
|
+
*
|
|
311
|
+
* @param {string} event
|
|
312
|
+
* @param {Function} listener
|
|
313
|
+
* @return {Command} `this` command for chaining
|
|
314
|
+
*/
|
|
315
|
+
hook(event: HookEvent, listener: (thisCommand: Command, actionCommand: Command) => any | void | Promise<void>): this;
|
|
316
|
+
/**
|
|
317
|
+
* Register callback to use as replacement for calling process.exit.
|
|
318
|
+
*
|
|
319
|
+
* @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
|
|
320
|
+
* @return {Command} `this` command for chaining
|
|
321
|
+
*/
|
|
322
|
+
exitOverride(fn?: (err: CommanderError) => never | void): this;
|
|
323
|
+
/**
|
|
324
|
+
* Call process.exit, and _exitCallback if defined.
|
|
325
|
+
*
|
|
326
|
+
* @param {number} exitCode exit code for using with process.exit
|
|
327
|
+
* @param {string} code an id string representing the error
|
|
328
|
+
* @param {string} message human-readable description of the error
|
|
329
|
+
* @return never
|
|
330
|
+
* @private
|
|
331
|
+
*/
|
|
332
|
+
_exit(exitCode: number, code: string, message: string): never;
|
|
333
|
+
/**
|
|
334
|
+
* Register callback `fn` for the command.
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* program
|
|
338
|
+
* .command('serve')
|
|
339
|
+
* .description('start service')
|
|
340
|
+
* .action(function() {
|
|
341
|
+
* // do work here
|
|
342
|
+
* });
|
|
343
|
+
*
|
|
344
|
+
* @param {Function} fn
|
|
345
|
+
* @return {Command} `this` command for chaining
|
|
346
|
+
*/
|
|
347
|
+
action(fn: (this: this, ...args: any[]) => any | void | Promise<void>): this;
|
|
348
|
+
/**
|
|
349
|
+
* Factory routine to create a new unattached option.
|
|
350
|
+
*
|
|
351
|
+
* See .option() for creating an attached option, which uses this routine to
|
|
352
|
+
* create the option. You can override createOption to return a custom option.
|
|
353
|
+
*
|
|
354
|
+
* @param {string} flags
|
|
355
|
+
* @param {string} [description]
|
|
356
|
+
* @return {Option} new option
|
|
357
|
+
*/
|
|
358
|
+
createOption(flags: string, description?: string): Option;
|
|
359
|
+
/**
|
|
360
|
+
* Wrap parseArgs to catch 'commander.invalidArgument'.
|
|
361
|
+
*
|
|
362
|
+
* @param {(Option | Argument)} target
|
|
363
|
+
* @param {string} value
|
|
364
|
+
* @param {*} previous
|
|
365
|
+
* @param {string} invalidArgumentMessage
|
|
366
|
+
* @private
|
|
367
|
+
*/
|
|
368
|
+
_callParseArg(target: Option | Argument, value: any, previous: any, invalidArgumentMessage: string): any;
|
|
369
|
+
/**
|
|
370
|
+
* Check for option flag conflicts.
|
|
371
|
+
* Register option if no conflicts found, or throw on conflict.
|
|
372
|
+
*
|
|
373
|
+
* @param {Option} option
|
|
374
|
+
* @private
|
|
375
|
+
*/
|
|
376
|
+
_registerOption(option: Option): void;
|
|
377
|
+
/**
|
|
378
|
+
* Check for command name and alias conflicts with existing commands.
|
|
379
|
+
* Register command if no conflicts found, or throw on conflict.
|
|
380
|
+
*
|
|
381
|
+
* @param {Command} command
|
|
382
|
+
* @private
|
|
383
|
+
*/
|
|
384
|
+
_registerCommand(command: Command): void;
|
|
385
|
+
/**
|
|
386
|
+
* Add an option.
|
|
387
|
+
*
|
|
388
|
+
* @param {Option} option
|
|
389
|
+
* @return {Command} `this` command for chaining
|
|
390
|
+
*/
|
|
391
|
+
addOption(option: Option): this;
|
|
392
|
+
/**
|
|
393
|
+
* Internal implementation shared by .option() and .requiredOption()
|
|
394
|
+
*
|
|
395
|
+
* @return {Command} `this` command for chaining
|
|
396
|
+
* @private
|
|
397
|
+
*/
|
|
398
|
+
private _optionEx;
|
|
399
|
+
/**
|
|
400
|
+
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
|
|
401
|
+
*
|
|
402
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
|
|
403
|
+
* option-argument is indicated by `<>` and an optional option-argument by `[]`.
|
|
404
|
+
*
|
|
405
|
+
* See the README for more details, and see also addOption() and requiredOption().
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* program
|
|
409
|
+
* .option('-p, --pepper', 'add pepper')
|
|
410
|
+
* .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
|
|
411
|
+
* .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
|
|
412
|
+
* .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
|
|
413
|
+
*
|
|
414
|
+
* @param {string} flags
|
|
415
|
+
* @param {string} [description]
|
|
416
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
417
|
+
* @param {*} [defaultValue]
|
|
418
|
+
* @return {Command} `this` command for chaining
|
|
419
|
+
*/
|
|
420
|
+
option(flags: string, description?: string, defaultValue?: string | number | boolean | string[]): this;
|
|
421
|
+
option<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
|
|
422
|
+
/**
|
|
423
|
+
* Add a required option which must have a value after parsing. This usually means
|
|
424
|
+
* the option must be specified on the command line. (Otherwise the same as .option().)
|
|
425
|
+
*
|
|
426
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
|
|
427
|
+
*
|
|
428
|
+
* @param {string} flags
|
|
429
|
+
* @param {string} [description]
|
|
430
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
431
|
+
* @param {*} [defaultValue]
|
|
432
|
+
* @return {Command} `this` command for chaining
|
|
433
|
+
*/
|
|
434
|
+
requiredOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
|
|
435
|
+
requiredOption<T>(flags: string, description: string, parseArg: ArgumentParseFunction, defaultValue?: T): this;
|
|
436
|
+
requiredOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
|
|
437
|
+
requiredOption<T>(flags: string, description: string, parseArg: ArgumentParseFunction, defaultValue?: T): this;
|
|
438
|
+
/**
|
|
439
|
+
* Alter parsing of short flags with optional values.
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* // for `.option('-f,--flag [value]'):
|
|
443
|
+
* program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
444
|
+
* program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
445
|
+
*
|
|
446
|
+
* @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
|
|
447
|
+
* @return {Command} `this` command for chaining
|
|
448
|
+
*/
|
|
449
|
+
combineFlagAndOptionalValue(combine?: boolean): this;
|
|
450
|
+
/**
|
|
451
|
+
* Allow unknown options on the command line.
|
|
452
|
+
*
|
|
453
|
+
* @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
|
|
454
|
+
* @return {Command} `this` command for chaining
|
|
455
|
+
*/
|
|
456
|
+
allowUnknownOption(allowUnknown?: boolean): this;
|
|
457
|
+
/**
|
|
458
|
+
* Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
|
|
459
|
+
*
|
|
460
|
+
* @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
|
|
461
|
+
* @return {Command} `this` command for chaining
|
|
462
|
+
*/
|
|
463
|
+
allowExcessArguments(allowExcess?: boolean): this;
|
|
464
|
+
/**
|
|
465
|
+
* Enable positional options. Positional means global options are specified before subcommands which lets
|
|
466
|
+
* subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
|
|
467
|
+
* The default behaviour is non-positional and global options may appear anywhere on the command line.
|
|
468
|
+
*
|
|
469
|
+
* @param {boolean} [positional]
|
|
470
|
+
* @return {Command} `this` command for chaining
|
|
471
|
+
*/
|
|
472
|
+
enablePositionalOptions(positional?: boolean): this;
|
|
473
|
+
/**
|
|
474
|
+
* Pass through options that come after command-arguments rather than treat them as command-options,
|
|
475
|
+
* so actual command-options come before command-arguments. Turning this on for a subcommand requires
|
|
476
|
+
* positional options to have been enabled on the program (parent commands).
|
|
477
|
+
* The default behaviour is non-positional and options may appear before or after command-arguments.
|
|
478
|
+
*
|
|
479
|
+
* @param {boolean} [passThrough] for unknown options.
|
|
480
|
+
* @return {Command} `this` command for chaining
|
|
481
|
+
*/
|
|
482
|
+
passThroughOptions(passThrough?: boolean): this;
|
|
483
|
+
/**
|
|
484
|
+
* @private
|
|
485
|
+
*/
|
|
486
|
+
_checkForBrokenPassThrough(): void;
|
|
487
|
+
/**
|
|
488
|
+
* Whether to store option values as properties on command object,
|
|
489
|
+
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
|
490
|
+
*
|
|
491
|
+
* @param {boolean} [storeAsProperties=true]
|
|
492
|
+
* @return {Command} `this` command for chaining
|
|
493
|
+
*/
|
|
494
|
+
storeOptionsAsProperties(storeAsProperties?: boolean): this;
|
|
495
|
+
/**
|
|
496
|
+
* Retrieve option value.
|
|
497
|
+
*
|
|
498
|
+
* @param {string} key
|
|
499
|
+
* @return {object} value
|
|
500
|
+
*/
|
|
501
|
+
getOptionValue(key: string): any;
|
|
502
|
+
/**
|
|
503
|
+
* Store option value.
|
|
504
|
+
*
|
|
505
|
+
* @param {string} key
|
|
506
|
+
* @param {object} value
|
|
507
|
+
* @return {Command} `this` command for chaining
|
|
508
|
+
*/
|
|
509
|
+
setOptionValue(key: string, value: unknown): this;
|
|
510
|
+
/**
|
|
511
|
+
* Store option value and where the value came from.
|
|
512
|
+
*
|
|
513
|
+
* @param {string} key
|
|
514
|
+
* @param {object} value
|
|
515
|
+
* @param {string} source - expected values are default/config/env/cli/implied
|
|
516
|
+
* @return {Command} `this` command for chaining
|
|
517
|
+
*/
|
|
518
|
+
setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this;
|
|
519
|
+
/**
|
|
520
|
+
* Get source of option value.
|
|
521
|
+
* Expected values are default | config | env | cli | implied
|
|
522
|
+
*
|
|
523
|
+
* @param {string} key
|
|
524
|
+
* @return {string}
|
|
525
|
+
*/
|
|
526
|
+
getOptionValueSource(key: string): OptionValueSource | undefined;
|
|
527
|
+
/**
|
|
528
|
+
* Get source of option value. See also .optsWithGlobals().
|
|
529
|
+
* Expected values are default | config | env | cli | implied
|
|
530
|
+
*
|
|
531
|
+
* @param {string} key
|
|
532
|
+
* @return {string}
|
|
533
|
+
*/
|
|
534
|
+
getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined;
|
|
535
|
+
/**
|
|
536
|
+
* Get user arguments from implied or explicit arguments.
|
|
537
|
+
* Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
|
|
538
|
+
*
|
|
539
|
+
* @private
|
|
540
|
+
*/
|
|
541
|
+
private _prepareUserArgs;
|
|
542
|
+
/**
|
|
543
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
544
|
+
*
|
|
545
|
+
* Use parseAsync instead of parse if any of your action handlers are async.
|
|
546
|
+
*
|
|
547
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
548
|
+
*
|
|
549
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
550
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
551
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
552
|
+
* - `'user'`: just user arguments
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* program.parse(); // parse process.argv and auto-detect electron and special node flags
|
|
556
|
+
* program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
|
557
|
+
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
558
|
+
*
|
|
559
|
+
* @param {string[]} [argv] - optional, defaults to process.argv
|
|
560
|
+
* @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
|
|
561
|
+
* @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
|
|
562
|
+
* @return {Command} `this` command for chaining
|
|
563
|
+
*/
|
|
564
|
+
parse(argv?: readonly (string | number)[], parseOptions?: ParseOptions): this;
|
|
565
|
+
/**
|
|
566
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
567
|
+
*
|
|
568
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
569
|
+
*
|
|
570
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
571
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
572
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
573
|
+
* - `'user'`: just user arguments
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
|
|
577
|
+
* await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
|
|
578
|
+
* await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
579
|
+
*
|
|
580
|
+
* @param {string[]} [argv]
|
|
581
|
+
* @param {object} [parseOptions]
|
|
582
|
+
* @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
|
|
583
|
+
* @return {Promise}
|
|
584
|
+
*/
|
|
585
|
+
parseAsync(argv?: readonly string[], parseOptions?: ParseOptions): Promise<this>;
|
|
586
|
+
_prepareForParse(): void;
|
|
587
|
+
/**
|
|
588
|
+
* Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
|
|
589
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
590
|
+
*
|
|
591
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state saved.
|
|
592
|
+
*/
|
|
593
|
+
saveStateBeforeParse(): void;
|
|
594
|
+
/**
|
|
595
|
+
* Restore state before parse for calls after the first.
|
|
596
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
597
|
+
*
|
|
598
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state restored.
|
|
599
|
+
*/
|
|
600
|
+
restoreStateBeforeParse(): void;
|
|
601
|
+
/**
|
|
602
|
+
* Throw if expected executable is missing. Add lots of help for author.
|
|
603
|
+
*
|
|
604
|
+
* @param {string} executableFile
|
|
605
|
+
* @param {string} executableDir
|
|
606
|
+
* @param {string} subcommandName
|
|
607
|
+
*/
|
|
608
|
+
_checkForMissingExecutable(executableFile: string, executableDir: string, subcommandName: string): void;
|
|
609
|
+
/**
|
|
610
|
+
* Execute a sub-command executable.
|
|
611
|
+
*
|
|
612
|
+
* @private
|
|
613
|
+
*/
|
|
614
|
+
_executeSubCommand(subcommand: Command, args: string[]): void;
|
|
615
|
+
/**
|
|
616
|
+
* @private
|
|
617
|
+
*/
|
|
618
|
+
_dispatchSubcommand(commandName: string, operands: string[], unknown: string[]): any;
|
|
619
|
+
/**
|
|
620
|
+
* Invoke help directly if possible, or dispatch if necessary.
|
|
621
|
+
* e.g. help foo
|
|
622
|
+
*
|
|
623
|
+
* @private
|
|
624
|
+
*/
|
|
625
|
+
_dispatchHelpCommand(subcommandName?: string): any;
|
|
626
|
+
/**
|
|
627
|
+
* Check this.args against expected this.registeredArguments.
|
|
628
|
+
*
|
|
629
|
+
* @private
|
|
630
|
+
*/
|
|
631
|
+
_checkNumberOfArguments(): void;
|
|
632
|
+
/**
|
|
633
|
+
* Process this.args using this.registeredArguments and save as this.processedArgs!
|
|
634
|
+
*
|
|
635
|
+
* @private
|
|
636
|
+
*/
|
|
637
|
+
_processArguments(): void;
|
|
638
|
+
/**
|
|
639
|
+
* Once we have a promise we chain, but call synchronously until then.
|
|
640
|
+
*
|
|
641
|
+
* @param {(Promise|undefined)} promise
|
|
642
|
+
* @param {Function} fn
|
|
643
|
+
* @return {(Promise|undefined)}
|
|
644
|
+
* @private
|
|
645
|
+
*/
|
|
646
|
+
_chainOrCall(promise: any, fn: () => any): any;
|
|
647
|
+
/**
|
|
648
|
+
*
|
|
649
|
+
* @param {(Promise|undefined)} promise
|
|
650
|
+
* @param {string} event
|
|
651
|
+
* @return {(Promise|undefined)}
|
|
652
|
+
* @private
|
|
653
|
+
*/
|
|
654
|
+
_chainOrCallHooks(promise: any, event: string): any;
|
|
655
|
+
/**
|
|
656
|
+
*
|
|
657
|
+
* @param {(Promise|undefined)} promise
|
|
658
|
+
* @param {Command} subCommand
|
|
659
|
+
* @param {string} event
|
|
660
|
+
* @return {(Promise|undefined)}
|
|
661
|
+
* @private
|
|
662
|
+
*/
|
|
663
|
+
_chainOrCallSubCommandHook(promise: any, subCommand: Command, event: string): any;
|
|
664
|
+
/**
|
|
665
|
+
* Process arguments in context of this command.
|
|
666
|
+
* Returns action result, in case it is a promise.
|
|
667
|
+
*
|
|
668
|
+
* @private
|
|
669
|
+
*/
|
|
670
|
+
_parseCommand(operands: string[], unknown: string[]): any;
|
|
671
|
+
/**
|
|
672
|
+
* Find matching command.
|
|
673
|
+
*
|
|
674
|
+
* @private
|
|
675
|
+
* @return {Command | undefined}
|
|
676
|
+
*/
|
|
677
|
+
_findCommand(name?: string): Command | undefined;
|
|
678
|
+
/**
|
|
679
|
+
* Return an option matching `arg` if any.
|
|
680
|
+
*
|
|
681
|
+
* @param {string} arg
|
|
682
|
+
* @return {Option}
|
|
683
|
+
* @package
|
|
684
|
+
*/
|
|
685
|
+
_findOption(arg: string): Option | undefined;
|
|
686
|
+
/**
|
|
687
|
+
* Display an error message if a mandatory option does not have a value.
|
|
688
|
+
* Called after checking for help flags in leaf subcommand.
|
|
689
|
+
*
|
|
690
|
+
* @private
|
|
691
|
+
*/
|
|
692
|
+
_checkForMissingMandatoryOptions(): void;
|
|
693
|
+
/**
|
|
694
|
+
* Display an error message if conflicting options are used together in this.
|
|
695
|
+
*
|
|
696
|
+
* @private
|
|
697
|
+
*/
|
|
698
|
+
_checkForConflictingLocalOptions(): void;
|
|
699
|
+
/**
|
|
700
|
+
* Display an error message if conflicting options are used together.
|
|
701
|
+
* Called after checking for help flags in leaf subcommand.
|
|
702
|
+
*
|
|
703
|
+
* @private
|
|
704
|
+
*/
|
|
705
|
+
_checkForConflictingOptions(): void;
|
|
706
|
+
/**
|
|
707
|
+
* Parse options from `argv` removing known options,
|
|
708
|
+
* and return argv split into operands and unknown arguments.
|
|
709
|
+
*
|
|
710
|
+
* Side effects: modifies command by storing options. Does not reset state if called again.
|
|
711
|
+
*
|
|
712
|
+
* Examples:
|
|
713
|
+
*
|
|
714
|
+
* argv => operands, unknown
|
|
715
|
+
* --known kkk op => [op], []
|
|
716
|
+
* op --known kkk => [op], []
|
|
717
|
+
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
718
|
+
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
719
|
+
*
|
|
720
|
+
* @param {string[]} args
|
|
721
|
+
* @return {{operands: string[], unknown: string[]}}
|
|
722
|
+
*/
|
|
723
|
+
parseOptions(args: string[]): ParseOptionsResult;
|
|
724
|
+
/**
|
|
725
|
+
* Return an object containing local option values as key-value pairs.
|
|
726
|
+
*
|
|
727
|
+
* @return {object}
|
|
728
|
+
*/
|
|
729
|
+
opts<T extends OptionValues>(): T;
|
|
730
|
+
/**
|
|
731
|
+
* Return an object containing merged local and global option values as key-value pairs.
|
|
732
|
+
*
|
|
733
|
+
* @return {object}
|
|
734
|
+
*/
|
|
735
|
+
optsWithGlobals<T extends OptionValues>(): T;
|
|
736
|
+
/**
|
|
737
|
+
* Display error message and exit (or call exitOverride).
|
|
738
|
+
*
|
|
739
|
+
* @param {string} message
|
|
740
|
+
* @param {object} [errorOptions]
|
|
741
|
+
* @param {string} [errorOptions.code] - an id string representing the error
|
|
742
|
+
* @param {number} [errorOptions.exitCode] - used with process.exit
|
|
743
|
+
*/
|
|
744
|
+
error(message: string, errorOptions?: ErrorOptions): never;
|
|
745
|
+
/**
|
|
746
|
+
* Apply any option related environment variables, if option does
|
|
747
|
+
* not have a value from cli or client code.
|
|
748
|
+
*
|
|
749
|
+
* @private
|
|
750
|
+
*/
|
|
751
|
+
_parseOptionsEnv(): void;
|
|
752
|
+
/**
|
|
753
|
+
* Apply any implied option values, if option is undefined or default value.
|
|
754
|
+
*
|
|
755
|
+
* @private
|
|
756
|
+
*/
|
|
757
|
+
_parseOptionsImplied(): void;
|
|
758
|
+
/**
|
|
759
|
+
* Argument `name` is missing.
|
|
760
|
+
*
|
|
761
|
+
* @param {string} name
|
|
762
|
+
* @private
|
|
763
|
+
*/
|
|
764
|
+
missingArgument(name: string): void;
|
|
765
|
+
/**
|
|
766
|
+
* `Option` is missing an argument.
|
|
767
|
+
*
|
|
768
|
+
* @param {Option} option
|
|
769
|
+
* @private
|
|
770
|
+
*/
|
|
771
|
+
optionMissingArgument(option: Option): void;
|
|
772
|
+
/**
|
|
773
|
+
* `Option` does not have a value, and is a mandatory option.
|
|
774
|
+
*
|
|
775
|
+
* @param {Option} option
|
|
776
|
+
* @private
|
|
777
|
+
*/
|
|
778
|
+
missingMandatoryOptionValue(option: Option): void;
|
|
779
|
+
/**
|
|
780
|
+
* `Option` conflicts with another option.
|
|
781
|
+
*
|
|
782
|
+
* @param {Option} option
|
|
783
|
+
* @param {Option} conflictingOption
|
|
784
|
+
* @private
|
|
785
|
+
*/
|
|
786
|
+
_conflictingOption(option: Option, conflictingOption: Option): void;
|
|
787
|
+
/**
|
|
788
|
+
* Unknown option `flag`.
|
|
789
|
+
*
|
|
790
|
+
* @param {string} flag
|
|
791
|
+
* @private
|
|
792
|
+
*/
|
|
793
|
+
private unknownOption;
|
|
794
|
+
/**
|
|
795
|
+
* Excess arguments, more than expected.
|
|
796
|
+
*
|
|
797
|
+
* @param {string[]} receivedArgs
|
|
798
|
+
* @private
|
|
799
|
+
*/
|
|
800
|
+
private _excessArguments;
|
|
801
|
+
/**
|
|
802
|
+
* Unknown command.
|
|
803
|
+
*
|
|
804
|
+
* @private
|
|
805
|
+
*/
|
|
806
|
+
private unknownCommand;
|
|
807
|
+
/**
|
|
808
|
+
* Get or set the program version.
|
|
809
|
+
*
|
|
810
|
+
* This method auto-registers the "-V, --version" option which will print the version number.
|
|
811
|
+
*
|
|
812
|
+
* You can optionally supply the flags and description to override the defaults.
|
|
813
|
+
*
|
|
814
|
+
* @param {string} [str]
|
|
815
|
+
* @param {string} [flags]
|
|
816
|
+
* @param {string} [description]
|
|
817
|
+
* @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
|
|
818
|
+
*/
|
|
819
|
+
version(): string | undefined;
|
|
820
|
+
version(str: string, flags?: string, description?: string): this;
|
|
821
|
+
/**
|
|
822
|
+
* Set the description.
|
|
823
|
+
*
|
|
824
|
+
* @param {string} [str]
|
|
825
|
+
* @param {object} [argsDescription]
|
|
826
|
+
* @return {(string|Command)}
|
|
827
|
+
*/
|
|
828
|
+
description(): string;
|
|
829
|
+
description(str: string): this;
|
|
830
|
+
description(str: string, argsDescription: Record<string, string>): this;
|
|
831
|
+
/**
|
|
832
|
+
* Set the summary. Used when listed as subcommand of parent.
|
|
833
|
+
*
|
|
834
|
+
* @param {string} [str]
|
|
835
|
+
* @return {(string|Command)}
|
|
836
|
+
*/
|
|
837
|
+
summary(): string;
|
|
838
|
+
summary(str: string): this;
|
|
839
|
+
/**
|
|
840
|
+
* Set an alias for the command.
|
|
841
|
+
*
|
|
842
|
+
* You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
|
|
843
|
+
*
|
|
844
|
+
* @param {string} [alias]
|
|
845
|
+
* @return {(string|Command)}
|
|
846
|
+
*/
|
|
847
|
+
alias(): string;
|
|
848
|
+
alias(alias: string): this;
|
|
849
|
+
/**
|
|
850
|
+
* Set aliases for the command.
|
|
851
|
+
*
|
|
852
|
+
* Only the first alias is shown in the auto-generated help.
|
|
853
|
+
*
|
|
854
|
+
* @param {string[]} [aliases]
|
|
855
|
+
* @return {(string[]|Command)}
|
|
856
|
+
*/
|
|
857
|
+
aliases(): string[];
|
|
858
|
+
aliases(aliases: readonly string[]): this;
|
|
859
|
+
/**
|
|
860
|
+
* Set / get the command usage `str`.
|
|
861
|
+
*
|
|
862
|
+
* @param {string} [str]
|
|
863
|
+
* @return {(string|Command)}
|
|
864
|
+
*/
|
|
865
|
+
usage(): string;
|
|
866
|
+
usage(str: string): this;
|
|
867
|
+
/**
|
|
868
|
+
* Get or set the name of the command.
|
|
869
|
+
*
|
|
870
|
+
* @param {string} [str]
|
|
871
|
+
* @return {(string|Command)}
|
|
872
|
+
*/
|
|
873
|
+
name(): string;
|
|
874
|
+
name(str: string): this;
|
|
875
|
+
/**
|
|
876
|
+
* Set/get the help group heading for this subcommand in parent command's help.
|
|
877
|
+
*
|
|
878
|
+
* @param {string} [heading]
|
|
879
|
+
* @return {Command | string}
|
|
880
|
+
*/
|
|
881
|
+
helpGroup(): string;
|
|
882
|
+
helpGroup(heading: string): this;
|
|
883
|
+
/**
|
|
884
|
+
* Set/get the default help group heading for subcommands added to this command.
|
|
885
|
+
* (This does not override a group set directly on the subcommand using .helpGroup().)
|
|
886
|
+
*
|
|
887
|
+
* @example
|
|
888
|
+
* program.commandsGroup('Development Commands:);
|
|
889
|
+
* program.command('watch')...
|
|
890
|
+
* program.command('lint')...
|
|
891
|
+
* ...
|
|
892
|
+
*
|
|
893
|
+
* @param {string} [heading]
|
|
894
|
+
* @returns {Command | string}
|
|
895
|
+
*/
|
|
896
|
+
commandsGroup(): string;
|
|
897
|
+
commandsGroup(heading: string): this;
|
|
898
|
+
/**
|
|
899
|
+
* Set/get the default help group heading for options added to this command.
|
|
900
|
+
* (This does not override a group set directly on the option using .helpGroup().)
|
|
901
|
+
*
|
|
902
|
+
* @example
|
|
903
|
+
* program
|
|
904
|
+
* .optionsGroup('Development Options:')
|
|
905
|
+
* .option('-d, --debug', 'output extra debugging')
|
|
906
|
+
* .option('-p, --profile', 'output profiling information')
|
|
907
|
+
*
|
|
908
|
+
* @param {string} [heading]
|
|
909
|
+
* @returns {Command | string}
|
|
910
|
+
*/
|
|
911
|
+
optionsGroup(): string;
|
|
912
|
+
optionsGroup(heading: string): this;
|
|
913
|
+
/**
|
|
914
|
+
* @param {Option} option
|
|
915
|
+
* @private
|
|
916
|
+
*/
|
|
917
|
+
private _initOptionGroup;
|
|
918
|
+
/**
|
|
919
|
+
* @param {Command} cmd
|
|
920
|
+
* @private
|
|
921
|
+
*/
|
|
922
|
+
private _initCommandGroup;
|
|
923
|
+
/**
|
|
924
|
+
* Set the name of the command from script filename, such as process.argv[1],
|
|
925
|
+
* or import.meta.filename.
|
|
926
|
+
*
|
|
927
|
+
* (Used internally and public although not documented in README.)
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* program.nameFromFilename(import.meta.filename);
|
|
931
|
+
*
|
|
932
|
+
* @param {string} filename
|
|
933
|
+
* @return {Command}
|
|
934
|
+
*/
|
|
935
|
+
nameFromFilename(filename: string): this;
|
|
936
|
+
/**
|
|
937
|
+
* Get or set the directory for searching for executable subcommands of this command.
|
|
938
|
+
*
|
|
939
|
+
* @example
|
|
940
|
+
* program.executableDir(import.meta.dirname);
|
|
941
|
+
* // or
|
|
942
|
+
* program.executableDir('subcommands');
|
|
943
|
+
*
|
|
944
|
+
* @param {string} [path]
|
|
945
|
+
* @return {(string|null|Command)}
|
|
946
|
+
*/
|
|
947
|
+
executableDir(): string | null;
|
|
948
|
+
executableDir(path: string): this;
|
|
949
|
+
/**
|
|
950
|
+
* Return program help documentation.
|
|
951
|
+
*
|
|
952
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
|
|
953
|
+
* @return {string}
|
|
954
|
+
*/
|
|
955
|
+
helpInformation(contextOptions?: HelpContext): string;
|
|
956
|
+
/**
|
|
957
|
+
* @typedef HelpContext
|
|
958
|
+
* @type {object}
|
|
959
|
+
* @property {boolean} error
|
|
960
|
+
* @property {number} helpWidth
|
|
961
|
+
* @property {boolean} hasColors
|
|
962
|
+
* @property {function} write - includes stripColor if needed
|
|
963
|
+
*
|
|
964
|
+
* @returns {HelpContext}
|
|
965
|
+
* @private
|
|
966
|
+
*/
|
|
967
|
+
private _getOutputContext;
|
|
968
|
+
/**
|
|
969
|
+
* Output help information for this command.
|
|
970
|
+
*
|
|
971
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
972
|
+
*
|
|
973
|
+
* @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
974
|
+
*/
|
|
975
|
+
outputHelp(cb: (str: string) => string): void;
|
|
976
|
+
outputHelp(context?: HelpContext): void;
|
|
977
|
+
/**
|
|
978
|
+
* You can pass in flags and a description to customise the built-in help option.
|
|
979
|
+
* Pass in false to disable the built-in help option.
|
|
980
|
+
*
|
|
981
|
+
* @example
|
|
982
|
+
* program.helpOption('-?, --help' 'show help'); // customise
|
|
983
|
+
* program.helpOption(false); // disable
|
|
984
|
+
*
|
|
985
|
+
* @param {(string | boolean)} flags
|
|
986
|
+
* @param {string} [description]
|
|
987
|
+
* @return {Command} `this` command for chaining
|
|
988
|
+
*/
|
|
989
|
+
helpOption(flags?: string | boolean, description?: string): this;
|
|
990
|
+
/**
|
|
991
|
+
* Lazy create help option.
|
|
992
|
+
* Returns null if has been disabled with .helpOption(false).
|
|
993
|
+
*
|
|
994
|
+
* @returns {(Option | null)} the help option
|
|
995
|
+
* @package
|
|
996
|
+
*/
|
|
997
|
+
_getHelpOption(): Option | null;
|
|
998
|
+
/**
|
|
999
|
+
* Supply your own option to use for the built-in help option.
|
|
1000
|
+
* This is an alternative to using helpOption() to customise the flags and description etc.
|
|
1001
|
+
*
|
|
1002
|
+
* @param {Option} option
|
|
1003
|
+
* @return {Command} `this` command for chaining
|
|
1004
|
+
*/
|
|
1005
|
+
addHelpOption(option: Option): this;
|
|
1006
|
+
/**
|
|
1007
|
+
* Output help information and exit.
|
|
1008
|
+
*
|
|
1009
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
1010
|
+
*
|
|
1011
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
1012
|
+
*/
|
|
1013
|
+
help(cb: (str: string) => string): never;
|
|
1014
|
+
help(context?: HelpContext): never;
|
|
1015
|
+
/**
|
|
1016
|
+
* // Do a little typing to coordinate emit and listener for the help text events.
|
|
1017
|
+
* @typedef HelpTextEventContext
|
|
1018
|
+
* @type {object}
|
|
1019
|
+
* @property {boolean} error
|
|
1020
|
+
* @property {Command} command
|
|
1021
|
+
* @property {function} write
|
|
1022
|
+
*/
|
|
1023
|
+
/**
|
|
1024
|
+
* Add additional text to be displayed with the built-in help.
|
|
1025
|
+
*
|
|
1026
|
+
* Position is 'before' or 'after' to affect just this command,
|
|
1027
|
+
* and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
|
|
1028
|
+
*
|
|
1029
|
+
* @param {string} position - before or after built-in help
|
|
1030
|
+
* @param {(string | Function)} text - string to add, or a function returning a string
|
|
1031
|
+
* @return {Command} `this` command for chaining
|
|
1032
|
+
*/
|
|
1033
|
+
addHelpText(position: AddHelpTextPosition, text: string): this;
|
|
1034
|
+
addHelpText(position: AddHelpTextPosition, text: (context: AddHelpTextContext) => string): this;
|
|
1035
|
+
/**
|
|
1036
|
+
* Output help information if help flags specified
|
|
1037
|
+
*
|
|
1038
|
+
* @param {Array} args - array of options to search for help flags
|
|
1039
|
+
* @private
|
|
1040
|
+
*/
|
|
1041
|
+
_outputHelpIfRequested(args: Array<string>): void;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Exported for using from tests, not otherwise used outside this file.
|
|
1045
|
+
*
|
|
1046
|
+
* @returns {boolean | undefined}
|
|
1047
|
+
* @package
|
|
1048
|
+
*/
|
|
1049
|
+
export declare function useColor(): boolean | undefined;
|
|
1050
|
+
export {};
|
|
1051
|
+
//# sourceMappingURL=command.d.ts.map
|