politty 0.4.14 → 0.4.15
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/README.md +7 -1
- package/dist/{arg-registry-r5wYN6qd.d.cts → arg-registry-CB5gGtzp.d.cts} +3 -1
- package/dist/arg-registry-CB5gGtzp.d.cts.map +1 -0
- package/dist/{arg-registry-CkPDokIu.d.ts → arg-registry-Dw0f11Zc.d.ts} +3 -1
- package/dist/arg-registry-Dw0f11Zc.d.ts.map +1 -0
- package/dist/augment.d.cts +1 -1
- package/dist/augment.d.ts +1 -1
- package/dist/completion/index.cjs +1 -1
- package/dist/completion/index.d.cts +1 -1
- package/dist/completion/index.d.ts +1 -1
- package/dist/completion/index.js +1 -1
- package/dist/{completion-CAekGYS4.cjs → completion-B5fgnUGm.cjs} +84 -29
- package/dist/completion-B5fgnUGm.cjs.map +1 -0
- package/dist/{completion-yHz8Pdr7.js → completion-Ca5ESJlG.js} +70 -15
- package/dist/completion-Ca5ESJlG.js.map +1 -0
- package/dist/docs/index.cjs +41 -45
- package/dist/docs/index.cjs.map +1 -1
- package/dist/docs/index.d.cts +5 -1
- package/dist/docs/index.d.cts.map +1 -1
- package/dist/docs/index.d.ts +5 -1
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +34 -38
- package/dist/docs/index.js.map +1 -1
- package/dist/{index-DPswv0Vt.d.cts → index-C1gGgUeB.d.cts} +4 -2
- package/dist/index-C1gGgUeB.d.cts.map +1 -0
- package/dist/{index-BLySW_2k.d.ts → index-Dg9Fpz0R.d.ts} +4 -2
- package/dist/index-Dg9Fpz0R.d.ts.map +1 -0
- package/dist/index.cjs +10 -10
- package/dist/index.d.cts +6 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/{subcommand-router-C9ONv6Nq.cjs → log-collector-Cd2_mv87.cjs} +1 -59
- package/dist/log-collector-Cd2_mv87.cjs.map +1 -0
- package/dist/{subcommand-router--EUt6ftA.js → log-collector-Cu6MCtAx.js} +2 -43
- package/dist/log-collector-Cu6MCtAx.js.map +1 -0
- package/dist/prompt/clack/index.cjs +1 -1
- package/dist/prompt/clack/index.d.cts +1 -1
- package/dist/prompt/clack/index.d.ts +1 -1
- package/dist/prompt/index.d.cts +1 -1
- package/dist/prompt/index.d.ts +1 -1
- package/dist/prompt/inquirer/index.cjs +1 -1
- package/dist/prompt/inquirer/index.d.cts +1 -1
- package/dist/prompt/inquirer/index.d.ts +1 -1
- package/dist/{runner-CY5fOsSh.cjs → runner-CriXJlm4.cjs} +116 -54
- package/dist/runner-CriXJlm4.cjs.map +1 -0
- package/dist/{runner-DSZw1AsW.js → runner-DKAQBNNh.js} +76 -14
- package/dist/runner-DKAQBNNh.js.map +1 -0
- package/dist/{lazy-AGV9Pkt5.cjs → subcommand-router-CqZX3orq.cjs} +108 -2
- package/dist/subcommand-router-CqZX3orq.cjs.map +1 -0
- package/dist/{lazy-DiMJSDMB.js → subcommand-router-ENeCymvX.js} +78 -2
- package/dist/subcommand-router-ENeCymvX.js.map +1 -0
- package/package.json +10 -10
- package/dist/arg-registry-CkPDokIu.d.ts.map +0 -1
- package/dist/arg-registry-r5wYN6qd.d.cts.map +0 -1
- package/dist/completion-CAekGYS4.cjs.map +0 -1
- package/dist/completion-yHz8Pdr7.js.map +0 -1
- package/dist/index-BLySW_2k.d.ts.map +0 -1
- package/dist/index-DPswv0Vt.d.cts.map +0 -1
- package/dist/lazy-AGV9Pkt5.cjs.map +0 -1
- package/dist/lazy-DiMJSDMB.js.map +0 -1
- package/dist/runner-CY5fOsSh.cjs.map +0 -1
- package/dist/runner-DSZw1AsW.js.map +0 -1
- package/dist/subcommand-router--EUt6ftA.js.map +0 -1
- package/dist/subcommand-router-C9ONv6Nq.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const require_log_collector = require('./log-collector-Cd2_mv87.cjs');
|
|
2
|
+
const require_subcommand_router = require('./subcommand-router-CqZX3orq.cjs');
|
|
3
3
|
let node_util = require("node:util");
|
|
4
4
|
let string_width = require("string-width");
|
|
5
|
-
string_width =
|
|
5
|
+
string_width = require_log_collector.__toESM(string_width, 1);
|
|
6
6
|
|
|
7
7
|
//#region src/core/case-proxy.ts
|
|
8
8
|
/**
|
|
@@ -19,9 +19,9 @@ function createDualCaseProxy(obj) {
|
|
|
19
19
|
get(target, prop, receiver) {
|
|
20
20
|
if (typeof prop === "string") {
|
|
21
21
|
if (prop in target) return Reflect.get(target, prop, receiver);
|
|
22
|
-
const camel =
|
|
22
|
+
const camel = require_subcommand_router.toCamelCase(prop);
|
|
23
23
|
if (camel !== prop && camel in target) return Reflect.get(target, camel, receiver);
|
|
24
|
-
const kebab =
|
|
24
|
+
const kebab = require_subcommand_router.toKebabCase(prop);
|
|
25
25
|
if (kebab !== prop && kebab in target) return Reflect.get(target, kebab, receiver);
|
|
26
26
|
}
|
|
27
27
|
return Reflect.get(target, prop, receiver);
|
|
@@ -29,9 +29,9 @@ function createDualCaseProxy(obj) {
|
|
|
29
29
|
has(target, prop) {
|
|
30
30
|
if (typeof prop === "string") {
|
|
31
31
|
if (prop in target) return true;
|
|
32
|
-
const camel =
|
|
32
|
+
const camel = require_subcommand_router.toCamelCase(prop);
|
|
33
33
|
if (camel !== prop && camel in target) return true;
|
|
34
|
-
const kebab =
|
|
34
|
+
const kebab = require_subcommand_router.toKebabCase(prop);
|
|
35
35
|
if (kebab !== prop && kebab in target) return true;
|
|
36
36
|
}
|
|
37
37
|
return Reflect.has(target, prop);
|
|
@@ -56,7 +56,7 @@ function createDualCaseProxy(obj) {
|
|
|
56
56
|
async function executeLifecycle(command, args, _options = {}) {
|
|
57
57
|
let error;
|
|
58
58
|
let result;
|
|
59
|
-
const collector = _options.captureLogs ?? false ?
|
|
59
|
+
const collector = _options.captureLogs ?? false ? require_log_collector.createLogCollector() : null;
|
|
60
60
|
collector?.start();
|
|
61
61
|
const setupContext = { args };
|
|
62
62
|
const cleanupContext = {
|
|
@@ -119,7 +119,7 @@ async function executeLifecycle(command, args, _options = {}) {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
collector?.stop();
|
|
122
|
-
const logs =
|
|
122
|
+
const logs = require_log_collector.mergeLogs(_options.existingLogs ?? require_log_collector.emptyLogs(), collector?.getLogs() ?? require_log_collector.emptyLogs());
|
|
123
123
|
if (error) return {
|
|
124
124
|
success: false,
|
|
125
125
|
error,
|
|
@@ -593,7 +593,7 @@ function renderUsageLine(command, context) {
|
|
|
593
593
|
const name = buildUsageCommandName(command, context);
|
|
594
594
|
parts.push(styles.commandName(name));
|
|
595
595
|
if (context?.globalExtracted?.fields.length) parts.push(styles.placeholder("[global options]"));
|
|
596
|
-
const extracted =
|
|
596
|
+
const extracted = require_subcommand_router.getExtractedFields(command);
|
|
597
597
|
if (extracted) {
|
|
598
598
|
const positionals = extracted.fields.filter((a) => a.positional);
|
|
599
599
|
if (extracted.fields.filter((a) => !a.positional).length > 0) parts.push(styles.placeholder("[options]"));
|
|
@@ -613,9 +613,9 @@ function renderOptions(command, descriptions = {}, context) {
|
|
|
613
613
|
helpAll: descriptions.helpAll ?? defaultBuiltinDescriptions.helpAll,
|
|
614
614
|
version: descriptions.version ?? defaultBuiltinDescriptions.version
|
|
615
615
|
};
|
|
616
|
-
const extracted =
|
|
617
|
-
const hasUserDefinedh = extracted?.fields.some((f) => f.overrideBuiltinAlias === true &&
|
|
618
|
-
const hasUserDefinedH = extracted?.fields.some((f) => f.overrideBuiltinAlias === true &&
|
|
616
|
+
const extracted = require_subcommand_router.getExtractedFields(command);
|
|
617
|
+
const hasUserDefinedh = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && require_subcommand_router.getAllAliases(f).includes("h")) ?? false;
|
|
618
|
+
const hasUserDefinedH = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && require_subcommand_router.getAllAliases(f).includes("H")) ?? false;
|
|
619
619
|
if (hasUserDefinedh) lines.push(formatOption(styles.option("--help"), desc.help));
|
|
620
620
|
else lines.push(formatOption(`${styles.option("-h")}, ${styles.option("--help")}`, desc.help));
|
|
621
621
|
if (hasUserDefinedH) lines.push(formatOption(styles.option("--help-all"), desc.helpAll));
|
|
@@ -816,7 +816,7 @@ function renderGlobalOptions(globalExtracted) {
|
|
|
816
816
|
*/
|
|
817
817
|
function renderSubcommandOptionsCompact(command, indent) {
|
|
818
818
|
const lines = [];
|
|
819
|
-
const extracted =
|
|
819
|
+
const extracted = require_subcommand_router.getExtractedFields(command);
|
|
820
820
|
if (extracted) {
|
|
821
821
|
const options = extracted.fields.filter((a) => !a.positional);
|
|
822
822
|
for (const opt of options) {
|
|
@@ -836,10 +836,12 @@ function renderSubcommandOptionsCompact(command, indent) {
|
|
|
836
836
|
function renderSubcommandsWithOptions(subCommands, parentPath, baseIndent) {
|
|
837
837
|
const lines = [];
|
|
838
838
|
for (const [name, subCmd] of getVisibleSubcommandEntries(subCommands)) {
|
|
839
|
-
const cmd =
|
|
839
|
+
const cmd = require_subcommand_router.resolveSubCommandMeta(subCmd);
|
|
840
840
|
const fullPath = parentPath ? `${parentPath} ${name}` : name;
|
|
841
841
|
const desc = cmd?.description ?? "";
|
|
842
|
-
|
|
842
|
+
const aliases = cmd?.aliases;
|
|
843
|
+
const displayName = aliases && aliases.length > 0 ? `${fullPath}, ${aliases.join(", ")}` : fullPath;
|
|
844
|
+
lines.push(formatOption(styles.command(displayName), desc, baseIndent));
|
|
843
845
|
if (cmd) {
|
|
844
846
|
const optionLines = renderSubcommandOptionsCompact(cmd, baseIndent + 1);
|
|
845
847
|
lines.push(...optionLines);
|
|
@@ -870,7 +872,9 @@ function generateHelp(command, options) {
|
|
|
870
872
|
else if (context?.rootVersion) header += ` ${styles.version(`v${context.rootVersion}`)}`;
|
|
871
873
|
sections.push(header);
|
|
872
874
|
}
|
|
875
|
+
if (context?.aliasFor) sections.push(styles.dim(`Alias for ${styles.commandName(context.aliasFor)}`));
|
|
873
876
|
if (command.description) sections.push(command.description);
|
|
877
|
+
if (!context?.aliasFor && command.aliases && command.aliases.length > 0) sections.push(`${styles.sectionHeader("Aliases:")} ${command.aliases.map((a) => styles.command(a)).join(", ")}`);
|
|
874
878
|
sections.push(`${styles.sectionHeader("Usage:")} ${renderUsageLine(command, context)}`);
|
|
875
879
|
const optionsText = renderOptions(command, options.descriptions, context);
|
|
876
880
|
if (optionsText) sections.push(`${styles.sectionHeader("Options:")}\n${optionsText}`);
|
|
@@ -884,9 +888,12 @@ function generateHelp(command, options) {
|
|
|
884
888
|
} else {
|
|
885
889
|
const subLines = [];
|
|
886
890
|
for (const [name, subCmd] of Object.entries(visibleSubCommands)) {
|
|
887
|
-
const
|
|
891
|
+
const cmd = require_subcommand_router.resolveSubCommandMeta(subCmd);
|
|
892
|
+
const desc = cmd?.description ?? "";
|
|
888
893
|
const fullName = currentPath ? `${currentPath} ${name}` : name;
|
|
889
|
-
|
|
894
|
+
const aliases = cmd?.aliases;
|
|
895
|
+
const displayName = aliases && aliases.length > 0 ? `${fullName}, ${aliases.join(", ")}` : fullName;
|
|
896
|
+
subLines.push(formatOption(styles.command(displayName), desc));
|
|
890
897
|
}
|
|
891
898
|
sections.push(`${styles.sectionHeader("Commands:")}\n${subLines.join("\n")}`);
|
|
892
899
|
}
|
|
@@ -993,7 +1000,7 @@ function checkCaseVariantCollisions(extracted, commandPath) {
|
|
|
993
1000
|
const errors = [];
|
|
994
1001
|
const canonicalMap = /* @__PURE__ */ new Map();
|
|
995
1002
|
for (const field of extracted.fields) {
|
|
996
|
-
const camel =
|
|
1003
|
+
const camel = require_subcommand_router.toCamelCase(field.name);
|
|
997
1004
|
const existing = canonicalMap.get(camel);
|
|
998
1005
|
if (existing && existing !== field.name) errors.push({
|
|
999
1006
|
commandPath,
|
|
@@ -1033,12 +1040,12 @@ function checkDuplicateAliases(extracted, commandPath) {
|
|
|
1033
1040
|
seenAliases.set(alias, fieldName);
|
|
1034
1041
|
};
|
|
1035
1042
|
for (const field of extracted.fields) {
|
|
1036
|
-
const allAliases =
|
|
1043
|
+
const allAliases = require_subcommand_router.getAllAliases(field);
|
|
1037
1044
|
if (allAliases.length === 0) continue;
|
|
1038
1045
|
for (const alias of allAliases) {
|
|
1039
1046
|
registerAlias(alias, field.name, false);
|
|
1040
1047
|
if (alias.length > 1 && alias.includes("-")) {
|
|
1041
|
-
const camelVariant =
|
|
1048
|
+
const camelVariant = require_subcommand_router.toCamelCase(alias);
|
|
1042
1049
|
if (camelVariant !== alias && !fieldNames.has(camelVariant)) registerAlias(camelVariant, field.name, true);
|
|
1043
1050
|
}
|
|
1044
1051
|
}
|
|
@@ -1084,7 +1091,7 @@ function checkReservedAliases(extracted, commandPath) {
|
|
|
1084
1091
|
const errors = [];
|
|
1085
1092
|
for (const field of extracted.fields) {
|
|
1086
1093
|
if (field.overrideBuiltinAlias === true) continue;
|
|
1087
|
-
for (const alias of
|
|
1094
|
+
for (const alias of require_subcommand_router.getAllAliases(field)) if (alias === "h" || alias === "H") errors.push({
|
|
1088
1095
|
commandPath,
|
|
1089
1096
|
type: "reserved_alias",
|
|
1090
1097
|
message: `Alias "${alias}" is reserved for --${alias === "h" ? "help" : "help-all"}.`,
|
|
@@ -1155,7 +1162,7 @@ function validateReservedAliases(extracted, _hasSubCommands) {
|
|
|
1155
1162
|
if (errors.length > 0) {
|
|
1156
1163
|
const field = errors[0].field ?? "unknown";
|
|
1157
1164
|
const found = extracted.fields.find((f) => f.name === field);
|
|
1158
|
-
const alias = (found ?
|
|
1165
|
+
const alias = (found ? require_subcommand_router.getAllAliases(found) : []).find((a) => a === "h" || a === "H") ?? "h";
|
|
1159
1166
|
throw new ReservedAliasError(`Alias "${alias}" is reserved for --${alias === "h" ? "help" : "help-all"}. To override this, set { overrideBuiltinAlias: true } for "${field}" and keep the alias where it is currently defined (in alias or hiddenAlias).`);
|
|
1160
1167
|
}
|
|
1161
1168
|
}
|
|
@@ -1182,9 +1189,9 @@ function validateCaseVariantCollisions(extracted) {
|
|
|
1182
1189
|
*/
|
|
1183
1190
|
function validateCrossSchemaCollisions(extractedA, extractedB) {
|
|
1184
1191
|
const canonicalMap = /* @__PURE__ */ new Map();
|
|
1185
|
-
for (const field of extractedA.fields) canonicalMap.set(
|
|
1192
|
+
for (const field of extractedA.fields) canonicalMap.set(require_subcommand_router.toCamelCase(field.name), field.name);
|
|
1186
1193
|
for (const field of extractedB.fields) {
|
|
1187
|
-
const camel =
|
|
1194
|
+
const camel = require_subcommand_router.toCamelCase(field.name);
|
|
1188
1195
|
const existing = canonicalMap.get(camel);
|
|
1189
1196
|
if (existing && existing !== field.name) throw new CaseVariantCollisionError(`Global field "${existing}" and command field "${field.name}" are case variants of each other and would collide.`);
|
|
1190
1197
|
}
|
|
@@ -1202,6 +1209,57 @@ function collectSchemaErrors(extracted, _hasSubCommands, commandPath) {
|
|
|
1202
1209
|
];
|
|
1203
1210
|
}
|
|
1204
1211
|
/**
|
|
1212
|
+
* Check for alias conflicts within subcommands
|
|
1213
|
+
* - Aliases must not conflict with subcommand names
|
|
1214
|
+
* - Aliases must not conflict with other aliases
|
|
1215
|
+
*/
|
|
1216
|
+
function checkSubCommandAliasConflicts(command, commandPath) {
|
|
1217
|
+
const errors = [];
|
|
1218
|
+
if (!command.subCommands) return errors;
|
|
1219
|
+
const nameToOwner = /* @__PURE__ */ new Map();
|
|
1220
|
+
for (const [name] of Object.entries(command.subCommands)) nameToOwner.set(name, name);
|
|
1221
|
+
for (const [name, subCmdValue] of Object.entries(command.subCommands)) {
|
|
1222
|
+
const resolved = require_subcommand_router.isLazyCommand(subCmdValue) ? subCmdValue.meta : typeof subCmdValue !== "function" ? subCmdValue : null;
|
|
1223
|
+
if (!resolved?.aliases) continue;
|
|
1224
|
+
const subCommandPath = [...commandPath, name];
|
|
1225
|
+
for (const alias of resolved.aliases) {
|
|
1226
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(alias)) {
|
|
1227
|
+
errors.push({
|
|
1228
|
+
commandPath: subCommandPath,
|
|
1229
|
+
type: "invalid_alias",
|
|
1230
|
+
message: `Alias "${alias}" is invalid. Aliases must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores.`,
|
|
1231
|
+
field: name
|
|
1232
|
+
});
|
|
1233
|
+
continue;
|
|
1234
|
+
}
|
|
1235
|
+
if (alias === name) {
|
|
1236
|
+
errors.push({
|
|
1237
|
+
commandPath: subCommandPath,
|
|
1238
|
+
type: "duplicate_alias",
|
|
1239
|
+
message: `Alias "${alias}" conflicts with its own name.`,
|
|
1240
|
+
field: name
|
|
1241
|
+
});
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
const existing = nameToOwner.get(alias);
|
|
1245
|
+
if (existing) if (existing === name) errors.push({
|
|
1246
|
+
commandPath: subCommandPath,
|
|
1247
|
+
type: "duplicate_alias",
|
|
1248
|
+
message: `Alias "${alias}" is duplicated within the alias list.`,
|
|
1249
|
+
field: name
|
|
1250
|
+
});
|
|
1251
|
+
else errors.push({
|
|
1252
|
+
commandPath: subCommandPath,
|
|
1253
|
+
type: "duplicate_alias",
|
|
1254
|
+
message: `Alias "${alias}" conflicts with existing subcommand or alias "${existing}".`,
|
|
1255
|
+
field: name
|
|
1256
|
+
});
|
|
1257
|
+
else nameToOwner.set(alias, name);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
return errors;
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1205
1263
|
* Validate a command and all its subcommands recursively
|
|
1206
1264
|
*
|
|
1207
1265
|
* This function collects all validation errors without throwing,
|
|
@@ -1224,9 +1282,10 @@ async function validateCommand(command, options = {}) {
|
|
|
1224
1282
|
const errors = [];
|
|
1225
1283
|
const hasSubCommands = command.subCommands ? Object.keys(command.subCommands).length > 0 : false;
|
|
1226
1284
|
if (command.args) {
|
|
1227
|
-
const extracted =
|
|
1285
|
+
const extracted = require_subcommand_router.extractFields(command.args);
|
|
1228
1286
|
errors.push(...collectSchemaErrors(extracted, hasSubCommands, commandPath));
|
|
1229
1287
|
}
|
|
1288
|
+
errors.push(...checkSubCommandAliasConflicts(command, commandPath));
|
|
1230
1289
|
if (command.subCommands) for (const [name, subCmd] of Object.entries(command.subCommands)) {
|
|
1231
1290
|
const subResult = await validateCommand(await require_subcommand_router.resolveLazyCommand(subCmd), { commandPath: [...commandPath, name] });
|
|
1232
1291
|
if (!subResult.valid) errors.push(...subResult.errors);
|
|
@@ -1401,14 +1460,14 @@ function buildParserOptions(extracted) {
|
|
|
1401
1460
|
for (const field of extracted.fields) definedNames.add(field.name);
|
|
1402
1461
|
for (const field of extracted.fields) {
|
|
1403
1462
|
if (field.cliName !== field.name) aliasMap.set(field.cliName, field.name);
|
|
1404
|
-
for (const alias of
|
|
1463
|
+
for (const alias of require_subcommand_router.getAllAliases(field)) {
|
|
1405
1464
|
aliasMap.set(alias, field.name);
|
|
1406
1465
|
if (alias.length > 1 && alias.includes("-")) {
|
|
1407
|
-
const camelAlias =
|
|
1466
|
+
const camelAlias = require_subcommand_router.toCamelCase(alias);
|
|
1408
1467
|
if (camelAlias !== alias && !definedNames.has(camelAlias) && !aliasMap.has(camelAlias)) aliasMap.set(camelAlias, field.name);
|
|
1409
1468
|
}
|
|
1410
1469
|
}
|
|
1411
|
-
const camelVariant =
|
|
1470
|
+
const camelVariant = require_subcommand_router.toCamelCase(field.name);
|
|
1412
1471
|
if (camelVariant !== field.name && !definedNames.has(camelVariant) && !aliasMap.has(camelVariant)) aliasMap.set(camelVariant, field.name);
|
|
1413
1472
|
if (field.type === "boolean") booleanFlags.add(field.name);
|
|
1414
1473
|
if (field.type === "array") arrayFlags.add(field.name);
|
|
@@ -1450,7 +1509,7 @@ function mergeWithPositionals(parsed, extracted) {
|
|
|
1450
1509
|
function buildGlobalFlagLookup(globalExtracted) {
|
|
1451
1510
|
const { aliasMap = /* @__PURE__ */ new Map(), booleanFlags = /* @__PURE__ */ new Set() } = buildParserOptions(globalExtracted);
|
|
1452
1511
|
const shortAliases = /* @__PURE__ */ new Set();
|
|
1453
|
-
for (const field of globalExtracted.fields) for (const alias of
|
|
1512
|
+
for (const field of globalExtracted.fields) for (const alias of require_subcommand_router.getAllAliases(field)) if (alias.length === 1) shortAliases.add(alias);
|
|
1454
1513
|
return {
|
|
1455
1514
|
aliasMap,
|
|
1456
1515
|
booleanFlags,
|
|
@@ -1599,7 +1658,8 @@ function findFirstPositional(argv, globalExtracted) {
|
|
|
1599
1658
|
* @returns Parse result
|
|
1600
1659
|
*/
|
|
1601
1660
|
function parseArgs(argv, command, options = {}) {
|
|
1602
|
-
const
|
|
1661
|
+
const subCommandNameSet = require_subcommand_router.listSubCommandNamesWithAliases(command);
|
|
1662
|
+
const subCommandNames = [...subCommandNameSet];
|
|
1603
1663
|
const hasSubCommands = subCommandNames.length > 0;
|
|
1604
1664
|
if (hasSubCommands && argv.length > 0) if (options.globalExtracted) {
|
|
1605
1665
|
const scanResult = scanForSubcommand(argv, subCommandNames, options.globalExtracted);
|
|
@@ -1619,7 +1679,7 @@ function parseArgs(argv, command, options = {}) {
|
|
|
1619
1679
|
}
|
|
1620
1680
|
} else {
|
|
1621
1681
|
const firstArg = argv[0];
|
|
1622
|
-
if (firstArg && !firstArg.startsWith("-") &&
|
|
1682
|
+
if (firstArg && !firstArg.startsWith("-") && subCommandNameSet.has(firstArg)) return {
|
|
1623
1683
|
helpRequested: false,
|
|
1624
1684
|
helpAllRequested: false,
|
|
1625
1685
|
versionRequested: false,
|
|
@@ -1632,7 +1692,7 @@ function parseArgs(argv, command, options = {}) {
|
|
|
1632
1692
|
}
|
|
1633
1693
|
let extracted;
|
|
1634
1694
|
if (command.args) {
|
|
1635
|
-
extracted =
|
|
1695
|
+
extracted = require_subcommand_router.extractFields(command.args);
|
|
1636
1696
|
if (!options.skipValidation) {
|
|
1637
1697
|
validateDuplicateFields(extracted);
|
|
1638
1698
|
validateCaseVariantCollisions(extracted);
|
|
@@ -1642,8 +1702,8 @@ function parseArgs(argv, command, options = {}) {
|
|
|
1642
1702
|
if (options.globalExtracted) validateCrossSchemaCollisions(options.globalExtracted, extracted);
|
|
1643
1703
|
}
|
|
1644
1704
|
}
|
|
1645
|
-
const hasUserDefinedH = extracted?.fields.some((f) => f.overrideBuiltinAlias === true &&
|
|
1646
|
-
const hasUserDefinedh = extracted?.fields.some((f) => f.overrideBuiltinAlias === true &&
|
|
1705
|
+
const hasUserDefinedH = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && require_subcommand_router.getAllAliases(f).includes("H")) ?? false;
|
|
1706
|
+
const hasUserDefinedh = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && require_subcommand_router.getAllAliases(f).includes("h")) ?? false;
|
|
1647
1707
|
const helpAllRequested = argv.includes("--help-all") || !hasUserDefinedH && argv.includes("-H");
|
|
1648
1708
|
const helpRequested = !helpAllRequested && (argv.includes("--help") || !hasUserDefinedh && argv.includes("-h"));
|
|
1649
1709
|
const versionRequested = argv.includes("--version");
|
|
@@ -1691,11 +1751,11 @@ function parseArgs(argv, command, options = {}) {
|
|
|
1691
1751
|
const knownFlags = new Set(extracted.fields.map((f) => f.name));
|
|
1692
1752
|
const knownCliNames = new Set(extracted.fields.map((f) => f.cliName));
|
|
1693
1753
|
const knownAliases = /* @__PURE__ */ new Set();
|
|
1694
|
-
for (const f of extracted.fields) for (const alias of
|
|
1754
|
+
for (const f of extracted.fields) for (const alias of require_subcommand_router.getAllAliases(f)) knownAliases.add(alias);
|
|
1695
1755
|
if (options.globalExtracted) for (const f of options.globalExtracted.fields) {
|
|
1696
1756
|
knownFlags.add(f.name);
|
|
1697
1757
|
knownCliNames.add(f.cliName);
|
|
1698
|
-
for (const alias of
|
|
1758
|
+
for (const alias of require_subcommand_router.getAllAliases(f)) knownAliases.add(alias);
|
|
1699
1759
|
}
|
|
1700
1760
|
const unknownFlags = [];
|
|
1701
1761
|
for (const key of Object.keys(parsed.options)) if (!knownFlags.has(key) && !knownCliNames.has(key) && !knownAliases.has(key)) unknownFlags.push(key);
|
|
@@ -1887,7 +1947,7 @@ async function runEffects(validatedArgs, extracted, globalArgs) {
|
|
|
1887
1947
|
|
|
1888
1948
|
//#endregion
|
|
1889
1949
|
//#region src/core/runner.ts
|
|
1890
|
-
var runner_exports = /* @__PURE__ */
|
|
1950
|
+
var runner_exports = /* @__PURE__ */ require_log_collector.__exportAll({
|
|
1891
1951
|
runCommand: () => runCommand,
|
|
1892
1952
|
runMain: () => runMain
|
|
1893
1953
|
});
|
|
@@ -1927,7 +1987,7 @@ const defaultLogger = {
|
|
|
1927
1987
|
async function runCommand(command, argv, options = {}) {
|
|
1928
1988
|
const globalExtracted = extractAndValidateGlobal(options);
|
|
1929
1989
|
const shouldCaptureLogs = options.captureLogs ?? false;
|
|
1930
|
-
const globalCollector = shouldCaptureLogs ?
|
|
1990
|
+
const globalCollector = shouldCaptureLogs ? require_log_collector.createLogCollector() : null;
|
|
1931
1991
|
if (options.setup) {
|
|
1932
1992
|
globalCollector?.start();
|
|
1933
1993
|
try {
|
|
@@ -1942,7 +2002,7 @@ async function runCommand(command, argv, options = {}) {
|
|
|
1942
2002
|
success: false,
|
|
1943
2003
|
error,
|
|
1944
2004
|
exitCode: 1,
|
|
1945
|
-
logs: globalCollector?.getLogs() ??
|
|
2005
|
+
logs: globalCollector?.getLogs() ?? require_log_collector.emptyLogs()
|
|
1946
2006
|
};
|
|
1947
2007
|
}
|
|
1948
2008
|
globalCollector?.stop();
|
|
@@ -1955,7 +2015,7 @@ async function runCommand(command, argv, options = {}) {
|
|
|
1955
2015
|
_existingLogs: globalCollector?.getLogs()
|
|
1956
2016
|
});
|
|
1957
2017
|
if (options.cleanup) {
|
|
1958
|
-
const cleanupCollector = shouldCaptureLogs ?
|
|
2018
|
+
const cleanupCollector = shouldCaptureLogs ? require_log_collector.createLogCollector() : null;
|
|
1959
2019
|
cleanupCollector?.start();
|
|
1960
2020
|
const cleanupCtx = { error: !result.success ? result.error : void 0 };
|
|
1961
2021
|
try {
|
|
@@ -1968,15 +2028,15 @@ async function runCommand(command, argv, options = {}) {
|
|
|
1968
2028
|
success: false,
|
|
1969
2029
|
error,
|
|
1970
2030
|
exitCode: 1,
|
|
1971
|
-
logs:
|
|
2031
|
+
logs: require_log_collector.mergeLogs(result.logs, cleanupCollector?.getLogs() ?? require_log_collector.emptyLogs())
|
|
1972
2032
|
};
|
|
1973
2033
|
}
|
|
1974
2034
|
}
|
|
1975
2035
|
cleanupCollector?.stop();
|
|
1976
|
-
const cleanupLogs = cleanupCollector?.getLogs() ??
|
|
2036
|
+
const cleanupLogs = cleanupCollector?.getLogs() ?? require_log_collector.emptyLogs();
|
|
1977
2037
|
if (cleanupLogs.entries.length > 0) return {
|
|
1978
2038
|
...result,
|
|
1979
|
-
logs:
|
|
2039
|
+
logs: require_log_collector.mergeLogs(result.logs, cleanupLogs)
|
|
1980
2040
|
};
|
|
1981
2041
|
}
|
|
1982
2042
|
return result;
|
|
@@ -2053,10 +2113,10 @@ async function runCommandInternal(command, argv, options = {}) {
|
|
|
2053
2113
|
rootName: command.name,
|
|
2054
2114
|
globalExtracted: options._globalExtracted
|
|
2055
2115
|
};
|
|
2056
|
-
const collector = options.captureLogs ?? false ?
|
|
2116
|
+
const collector = options.captureLogs ?? false ? require_log_collector.createLogCollector() : null;
|
|
2057
2117
|
collector?.start();
|
|
2058
2118
|
const getCurrentLogs = () => {
|
|
2059
|
-
return
|
|
2119
|
+
return require_log_collector.mergeLogs(options._existingLogs ?? require_log_collector.emptyLogs(), collector?.getLogs() ?? require_log_collector.emptyLogs());
|
|
2060
2120
|
};
|
|
2061
2121
|
try {
|
|
2062
2122
|
const parseResult = parseArgs(argv, command, {
|
|
@@ -2070,9 +2130,10 @@ async function runCommandInternal(command, argv, options = {}) {
|
|
|
2070
2130
|
if (parseResult.helpRequested || parseResult.helpAllRequested) {
|
|
2071
2131
|
let hasUnknownSubcommand = false;
|
|
2072
2132
|
const subCmdNames = require_subcommand_router.listSubCommands(command);
|
|
2133
|
+
const allSubCmdNameSet = require_subcommand_router.listSubCommandNamesWithAliases(command);
|
|
2073
2134
|
if (subCmdNames.length > 0) {
|
|
2074
2135
|
const potentialSubCmd = findFirstPositional(argv, context.globalExtracted);
|
|
2075
|
-
if (potentialSubCmd && !
|
|
2136
|
+
if (potentialSubCmd && !allSubCmdNameSet.has(potentialSubCmd)) hasUnknownSubcommand = true;
|
|
2076
2137
|
}
|
|
2077
2138
|
const help = generateHelp(command, {
|
|
2078
2139
|
showSubcommands: options.showSubcommands ?? true,
|
|
@@ -2083,7 +2144,7 @@ async function runCommandInternal(command, argv, options = {}) {
|
|
|
2083
2144
|
collector?.stop();
|
|
2084
2145
|
if (hasUnknownSubcommand) {
|
|
2085
2146
|
const unknownCmd = findFirstPositional(argv, context.globalExtracted) ?? "";
|
|
2086
|
-
const similar = findSimilar(unknownCmd,
|
|
2147
|
+
const similar = findSimilar(unknownCmd, [...allSubCmdNameSet]);
|
|
2087
2148
|
const suggestion = similar.length > 0 ? ` Did you mean: ${similar.join(", ")}?` : "";
|
|
2088
2149
|
return {
|
|
2089
2150
|
success: false,
|
|
@@ -2111,16 +2172,17 @@ async function runCommandInternal(command, argv, options = {}) {
|
|
|
2111
2172
|
};
|
|
2112
2173
|
}
|
|
2113
2174
|
if (parseResult.subCommand) {
|
|
2114
|
-
const
|
|
2115
|
-
if (
|
|
2175
|
+
const resolved = await require_subcommand_router.resolveSubcommandWithAlias(command, parseResult.subCommand);
|
|
2176
|
+
if (resolved) {
|
|
2116
2177
|
const subContext = {
|
|
2117
2178
|
commandPath: [...context.commandPath ?? [], parseResult.subCommand],
|
|
2118
2179
|
rootName: context.rootName,
|
|
2119
2180
|
rootVersion: context.rootVersion,
|
|
2120
|
-
globalExtracted: context.globalExtracted
|
|
2181
|
+
globalExtracted: context.globalExtracted,
|
|
2182
|
+
aliasFor: resolved.aliasFor
|
|
2121
2183
|
};
|
|
2122
2184
|
collector?.stop();
|
|
2123
|
-
return runCommandInternal(
|
|
2185
|
+
return runCommandInternal(resolved.command, parseResult.remainingArgs, {
|
|
2124
2186
|
...options,
|
|
2125
2187
|
_context: subContext,
|
|
2126
2188
|
_existingLogs: getCurrentLogs(),
|
|
@@ -2245,7 +2307,7 @@ async function runCommandInternal(command, argv, options = {}) {
|
|
|
2245
2307
|
*/
|
|
2246
2308
|
function extractAndValidateGlobal(options) {
|
|
2247
2309
|
if (!options.globalArgs) return void 0;
|
|
2248
|
-
const extracted =
|
|
2310
|
+
const extracted = require_subcommand_router.extractFields(options.globalArgs);
|
|
2249
2311
|
if (!options.skipValidation) {
|
|
2250
2312
|
validateDuplicateFields(extracted);
|
|
2251
2313
|
validateCaseVariantCollisions(extracted);
|
|
@@ -2420,4 +2482,4 @@ Object.defineProperty(exports, 'validateReservedAliases', {
|
|
|
2420
2482
|
return validateReservedAliases;
|
|
2421
2483
|
}
|
|
2422
2484
|
});
|
|
2423
|
-
//# sourceMappingURL=runner-
|
|
2485
|
+
//# sourceMappingURL=runner-CriXJlm4.cjs.map
|