@gunshi/shared 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 +10 -3
- package/lib/index.js +14 -0
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -871,7 +871,8 @@ interface CommandEnvironment<G extends GunshiParamsConstraint = DefaultGunshiPar
|
|
|
871
871
|
* The entry command of the CLI, marked with `entry: true`.
|
|
872
872
|
*
|
|
873
873
|
* It is available whether or not the CLI has sub-commands, while {@linkcode CommandEnvironment.subCommands}
|
|
874
|
-
* includes the entry command only when the sub-commands
|
|
874
|
+
* includes the entry command only when the CLI has sub-commands, given with {@linkcode CliOptions.subCommands}
|
|
875
|
+
* or with {@linkcode Command.subCommands} of the entry command.
|
|
875
876
|
* It is not frozen, like the commands in {@linkcode CommandEnvironment.subCommands}.
|
|
876
877
|
*/
|
|
877
878
|
entryCommand?: Command<any> | LazyCommand<any>;
|
|
@@ -1125,10 +1126,13 @@ interface Command<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
|
1125
1126
|
*
|
|
1126
1127
|
* Allows building command trees like `git remote add`.
|
|
1127
1128
|
* Each key is the sub-command name, and the value is a command or lazy command.
|
|
1129
|
+
* An array of commands is keyed by the names of the commands.
|
|
1130
|
+
*
|
|
1131
|
+
* On the entry command, these are the top-level sub-commands when {@linkcode CliOptions.subCommands} is not given.
|
|
1128
1132
|
*
|
|
1129
1133
|
* @since v0.28.0
|
|
1130
1134
|
*/
|
|
1131
|
-
subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable
|
|
1135
|
+
subCommands?: Record<string, SubCommandable> | Map<string, SubCommandable> | readonly SubCommandable[];
|
|
1132
1136
|
}
|
|
1133
1137
|
/**
|
|
1134
1138
|
* Lazy command interface.
|
|
@@ -1211,7 +1215,7 @@ interface SubCommandable {
|
|
|
1211
1215
|
* @see {@link Command.subCommands}
|
|
1212
1216
|
* @since v0.28.0
|
|
1213
1217
|
*/
|
|
1214
|
-
subCommands?: Record<string, any> | Map<string, any
|
|
1218
|
+
subCommands?: Record<string, any> | Map<string, any> | readonly any[];
|
|
1215
1219
|
/**
|
|
1216
1220
|
* Index signature to allow additional properties
|
|
1217
1221
|
*/
|
|
@@ -1296,8 +1300,11 @@ declare function log(...args: unknown[]): void;
|
|
|
1296
1300
|
/**
|
|
1297
1301
|
* Get the sub-commands of a command as a normalized Map.
|
|
1298
1302
|
*
|
|
1303
|
+
* An array of sub-commands is keyed by the names of the commands (`commandName` for a lazy command).
|
|
1304
|
+
*
|
|
1299
1305
|
* @param cmd - A command or lazy command
|
|
1300
1306
|
* @returns A Map of sub-commands, or undefined if the command has no sub-commands.
|
|
1307
|
+
* @throws {TypeError} If a command in an array has no name, or two commands in an array have the same name.
|
|
1301
1308
|
*/
|
|
1302
1309
|
declare function getCommandSubCommands<G extends GunshiParamsConstraint = DefaultGunshiParams>(cmd: Commandable<G> | Command<G> | LazyCommand<G>): Map<string, Command<G> | LazyCommand<G>> | undefined;
|
|
1303
1310
|
/**
|
package/lib/index.js
CHANGED
|
@@ -111,13 +111,27 @@ function log(...args) {
|
|
|
111
111
|
/**
|
|
112
112
|
* Get the sub-commands of a command as a normalized Map.
|
|
113
113
|
*
|
|
114
|
+
* An array of sub-commands is keyed by the names of the commands (`commandName` for a lazy command).
|
|
115
|
+
*
|
|
114
116
|
* @param cmd - A command or lazy command
|
|
115
117
|
* @returns A Map of sub-commands, or undefined if the command has no sub-commands.
|
|
118
|
+
* @throws {TypeError} If a command in an array has no name, or two commands in an array have the same name.
|
|
116
119
|
*/
|
|
117
120
|
function getCommandSubCommands(cmd) {
|
|
118
121
|
const subCommands = isLazyCommand(cmd) ? cmd.subCommands : typeof cmd === "object" ? cmd.subCommands : void 0;
|
|
119
122
|
if (!subCommands) return;
|
|
120
123
|
if (subCommands instanceof Map) return subCommands.size > 0 ? subCommands : void 0;
|
|
124
|
+
if (Array.isArray(subCommands)) {
|
|
125
|
+
if (subCommands.length === 0) return;
|
|
126
|
+
const map = /* @__PURE__ */ new Map();
|
|
127
|
+
for (const sub of subCommands) {
|
|
128
|
+
const name = isLazyCommand(sub) ? sub.commandName : sub?.name;
|
|
129
|
+
if (typeof name !== "string" || name === "") throw new TypeError(`Sub-command name must be a non-empty string in an array of 'subCommands'`);
|
|
130
|
+
if (map.has(name)) throw new TypeError(`Sub-command '${name}' is given twice in an array of 'subCommands'`);
|
|
131
|
+
map.set(name, sub);
|
|
132
|
+
}
|
|
133
|
+
return map;
|
|
134
|
+
}
|
|
121
135
|
if (typeof subCommands === "object") {
|
|
122
136
|
const entries = Object.entries(subCommands);
|
|
123
137
|
if (entries.length === 0) return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/shared",
|
|
3
3
|
"description": "shared utils for gunshi",
|
|
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"
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@gunshi/resources": "1.0.0-rc.
|
|
53
|
+
"@gunshi/resources": "1.0.0-rc.3",
|
|
54
54
|
"deno": "^2.7.14",
|
|
55
|
-
"gunshi": "1.0.0-rc.
|
|
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",
|