@clo4/cli 1.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +956 -43
- package/dist/index.d.ts +77 -19
- package/dist/index.js +1221 -1288
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +105 -31
- package/dist/testing.js +1236 -324
- package/dist/testing.js.map +1 -1
- package/package.json +17 -3
package/dist/index.d.ts
CHANGED
|
@@ -34,13 +34,22 @@ type CommandPath = readonly [Spec, ...Subcommand[]];
|
|
|
34
34
|
interface OptionArgs {
|
|
35
35
|
/** Escape hatch: the underlying map of option names to values. */
|
|
36
36
|
readonly options: Map<string, string[]>;
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Get every argument supplied to a option, or the defaults of its arguments
|
|
39
|
+
* if it wasn't supplied.
|
|
40
|
+
*/
|
|
38
41
|
all(name: string): string[] | undefined;
|
|
39
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Get the first argument supplied to a option, or the default of its first
|
|
44
|
+
* argument if it wasn't supplied.
|
|
45
|
+
*/
|
|
40
46
|
get(name: string): string | undefined;
|
|
41
|
-
/** Check whether a option was supplied. */
|
|
47
|
+
/** Check whether a option was supplied. Defaults don't count. */
|
|
42
48
|
has(name: string): boolean;
|
|
43
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Count option values, useful for repeatable options. It's 0 for an option
|
|
51
|
+
* that wasn't supplied, even if its arguments have defaults.
|
|
52
|
+
*/
|
|
44
53
|
count(name: string): number;
|
|
45
54
|
}
|
|
46
55
|
/** The data an action receives. */
|
|
@@ -62,7 +71,8 @@ interface ActionInit {
|
|
|
62
71
|
/** Suggest the closest choice for an incorrect input. */
|
|
63
72
|
didYouMean?: {
|
|
64
73
|
input: string;
|
|
65
|
-
|
|
74
|
+
/** Names to suggest. The names in one array are one command or option. */
|
|
75
|
+
choices: readonly (string | readonly string[])[];
|
|
66
76
|
};
|
|
67
77
|
/** Alternative command path to render help for. */
|
|
68
78
|
path?: NonEmptyArray<Subcommand>;
|
|
@@ -99,14 +109,31 @@ interface Subcommand {
|
|
|
99
109
|
optionsMustPrecedeArguments?: boolean;
|
|
100
110
|
/** Separators that can attach a option argument to a option token. */
|
|
101
111
|
optionArgSeparators?: SingleOrArrayOrEmpty<string>;
|
|
102
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* Match subcommands by shortest unique prefix instead of exact name.
|
|
114
|
+
* Hidden subcommands still only match their exact name.
|
|
115
|
+
*/
|
|
103
116
|
subcommandsMatchUniquePrefix?: boolean;
|
|
104
117
|
};
|
|
105
118
|
/** Hide this command from help. */
|
|
106
119
|
hidden?: true;
|
|
107
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* Allow descendant commands to use this command as a subcommand too, like
|
|
122
|
+
* `{ ...helpCommand, isPersistent: true }`. There it only matches its exact
|
|
123
|
+
* name, a descendant's own subcommand with the same name wins, and help
|
|
124
|
+
* doesn't list it. Where a descendant takes positional arguments, its first
|
|
125
|
+
* argument can't be this command's name without `--` before it.
|
|
126
|
+
*/
|
|
127
|
+
isPersistent?: true;
|
|
128
|
+
/**
|
|
129
|
+
* Require a subcommand, so the command takes no arguments. Without a
|
|
130
|
+
* subcommand, the command's action runs, or its help prints if it has none.
|
|
131
|
+
*/
|
|
108
132
|
requiresSubcommand?: true;
|
|
109
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Action to run when this command is selected. A command without an action
|
|
135
|
+
* prints its help.
|
|
136
|
+
*/
|
|
110
137
|
action?: Action;
|
|
111
138
|
/**
|
|
112
139
|
* This property never exists. It prevents accidental structural assignment
|
|
@@ -130,7 +157,12 @@ interface Option {
|
|
|
130
157
|
hidden?: true;
|
|
131
158
|
/** Only allow arguments to be supplied with a separator. */
|
|
132
159
|
requiresSeparator?: true | string;
|
|
133
|
-
/**
|
|
160
|
+
/**
|
|
161
|
+
* Allow this option to be supplied multiple times. `true` allows any number
|
|
162
|
+
* of uses, and a number is the most uses allowed. An option with arguments
|
|
163
|
+
* collects the values from every use, in order. Without arguments, each use
|
|
164
|
+
* adds an empty string, so `count()` returns the number of uses.
|
|
165
|
+
*/
|
|
134
166
|
isRepeatable?: true | number;
|
|
135
167
|
/** Require this option to be supplied before the selected action runs. */
|
|
136
168
|
isRequired?: true;
|
|
@@ -176,9 +208,8 @@ interface Suggestion {
|
|
|
176
208
|
/**
|
|
177
209
|
* Generates dynamic completion suggestions.
|
|
178
210
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* process. Completions only — no effect on parsing.
|
|
211
|
+
* `custom` runs inside the CLI when the shell asks it for completions. It only
|
|
212
|
+
* affects completion and has no effect on parsing.
|
|
182
213
|
*/
|
|
183
214
|
interface Generator {
|
|
184
215
|
/** Produce suggestions from the current command-line tokens. */
|
|
@@ -188,12 +219,29 @@ interface Generator {
|
|
|
188
219
|
interface Arg {
|
|
189
220
|
/** Name shown in generated help. */
|
|
190
221
|
name?: string;
|
|
191
|
-
/**
|
|
222
|
+
/**
|
|
223
|
+
* Description shown in help. A command's positional arguments are listed
|
|
224
|
+
* with their descriptions and defaults. An option argument's description
|
|
225
|
+
* isn't shown.
|
|
226
|
+
*/
|
|
192
227
|
description?: string;
|
|
193
228
|
/** Allow this argument to take unlimited values. */
|
|
194
229
|
isVariadic?: true;
|
|
195
230
|
/** Allow this argument to be omitted. */
|
|
196
231
|
isOptional?: true;
|
|
232
|
+
/**
|
|
233
|
+
* The value used when this argument is left out.
|
|
234
|
+
*
|
|
235
|
+
* - A positional argument's default is added to `args`, so the argument
|
|
236
|
+
* must be optional.
|
|
237
|
+
* - An optional option argument's default is added when the option is used
|
|
238
|
+
* without it, so a bare `--inspect` can mean `--inspect=9229`.
|
|
239
|
+
* - A required option argument's default is what `get` and `all` return
|
|
240
|
+
* when the option isn't used. `has` and `count` still say it wasn't.
|
|
241
|
+
*
|
|
242
|
+
* Help shows an option's defaults after its description.
|
|
243
|
+
*/
|
|
244
|
+
default?: string;
|
|
197
245
|
/** Completions: complete file or folder paths for this argument. */
|
|
198
246
|
template?: Template;
|
|
199
247
|
/** Completions: static suggestions offered while typing this argument. */
|
|
@@ -202,22 +250,32 @@ interface Arg {
|
|
|
202
250
|
generators?: SingleOrArray<Generator>;
|
|
203
251
|
}
|
|
204
252
|
/** Shells that {@link getCompletion} can generate scripts for. */
|
|
205
|
-
type Shell = "bash" | "zsh" | "fish";
|
|
253
|
+
type Shell = "bash" | "zsh" | "fish" | "powershell" | "nushell";
|
|
206
254
|
/** A subcommand that prints a shell completion script for the whole CLI. */
|
|
207
255
|
export declare const completion: Subcommand;
|
|
208
|
-
/**
|
|
256
|
+
/**
|
|
257
|
+
* A subcommand that prints help for its parent, or for the command the names
|
|
258
|
+
* after it lead to from there, so `cli help a b` prints the help of `cli a b`.
|
|
259
|
+
* It reads names until one isn't a subcommand. A token where the command takes
|
|
260
|
+
* arguments, or where it has no subcommands, ends the names, so
|
|
261
|
+
* `cli help completion zsh` prints the help of `completion`. Any other token
|
|
262
|
+
* is an unknown command. Add `{ ...helpCommand, isPersistent: true }` instead
|
|
263
|
+
* to make `cli a b help` work too.
|
|
264
|
+
*/
|
|
209
265
|
export declare const helpCommand: Subcommand;
|
|
210
266
|
/** A persistent help option that prints help for the selected command. */
|
|
211
267
|
export declare const help: Option;
|
|
268
|
+
/** Print `Error:` and the given values to stderr, separated by spaces. */
|
|
269
|
+
export declare function printError(...strings: unknown[]): void;
|
|
212
270
|
/**
|
|
213
271
|
* Parse argv and execute the selected action.
|
|
214
272
|
*
|
|
215
|
-
* The
|
|
216
|
-
* actions take precedence so helpers like `--help` can run without
|
|
217
|
-
* the selected command's required arguments.
|
|
273
|
+
* The selected command's action runs unless a parsed option has an action.
|
|
274
|
+
* Option actions take precedence so helpers like `--help` can run without
|
|
275
|
+
* satisfying the selected command's required arguments. A command without an
|
|
276
|
+
* action prints its help.
|
|
218
277
|
*/
|
|
219
278
|
export declare function run(spec: Spec, args?: readonly string[]): Promise<number>;
|
|
220
|
-
export declare function printError(...strings: unknown[]): void;
|
|
221
279
|
declare const _default: {
|
|
222
280
|
completion: Subcommand;
|
|
223
281
|
help: Option;
|