@gunshi/plugin 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
@@ -1297,7 +1297,8 @@ interface CommandEnvironment<G extends GunshiParamsConstraint = DefaultGunshiPar
1297
1297
  * The entry command of the CLI, marked with `entry: true`.
1298
1298
  *
1299
1299
  * It is available whether or not the CLI has sub-commands, while {@linkcode CommandEnvironment.subCommands}
1300
- * includes the entry command only when the sub-commands are given with {@linkcode CliOptions.subCommands}.
1300
+ * includes the entry command only when the CLI has sub-commands, given with {@linkcode CliOptions.subCommands}
1301
+ * or with {@linkcode Command.subCommands} of the entry command.
1301
1302
  * It is not frozen, like the commands in {@linkcode CommandEnvironment.subCommands}.
1302
1303
  */
1303
1304
  entryCommand?: Command<any> | LazyCommand<any>;
@@ -1372,8 +1373,11 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1372
1373
  version?: string;
1373
1374
  /**
1374
1375
  * Sub commands.
1376
+ *
1377
+ * An object or a Map keyed by the sub-command names, or an array of commands, which are keyed by their names.
1378
+ * When this is not given, the {@linkcode Command.subCommands} of the entry command are the sub-commands.
1375
1379
  */
1376
- subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable>;
1380
+ subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable> | readonly SubCommandable[];
1377
1381
  /**
1378
1382
  * Left margin of the command output.
1379
1383
  */
@@ -1397,6 +1401,9 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1397
1401
  * Output that must still appear — machine-readable results for an agent, warnings for the
1398
1402
  * CLI author — should use `console.log` / `console.warn`, not `ctx.log`.
1399
1403
  *
1404
+ * The validation errors are not printed either, so `cli()` rejects with them, for the caller to
1405
+ * report them (see {@linkcode CliOptions.renderValidationErrors}).
1406
+ *
1400
1407
  * @default false
1401
1408
  */
1402
1409
  usageSilent?: boolean;
@@ -1420,6 +1427,12 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1420
1427
  renderHeader?: ((ctx: Readonly<CommandContext<G>>) => Promise<string>) | null;
1421
1428
  /**
1422
1429
  * Render function the validation errors.
1430
+ *
1431
+ * With the global options plugin, the rendered message is printed to stderr, the exit code is set
1432
+ * to `1`, {@linkcode CliOptions.onErrorCommand} is called, and `cli()` resolves with `undefined`.
1433
+ * Set it to `null` to report the validation errors yourself: nothing is printed, and `cli()` rejects
1434
+ * with the `AggregateError`. A renderer that returns an empty message, and
1435
+ * {@linkcode CliOptions.usageSilent}, also leave them to the caller.
1423
1436
  */
1424
1437
  renderValidationErrors?: ((ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>) | null;
1425
1438
  /**
@@ -1451,10 +1464,14 @@ interface CliOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1451
1464
  */
1452
1465
  onAfterCommand?: (ctx: Readonly<CommandContext<G>>, result: string | undefined) => Awaitable<void>;
1453
1466
  /**
1454
- * Hook that runs when a command throws an error
1467
+ * Hook that runs when a command throws an error, or when the arguments fail validation
1468
+ *
1469
+ * For the validation errors that the global options plugin has printed, the exit code is already `1`
1470
+ * when the hook runs, so the hook can set another one, and `cli()` resolves after it. Any other
1471
+ * error rejects `cli()` after the hook.
1455
1472
  *
1456
1473
  * @param ctx - The command context
1457
- * @param error - The error thrown during execution
1474
+ * @param error - The error thrown during execution, or the `AggregateError` of the validation errors
1458
1475
  * @since v0.27.0
1459
1476
  */
1460
1477
  onErrorCommand?: (ctx: Readonly<CommandContext<G>>, error: Error) => Awaitable<void>;
@@ -1623,9 +1640,11 @@ interface RenderingOptions<G extends GunshiParamsConstraint = DefaultGunshiParam
1623
1640
  usage?: ((ctx: Readonly<CommandContext<G>>) => Promise<string>) | null;
1624
1641
  /**
1625
1642
  * Validation errors rendering configuration
1626
- * - `null`: Disable rendering
1643
+ * - `null`: Disable rendering. `cli()` rejects with the validation errors, for the caller to report them
1627
1644
  * - `function`: Use custom renderer
1628
1645
  * - `undefined` (when omitted): Use default renderer
1646
+ *
1647
+ * See {@linkcode CliOptions.renderValidationErrors} for where the rendered message goes.
1629
1648
  */
1630
1649
  validationErrors?: ((ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>) | null;
1631
1650
  }
@@ -1690,10 +1709,13 @@ interface Command<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1690
1709
  *
1691
1710
  * Allows building command trees like `git remote add`.
1692
1711
  * Each key is the sub-command name, and the value is a command or lazy command.
1712
+ * An array of commands is keyed by the names of the commands.
1713
+ *
1714
+ * On the entry command, these are the top-level sub-commands when {@linkcode CliOptions.subCommands} is not given.
1693
1715
  *
1694
1716
  * @since v0.28.0
1695
1717
  */
1696
- subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable>;
1718
+ subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable> | readonly SubCommandable[];
1697
1719
  }
1698
1720
  /**
1699
1721
  * Lazy command interface.
@@ -1770,7 +1792,7 @@ interface SubCommandable {
1770
1792
  * @see {@link Command.subCommands}
1771
1793
  * @since v0.28.0
1772
1794
  */
1773
- subCommands?: Record<string, any> | Map<string, any>;
1795
+ subCommands?: Record<string, any> | Map<string, any> | readonly any[];
1774
1796
  /**
1775
1797
  * Index signature to allow additional properties
1776
1798
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/plugin",
3
3
  "description": "plugin development kit for gunshi",
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"
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "deno": "^2.7.14",
55
- "gunshi": "1.0.0-rc.1",
55
+ "gunshi": "1.0.0-rc.3",
56
56
  "jsr": "^0.14.3",
57
57
  "jsr-exports-lint": "^0.4.2",
58
58
  "publint": "^0.3.20",