@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/dist/testing.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
- /** Get every argument supplied to a option. */
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
- /** Get the first argument supplied to a option. */
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
- /** Count option values, useful for repeatable options. */
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
- choices: readonly string[];
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
- /** Match subcommands by shortest unique prefix instead of exact name. */
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
- /** Require a subcommand; without one, print usage. */
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
- /** Action to run when this command is selected. */
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
- /** Allow this option to be supplied multiple times. */
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
- * Generators run by re-invoking the CLI's hidden `completion
180
- * generate-suggestions` command, so `custom` executes in the CLI's own
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
- /** Description for documentation or future help output. */
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. */
@@ -203,36 +251,48 @@ interface Arg {
203
251
  }
204
252
  /** Asserts that required arguments do not come after an optional argument */
205
253
  export declare function assertRequiredArgumentsDoNotFollowOptionalArguments(spec: Subcommand): void;
206
- /** Asserts that options with `isRepeatable: true` don't have arguments */
207
- export declare function assertRepeatableOptionsHaveNoArguments(spec: Subcommand): void;
254
+ /**
255
+ * Asserts that the parser can use every default. A positional argument with a
256
+ * default must be optional. A required option argument's default is only used
257
+ * when the option is left out, so every argument before it needs a default
258
+ * too, and the option can't be required.
259
+ */
260
+ export declare function assertDefaultsCanBeUsed(spec: Subcommand): void;
208
261
  /** Asserts that `isRepeatable` is only assigned a positive integer */
209
262
  export declare function assertRepeatableOptionsArePositiveIntegers(spec: Subcommand): void;
210
263
  /** Asserts that options have unique names in their scope */
211
264
  export declare function assertOptionsHaveLocallyUniqueNames(spec: Subcommand): void;
212
265
  /** Asserts that options don't shadow a persistent option */
213
266
  export declare function assertOptionsDoNotShadowPersistentOptions(spec: Subcommand): void;
214
- /** Asserts that subcommands don't share a name with a sibling subcommand */
215
- export declare function assertSubcommandsHaveLocallyUniqueNames(spec: Subcommand): void;
216
- /**
217
- * Asserts that option names starting with a single dash aren't longer
218
- * than two characters, unless parserDirectives.flagsArePosixNoncompliant is
219
- * set on an ancestor command.
220
- */
221
- export declare function assertLongOptionNamesDoNotStartWithSingleDash(spec: Subcommand): void;
222
- /**
223
- * Asserts that all option names start with dashes
224
- */
225
- export declare function assertOptionNamesStartWithDashes(spec: Subcommand): void;
226
267
  /**
227
- * Asserts that nothing is named exactly '--'
268
+ * Asserts that when a subcommand's option and a different option on a parent
269
+ * share a name, each of them has a name of its own.
270
+ *
271
+ * Parsed values are looked up by name, and an option sets every one of its
272
+ * names when it's used. If every name of the parent's option is also the
273
+ * subcommand's, using the subcommand's option replaces the parent's value, so
274
+ * it can't be read. If every name of the subcommand's option is also the
275
+ * parent's, its names hold the parent's value when it isn't used, so it can't
276
+ * tell whether it was. Options with the same names are fine when they're
277
+ * identical, such as an option kept in a constant, because the parser treats
278
+ * them as one option.
279
+ *
280
+ * This skips persistent parent options, because
281
+ * {@link assertOptionsDoNotShadowPersistentOptions} covers those and
282
+ * `allowShadowingPersistentOptions` opts out of it.
228
283
  */
229
- export declare function assertNothingIsNamedDashDash(spec: Subcommand): void;
284
+ export declare function assertOptionsHaveDifferentNamesFromParents(spec: Subcommand): void;
285
+ /** Asserts that subcommands don't share a name with a sibling subcommand */
286
+ export declare function assertSubcommandsHaveLocallyUniqueNames(spec: Subcommand): void;
230
287
  /**
231
288
  * Asserts that no option arg separator is an empty string
232
289
  */
233
290
  export declare function assertOptionArgSeparatorsHaveCharacters(spec: Subcommand): void;
234
291
  /**
235
- * Asserts that options named "+" or "-" takes one arg
292
+ * Asserts that the parser reads options named "+" or "-" the way they're
293
+ * written, which needs them to take one argument.
294
+ *
295
+ * @deprecated {@link assertNamesReadBack} checks this for every option.
236
296
  */
237
297
  export declare function assertPlusMinusOptionsTakeOneArg(spec: Subcommand): void;
238
298
  /**
@@ -247,11 +307,25 @@ export declare function assertEverythingHasDescription(spec: Subcommand): void;
247
307
  * Asserts that descriptions have line length < 69
248
308
  */
249
309
  export declare function assertDescriptionLineLengthUnder69(spec: Subcommand): void;
310
+ /**
311
+ * Asserts that the parser reads options with `requiresSeparator` the way
312
+ * they're written, which needs them to take at most one argument.
313
+ *
314
+ * @deprecated {@link assertNamesReadBack} checks this for every option.
315
+ */
250
316
  export declare function assertRequiresSeparatorTakesOneArg(spec: Subcommand): void;
317
+ /**
318
+ * Asserts that the parser reads every name the way it's written: each name of
319
+ * a subcommand enters that subcommand, and each name of an option uses that
320
+ * option, at every command the option can be used in. Each option is also
321
+ * written the way help shows it, with every value it takes, and the parser has
322
+ * to read all of those values as the option's.
323
+ */
324
+ export declare function assertNamesReadBack(spec: Subcommand): void;
251
325
  export declare function assertCommonOptionsArePersistent(spec: Subcommand): void;
252
326
  /**
253
327
  * Asserts that references to other options by name actually refer to options
254
- * that exist in scope
328
+ * that exist in scope, at every command the option can be used in
255
329
  */
256
330
  export declare function assertOptionNameReferencesExist(spec: Subcommand): void;
257
331
  /**