@clo4/cli 2.0.0 → 3.0.1

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
@@ -192,12 +219,29 @@ interface Generator {
192
219
  interface Arg {
193
220
  /** Name shown in generated help. */
194
221
  name?: string;
195
- /** 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
+ */
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. */
@@ -207,6 +251,13 @@ interface Arg {
207
251
  }
208
252
  /** Asserts that required arguments do not come after an optional argument */
209
253
  export declare function assertRequiredArgumentsDoNotFollowOptionalArguments(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;
210
261
  /** Asserts that `isRepeatable` is only assigned a positive integer */
211
262
  export declare function assertRepeatableOptionsArePositiveIntegers(spec: Subcommand): void;
212
263
  /** Asserts that options have unique names in their scope */
@@ -214,12 +265,17 @@ export declare function assertOptionsHaveLocallyUniqueNames(spec: Subcommand): v
214
265
  /** Asserts that options don't shadow a persistent option */
215
266
  export declare function assertOptionsDoNotShadowPersistentOptions(spec: Subcommand): void;
216
267
  /**
217
- * Asserts that a subcommand's option isn't a different option with exactly the
218
- * same names as one on a parent.
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.
219
270
  *
220
- * Parsed values are looked up by name, so that parent's value would be
221
- * unreadable. A shared name is fine when each option has a name of its own, and
222
- * when the options are identical, such as an option kept in a constant.
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.
223
279
  *
224
280
  * This skips persistent parent options, because
225
281
  * {@link assertOptionsDoNotShadowPersistentOptions} covers those and
@@ -228,26 +284,15 @@ export declare function assertOptionsDoNotShadowPersistentOptions(spec: Subcomma
228
284
  export declare function assertOptionsHaveDifferentNamesFromParents(spec: Subcommand): void;
229
285
  /** Asserts that subcommands don't share a name with a sibling subcommand */
230
286
  export declare function assertSubcommandsHaveLocallyUniqueNames(spec: Subcommand): void;
231
- /**
232
- * Asserts that option names starting with a single dash aren't longer
233
- * than two characters, unless parserDirectives.flagsArePosixNoncompliant is
234
- * set on an ancestor command.
235
- */
236
- export declare function assertLongOptionNamesDoNotStartWithSingleDash(spec: Subcommand): void;
237
- /**
238
- * Asserts that all option names start with dashes
239
- */
240
- export declare function assertOptionNamesStartWithDashes(spec: Subcommand): void;
241
- /**
242
- * Asserts that nothing is named exactly '--'
243
- */
244
- export declare function assertNothingIsNamedDashDash(spec: Subcommand): void;
245
287
  /**
246
288
  * Asserts that no option arg separator is an empty string
247
289
  */
248
290
  export declare function assertOptionArgSeparatorsHaveCharacters(spec: Subcommand): void;
249
291
  /**
250
- * 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.
251
296
  */
252
297
  export declare function assertPlusMinusOptionsTakeOneArg(spec: Subcommand): void;
253
298
  /**
@@ -262,11 +307,25 @@ export declare function assertEverythingHasDescription(spec: Subcommand): void;
262
307
  * Asserts that descriptions have line length < 69
263
308
  */
264
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
+ */
265
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;
266
325
  export declare function assertCommonOptionsArePersistent(spec: Subcommand): void;
267
326
  /**
268
327
  * Asserts that references to other options by name actually refer to options
269
- * that exist in scope
328
+ * that exist in scope, at every command the option can be used in
270
329
  */
271
330
  export declare function assertOptionNameReferencesExist(spec: Subcommand): void;
272
331
  /**