@gunshi/definition 0.27.6 → 0.28.2

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/lib/index.d.ts CHANGED
@@ -1057,6 +1057,15 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
1057
1057
  * The command call mode is `entry` when the command is executed as an entry command, and `subCommand` when the command is executed as a sub-command.
1058
1058
  */
1059
1059
  callMode: CommandCallMode;
1060
+ /**
1061
+ * The path of nested sub-commands that were resolved to reach the current command.
1062
+ *
1063
+ * For example, if the user runs `git remote add`, `commandPath` would be `['remote', 'add']`.
1064
+ * For the entry command, this is an empty array.
1065
+ *
1066
+ * @since v0.28.0
1067
+ */
1068
+ commandPath: string[];
1060
1069
  /**
1061
1070
  * Whether to convert the camel-case style argument name to kebab-case.
1062
1071
  * This context value is set from {@linkcode Command.toKebab} option.
@@ -1198,6 +1207,15 @@ interface Command<G extends GunshiParamsConstraint = DefaultGunshiParams> {
1198
1207
  * @since v0.27.0
1199
1208
  */
1200
1209
  rendering?: RenderingOptions<G>;
1210
+ /**
1211
+ * Nested sub-commands for this command.
1212
+ *
1213
+ * Allows building command trees like `git remote add`.
1214
+ * Each key is the sub-command name, and the value is a command or lazy command.
1215
+ *
1216
+ * @since v0.28.0
1217
+ */
1218
+ subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable>;
1201
1219
  }
1202
1220
  /**
1203
1221
  * Lazy command interface.
@@ -1268,6 +1286,13 @@ interface SubCommandable {
1268
1286
  * see {@link LazyCommand.commandName}
1269
1287
  */
1270
1288
  commandName?: string;
1289
+ /**
1290
+ * Nested sub-commands for this command.
1291
+ *
1292
+ * @see {@link Command.subCommands}
1293
+ * @since v0.28.0
1294
+ */
1295
+ subCommands?: Record<string, any> | Map<string, any>;
1271
1296
  /**
1272
1297
  * Index signature to allow additional properties
1273
1298
  */
@@ -1354,6 +1379,10 @@ interface CommandContextParams<G extends GunshiParams | {
1354
1379
  * Command call mode.
1355
1380
  */
1356
1381
  callMode?: CommandCallMode;
1382
+ /**
1383
+ * The path of nested sub-commands resolved to reach the current command.
1384
+ */
1385
+ commandPath?: string[];
1357
1386
  /**
1358
1387
  * A target command
1359
1388
  */
@@ -1389,6 +1418,7 @@ declare function createCommandContext<G extends GunshiParamsConstraint = Default
1389
1418
  extensions,
1390
1419
  cliOptions,
1391
1420
  callMode,
1421
+ commandPath,
1392
1422
  omitted,
1393
1423
  validationError
1394
1424
  }: CommandContextParams<G, V, C, E>): Promise<{} extends ExtractExtensions<E> ? Readonly<CommandContext<G>> : Readonly<CommandContext<GunshiParams<{
package/lib/index.js CHANGED
@@ -90,7 +90,7 @@ function deepFreeze(obj, ignores = []) {
90
90
  * @param param - A {@link CommandContextParams | parameters} to create a command context.
91
91
  * @returns A {@link CommandContext | command context}, which is readonly.
92
92
  */
93
- async function createCommandContext({ args = {}, explicit = {}, values = {}, positionals = [], rest = [], argv = [], tokens = [], command = {}, extensions = {}, cliOptions = {}, callMode = "entry", omitted = false, validationError = void 0 }) {
93
+ async function createCommandContext({ args = {}, explicit = {}, values = {}, positionals = [], rest = [], argv = [], tokens = [], command = {}, extensions = {}, cliOptions = {}, callMode = "entry", commandPath = [], omitted = false, validationError = void 0 }) {
94
94
  /**
95
95
  * normailize the options schema and values, to avoid prototype pollution
96
96
  */
@@ -119,6 +119,7 @@ async function createCommandContext({ args = {}, explicit = {}, values = {}, pos
119
119
  description: command.description,
120
120
  omitted,
121
121
  callMode,
122
+ commandPath,
122
123
  env,
123
124
  args: _args,
124
125
  explicit,
@@ -219,6 +220,7 @@ function lazy(loader, definition) {
219
220
  lazyCommand.internal = definition.internal;
220
221
  lazyCommand.entry = definition.entry;
221
222
  lazyCommand.toKebab = definition.toKebab;
223
+ if (definition.subCommands) lazyCommand.subCommands = definition.subCommands;
222
224
  if ("resource" in definition) lazyCommand.resource = definition.resource;
223
225
  }
224
226
  return lazyCommand;
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": "0.27.6",
4
+ "version": "0.28.2",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -57,7 +57,7 @@
57
57
  "jsr-exports-lint": "^0.4.1",
58
58
  "publint": "^0.3.16",
59
59
  "tsdown": "0.15.12",
60
- "gunshi": "0.27.6"
60
+ "gunshi": "0.28.2"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsdown",