@gunshi/bone 1.0.0-rc.2 → 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.
- package/lib/index.d.ts +11 -4
- package/lib/index.js +21 -5
- package/package.json +5 -5
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
|
|
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
|
*/
|
|
@@ -1442,10 +1446,13 @@ interface Command<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
|
1442
1446
|
*
|
|
1443
1447
|
* Allows building command trees like `git remote add`.
|
|
1444
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.
|
|
1445
1452
|
*
|
|
1446
1453
|
* @since v0.28.0
|
|
1447
1454
|
*/
|
|
1448
|
-
subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable
|
|
1455
|
+
subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable> | readonly SubCommandable[];
|
|
1449
1456
|
}
|
|
1450
1457
|
/**
|
|
1451
1458
|
* Lazy command interface.
|
|
@@ -1528,7 +1535,7 @@ interface SubCommandable {
|
|
|
1528
1535
|
* @see {@link Command.subCommands}
|
|
1529
1536
|
* @since v0.28.0
|
|
1530
1537
|
*/
|
|
1531
|
-
subCommands?: Record<string, any> | Map<string, any
|
|
1538
|
+
subCommands?: Record<string, any> | Map<string, any> | readonly any[];
|
|
1532
1539
|
/**
|
|
1533
1540
|
* Index signature to allow additional properties
|
|
1534
1541
|
*/
|
package/lib/index.js
CHANGED
|
@@ -1264,13 +1264,27 @@ function log(...args) {
|
|
|
1264
1264
|
/**
|
|
1265
1265
|
* Get the sub-commands of a command as a normalized Map.
|
|
1266
1266
|
*
|
|
1267
|
+
* An array of sub-commands is keyed by the names of the commands (`commandName` for a lazy command).
|
|
1268
|
+
*
|
|
1267
1269
|
* @param cmd - A command or lazy command
|
|
1268
1270
|
* @returns A Map of sub-commands, or undefined if the command has no sub-commands.
|
|
1271
|
+
* @throws {TypeError} If a command in an array has no name, or two commands in an array have the same name.
|
|
1269
1272
|
*/
|
|
1270
1273
|
function getCommandSubCommands(cmd) {
|
|
1271
1274
|
const subCommands = isLazyCommand(cmd) ? cmd.subCommands : typeof cmd === "object" ? cmd.subCommands : void 0;
|
|
1272
1275
|
if (!subCommands) return;
|
|
1273
1276
|
if (subCommands instanceof Map) return subCommands.size > 0 ? subCommands : void 0;
|
|
1277
|
+
if (Array.isArray(subCommands)) {
|
|
1278
|
+
if (subCommands.length === 0) return;
|
|
1279
|
+
const map = /* @__PURE__ */ new Map();
|
|
1280
|
+
for (const sub of subCommands) {
|
|
1281
|
+
const name = isLazyCommand(sub) ? sub.commandName : sub?.name;
|
|
1282
|
+
if (typeof name !== "string" || name === "") throw new TypeError(`Sub-command name must be a non-empty string in an array of 'subCommands'`);
|
|
1283
|
+
if (map.has(name)) throw new TypeError(`Sub-command '${name}' is given twice in an array of 'subCommands'`);
|
|
1284
|
+
map.set(name, sub);
|
|
1285
|
+
}
|
|
1286
|
+
return map;
|
|
1287
|
+
}
|
|
1274
1288
|
if (typeof subCommands === "object") {
|
|
1275
1289
|
const entries = Object.entries(subCommands);
|
|
1276
1290
|
if (entries.length === 0) return;
|
|
@@ -2076,7 +2090,6 @@ function mergeValidationErrors(error, additionalErrors) {
|
|
|
2076
2090
|
if (additionalErrors.length === 0) return error;
|
|
2077
2091
|
return new AggregateError(error ? [...error.errors, ...additionalErrors] : additionalErrors, error?.message || additionalErrors[0]?.message);
|
|
2078
2092
|
}
|
|
2079
|
-
const isObject = (val) => val !== null && typeof val === "object";
|
|
2080
2093
|
/**
|
|
2081
2094
|
* Create the entry command that sub-commands and plugins can see.
|
|
2082
2095
|
* The user-provided entry is copied, so that marking it with `entry: true` does not mutate it.
|
|
@@ -2094,10 +2107,13 @@ function createEntryCommand(entryCmd) {
|
|
|
2094
2107
|
};
|
|
2095
2108
|
}
|
|
2096
2109
|
function createInitialSubCommands(options, entryCommand) {
|
|
2097
|
-
const
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2110
|
+
const subCommands = new Map(getCommandSubCommands({ subCommands: options.subCommands }) ?? []);
|
|
2111
|
+
/**
|
|
2112
|
+
* NOTE(kazupon): `subCommands` works for any command definition, the entry included.
|
|
2113
|
+
* Without sub-commands in the options, the sub-commands of the entry are the top-level ones.
|
|
2114
|
+
*/
|
|
2115
|
+
if (!(subCommands.size > 0) && entryCommand) for (const [name, cmd] of getCommandSubCommands(entryCommand) ?? []) subCommands.set(name, cmd);
|
|
2116
|
+
if (subCommands.size > 0 && entryCommand) subCommands.set(resolveEntryName(entryCommand), entryCommand);
|
|
2101
2117
|
return subCommands;
|
|
2102
2118
|
}
|
|
2103
2119
|
function normalizeCliOptions(options, decorators, pluginContext, entryCommand) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/bone",
|
|
3
3
|
"description": "gunshi minimum",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.3",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@gunshi/definition": "1.0.0-rc.
|
|
55
|
-
"@gunshi/plugin-global": "1.0.0-rc.
|
|
56
|
-
"@gunshi/plugin-renderer": "1.0.0-rc.
|
|
54
|
+
"@gunshi/definition": "1.0.0-rc.3",
|
|
55
|
+
"@gunshi/plugin-global": "1.0.0-rc.3",
|
|
56
|
+
"@gunshi/plugin-renderer": "1.0.0-rc.3",
|
|
57
57
|
"deno": "^2.7.14",
|
|
58
|
-
"gunshi": "1.0.0-rc.
|
|
58
|
+
"gunshi": "1.0.0-rc.3",
|
|
59
59
|
"jsr": "^0.14.3",
|
|
60
60
|
"jsr-exports-lint": "^0.4.2",
|
|
61
61
|
"publint": "^0.3.20",
|