@clo4/cli 2.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 +957 -42
- package/dist/index.d.ts +69 -16
- package/dist/index.js +1077 -668
- package/dist/index.js.map +1 -1
- package/dist/testing.d.ts +89 -30
- package/dist/testing.js +1218 -217
- package/dist/testing.js.map +1 -1
- package/package.json +17 -2
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
|
|
@@ -192,12 +219,29 @@ interface Generator {
|
|
|
192
219
|
interface Arg {
|
|
193
220
|
/** Name shown in generated help. */
|
|
194
221
|
name?: string;
|
|
195
|
-
/**
|
|
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
|
+
*/
|
|
196
227
|
description?: string;
|
|
197
228
|
/** Allow this argument to take unlimited values. */
|
|
198
229
|
isVariadic?: true;
|
|
199
230
|
/** Allow this argument to be omitted. */
|
|
200
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;
|
|
201
245
|
/** Completions: complete file or folder paths for this argument. */
|
|
202
246
|
template?: Template;
|
|
203
247
|
/** Completions: static suggestions offered while typing this argument. */
|
|
@@ -206,23 +250,32 @@ interface Arg {
|
|
|
206
250
|
generators?: SingleOrArray<Generator>;
|
|
207
251
|
}
|
|
208
252
|
/** Shells that {@link getCompletion} can generate scripts for. */
|
|
209
|
-
type Shell = "bash" | "zsh" | "fish";
|
|
253
|
+
type Shell = "bash" | "zsh" | "fish" | "powershell" | "nushell";
|
|
210
254
|
/** A subcommand that prints a shell completion script for the whole CLI. */
|
|
211
255
|
export declare const completion: Subcommand;
|
|
212
|
-
/**
|
|
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
|
+
*/
|
|
213
265
|
export declare const helpCommand: Subcommand;
|
|
214
266
|
/** A persistent help option that prints help for the selected command. */
|
|
215
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;
|
|
216
270
|
/**
|
|
217
271
|
* Parse argv and execute the selected action.
|
|
218
272
|
*
|
|
219
|
-
* The
|
|
220
|
-
* actions take precedence so helpers like `--help` can run without
|
|
221
|
-
* 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.
|
|
222
277
|
*/
|
|
223
278
|
export declare function run(spec: Spec, args?: readonly string[]): Promise<number>;
|
|
224
|
-
/** Print `Error:` and the given values to stderr, separated by spaces. */
|
|
225
|
-
export declare function printError(...strings: unknown[]): void;
|
|
226
279
|
declare const _default: {
|
|
227
280
|
completion: Subcommand;
|
|
228
281
|
help: Option;
|