@gunshi/definition 1.0.0-rc.1 → 1.0.0-rc.3

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.
Files changed (2) hide show
  1. package/lib/index.d.ts +29 -7
  2. package/package.json +2 -2
package/lib/index.d.ts CHANGED
@@ -1034,7 +1034,8 @@ interface CommandEnvironment<G extends GunshiParamsConstraint = DefaultGunshiPar
1034
1034
  * The entry command of the CLI, marked with `entry: true`.
1035
1035
  *
1036
1036
  * It is available whether or not the CLI has sub-commands, while {@linkcode CommandEnvironment.subCommands}
1037
- * includes the entry command only when the sub-commands are given with {@linkcode CliOptions.subCommands}.
1037
+ * includes the entry command only when the CLI has sub-commands, given with {@linkcode CliOptions.subCommands}
1038
+ * or with {@linkcode Command.subCommands} of the entry command.
1038
1039
  * It is not frozen, like the commands in {@linkcode CommandEnvironment.subCommands}.
1039
1040
  */
1040
1041
  entryCommand?: Command<any> | LazyCommand<any>;
@@ -1109,8 +1110,11 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1109
1110
  version?: string;
1110
1111
  /**
1111
1112
  * Sub commands.
1113
+ *
1114
+ * An object or a Map keyed by the sub-command names, or an array of commands, which are keyed by their names.
1115
+ * When this is not given, the {@linkcode Command.subCommands} of the entry command are the sub-commands.
1112
1116
  */
1113
- subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable>;
1117
+ subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable> | readonly SubCommandable[];
1114
1118
  /**
1115
1119
  * Left margin of the command output.
1116
1120
  */
@@ -1134,6 +1138,9 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1134
1138
  * Output that must still appear — machine-readable results for an agent, warnings for the
1135
1139
  * CLI author — should use `console.log` / `console.warn`, not `ctx.log`.
1136
1140
  *
1141
+ * The validation errors are not printed either, so `cli()` rejects with them, for the caller to
1142
+ * report them (see {@linkcode CliOptions.renderValidationErrors}).
1143
+ *
1137
1144
  * @default false
1138
1145
  */
1139
1146
  usageSilent?: boolean;
@@ -1157,6 +1164,12 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1157
1164
  renderHeader?: ((ctx: Readonly<CommandContext<G>>) => Promise<string>) | null;
1158
1165
  /**
1159
1166
  * Render function the validation errors.
1167
+ *
1168
+ * With the global options plugin, the rendered message is printed to stderr, the exit code is set
1169
+ * to `1`, {@linkcode CliOptions.onErrorCommand} is called, and `cli()` resolves with `undefined`.
1170
+ * Set it to `null` to report the validation errors yourself: nothing is printed, and `cli()` rejects
1171
+ * with the `AggregateError`. A renderer that returns an empty message, and
1172
+ * {@linkcode CliOptions.usageSilent}, also leave them to the caller.
1160
1173
  */
1161
1174
  renderValidationErrors?: ((ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>) | null;
1162
1175
  /**
@@ -1188,10 +1201,14 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1188
1201
  */
1189
1202
  onAfterCommand?: (ctx: Readonly<CommandContext<G>>, result: string | undefined) => Awaitable<void>;
1190
1203
  /**
1191
- * Hook that runs when a command throws an error
1204
+ * Hook that runs when a command throws an error, or when the arguments fail validation
1205
+ *
1206
+ * For the validation errors that the global options plugin has printed, the exit code is already `1`
1207
+ * when the hook runs, so the hook can set another one, and `cli()` resolves after it. Any other
1208
+ * error rejects `cli()` after the hook.
1192
1209
  *
1193
1210
  * @param ctx - The command context
1194
- * @param error - The error thrown during execution
1211
+ * @param error - The error thrown during execution, or the `AggregateError` of the validation errors
1195
1212
  * @since v0.27.0
1196
1213
  */
1197
1214
  onErrorCommand?: (ctx: Readonly<CommandContext<G>>, error: Error) => Awaitable<void>;
@@ -1360,9 +1377,11 @@ interface RenderingOptions<G extends GunshiParamsConstraint = DefaultGunshiParam
1360
1377
  usage?: ((ctx: Readonly<CommandContext<G>>) => Promise<string>) | null;
1361
1378
  /**
1362
1379
  * Validation errors rendering configuration
1363
- * - `null`: Disable rendering
1380
+ * - `null`: Disable rendering. `cli()` rejects with the validation errors, for the caller to report them
1364
1381
  * - `function`: Use custom renderer
1365
1382
  * - `undefined` (when omitted): Use default renderer
1383
+ *
1384
+ * See {@linkcode CliOptions.renderValidationErrors} for where the rendered message goes.
1366
1385
  */
1367
1386
  validationErrors?: ((ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>) | null;
1368
1387
  }
@@ -1427,10 +1446,13 @@ interface Command<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1427
1446
  *
1428
1447
  * Allows building command trees like `git remote add`.
1429
1448
  * Each key is the sub-command name, and the value is a command or lazy command.
1449
+ * An array of commands is keyed by the names of the commands.
1450
+ *
1451
+ * On the entry command, these are the top-level sub-commands when {@linkcode CliOptions.subCommands} is not given.
1430
1452
  *
1431
1453
  * @since v0.28.0
1432
1454
  */
1433
- subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable>;
1455
+ subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable> | readonly SubCommandable[];
1434
1456
  }
1435
1457
  /**
1436
1458
  * Lazy command interface.
@@ -1507,7 +1529,7 @@ interface SubCommandable {
1507
1529
  * @see {@link Command.subCommands}
1508
1530
  * @since v0.28.0
1509
1531
  */
1510
- subCommands?: Record<string, any> | Map<string, any>;
1532
+ subCommands?: Record<string, any> | Map<string, any> | readonly any[];
1511
1533
  /**
1512
1534
  * Index signature to allow additional properties
1513
1535
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/definition",
3
3
  "description": "utilities for gunshi command definition",
4
- "version": "1.0.0-rc.1",
4
+ "version": "1.0.0-rc.3",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "deno": "^2.7.14",
56
- "gunshi": "1.0.0-rc.1",
56
+ "gunshi": "1.0.0-rc.3",
57
57
  "jsr": "^0.14.3",
58
58
  "jsr-exports-lint": "^0.4.2",
59
59
  "publint": "^0.3.20",