politty 0.4.13 → 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.
Files changed (68) hide show
  1. package/README.md +7 -1
  2. package/dist/{arg-registry-CeIRoLaB.d.cts → arg-registry-CB5gGtzp.d.cts} +55 -14
  3. package/dist/arg-registry-CB5gGtzp.d.cts.map +1 -0
  4. package/dist/{arg-registry-6E4C5MTC.d.ts → arg-registry-Dw0f11Zc.d.ts} +55 -14
  5. package/dist/arg-registry-Dw0f11Zc.d.ts.map +1 -0
  6. package/dist/augment.d.cts +3 -2
  7. package/dist/augment.d.cts.map +1 -1
  8. package/dist/augment.d.ts +3 -2
  9. package/dist/augment.d.ts.map +1 -1
  10. package/dist/completion/index.cjs +1 -1
  11. package/dist/completion/index.d.cts +1 -1
  12. package/dist/completion/index.d.ts +1 -1
  13. package/dist/completion/index.js +1 -1
  14. package/dist/{completion-D3LUac1o.cjs → completion-B5fgnUGm.cjs} +103 -38
  15. package/dist/completion-B5fgnUGm.cjs.map +1 -0
  16. package/dist/{completion-DzaT2YCN.js → completion-Ca5ESJlG.js} +91 -26
  17. package/dist/completion-Ca5ESJlG.js.map +1 -0
  18. package/dist/docs/index.cjs +59 -50
  19. package/dist/docs/index.cjs.map +1 -1
  20. package/dist/docs/index.d.cts +5 -1
  21. package/dist/docs/index.d.cts.map +1 -1
  22. package/dist/docs/index.d.ts +5 -1
  23. package/dist/docs/index.d.ts.map +1 -1
  24. package/dist/docs/index.js +52 -43
  25. package/dist/docs/index.js.map +1 -1
  26. package/dist/{index-C3UtsvgY.d.ts → index-C1gGgUeB.d.cts} +9 -4
  27. package/dist/index-C1gGgUeB.d.cts.map +1 -0
  28. package/dist/{index-BW02tH1-.d.cts → index-Dg9Fpz0R.d.ts} +9 -4
  29. package/dist/index-Dg9Fpz0R.d.ts.map +1 -0
  30. package/dist/index.cjs +10 -10
  31. package/dist/index.d.cts +6 -3
  32. package/dist/index.d.cts.map +1 -1
  33. package/dist/index.d.ts +6 -3
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +3 -3
  36. package/dist/{subcommand-router-BnHpqyRk.cjs → log-collector-Cd2_mv87.cjs} +1 -59
  37. package/dist/log-collector-Cd2_mv87.cjs.map +1 -0
  38. package/dist/{subcommand-router-BhYVuS83.js → log-collector-Cu6MCtAx.js} +2 -43
  39. package/dist/log-collector-Cu6MCtAx.js.map +1 -0
  40. package/dist/prompt/clack/index.cjs +1 -1
  41. package/dist/prompt/clack/index.d.cts +1 -1
  42. package/dist/prompt/clack/index.d.ts +1 -1
  43. package/dist/prompt/index.d.cts +1 -1
  44. package/dist/prompt/index.d.ts +1 -1
  45. package/dist/prompt/inquirer/index.cjs +1 -1
  46. package/dist/prompt/inquirer/index.d.cts +1 -1
  47. package/dist/prompt/inquirer/index.d.ts +1 -1
  48. package/dist/{runner-DA48D-3K.cjs → runner-CriXJlm4.cjs} +176 -74
  49. package/dist/runner-CriXJlm4.cjs.map +1 -0
  50. package/dist/{runner-CnG-Ncz0.js → runner-DKAQBNNh.js} +149 -47
  51. package/dist/runner-DKAQBNNh.js.map +1 -0
  52. package/dist/{lazy-qPy4cMnv.cjs → subcommand-router-CqZX3orq.cjs} +140 -3
  53. package/dist/subcommand-router-CqZX3orq.cjs.map +1 -0
  54. package/dist/{lazy-xrzxwnru.js → subcommand-router-ENeCymvX.js} +104 -3
  55. package/dist/subcommand-router-ENeCymvX.js.map +1 -0
  56. package/package.json +12 -12
  57. package/dist/arg-registry-6E4C5MTC.d.ts.map +0 -1
  58. package/dist/arg-registry-CeIRoLaB.d.cts.map +0 -1
  59. package/dist/completion-D3LUac1o.cjs.map +0 -1
  60. package/dist/completion-DzaT2YCN.js.map +0 -1
  61. package/dist/index-BW02tH1-.d.cts.map +0 -1
  62. package/dist/index-C3UtsvgY.d.ts.map +0 -1
  63. package/dist/lazy-qPy4cMnv.cjs.map +0 -1
  64. package/dist/lazy-xrzxwnru.js.map +0 -1
  65. package/dist/runner-CnG-Ncz0.js.map +0 -1
  66. package/dist/runner-DA48D-3K.cjs.map +0 -1
  67. package/dist/subcommand-router-BhYVuS83.js.map +0 -1
  68. package/dist/subcommand-router-BnHpqyRk.cjs.map +0 -1
@@ -1,8 +1,8 @@
1
- const require_subcommand_router = require('./subcommand-router-BnHpqyRk.cjs');
2
- const require_lazy = require('./lazy-qPy4cMnv.cjs');
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 = require_subcommand_router.__toESM(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 = require_lazy.toCamelCase(prop);
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 = require_lazy.toKebabCase(prop);
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 = require_lazy.toCamelCase(prop);
32
+ const camel = require_subcommand_router.toCamelCase(prop);
33
33
  if (camel !== prop && camel in target) return true;
34
- const kebab = require_lazy.toKebabCase(prop);
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 ? require_subcommand_router.createLogCollector() : null;
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 = require_subcommand_router.mergeLogs(_options.existingLogs ?? require_subcommand_router.emptyLogs(), collector?.getLogs() ?? require_subcommand_router.emptyLogs());
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 = require_lazy.getExtractedFields(command);
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 = require_lazy.getExtractedFields(command);
617
- const hasUserDefinedh = extracted?.fields.some((f) => f.alias === "h" && f.overrideBuiltinAlias === true) ?? false;
618
- const hasUserDefinedH = extracted?.fields.some((f) => f.alias === "H" && f.overrideBuiltinAlias === true) ?? false;
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));
@@ -738,13 +738,25 @@ function renderUnionOptions(extracted, _command, lines) {
738
738
  */
739
739
  function formatFlags(opt) {
740
740
  const parts = [];
741
- if (opt.alias) parts.push(styles.option(`-${opt.alias}`));
741
+ if (opt.alias) {
742
+ for (const alias of opt.alias) if (alias.length === 1) parts.push(styles.option(`-${alias}`));
743
+ }
742
744
  let longFlag = styles.option(`--${opt.cliName}`);
743
745
  if (opt.type !== "boolean") {
744
746
  const placeholder = opt.placeholder ?? opt.cliName.toUpperCase();
745
747
  longFlag += ` ${styles.placeholder(`<${placeholder}>`)}`;
746
748
  }
747
749
  parts.push(longFlag);
750
+ if (opt.alias) {
751
+ for (const alias of opt.alias) if (alias.length > 1) {
752
+ let longAlias = styles.option(`--${alias}`);
753
+ if (opt.type !== "boolean") {
754
+ const placeholder = opt.placeholder ?? opt.cliName.toUpperCase();
755
+ longAlias += ` ${styles.placeholder(`<${placeholder}>`)}`;
756
+ }
757
+ parts.push(longAlias);
758
+ }
759
+ }
748
760
  return parts.join(", ");
749
761
  }
750
762
  /**
@@ -804,7 +816,7 @@ function renderGlobalOptions(globalExtracted) {
804
816
  */
805
817
  function renderSubcommandOptionsCompact(command, indent) {
806
818
  const lines = [];
807
- const extracted = require_lazy.getExtractedFields(command);
819
+ const extracted = require_subcommand_router.getExtractedFields(command);
808
820
  if (extracted) {
809
821
  const options = extracted.fields.filter((a) => !a.positional);
810
822
  for (const opt of options) {
@@ -824,10 +836,12 @@ function renderSubcommandOptionsCompact(command, indent) {
824
836
  function renderSubcommandsWithOptions(subCommands, parentPath, baseIndent) {
825
837
  const lines = [];
826
838
  for (const [name, subCmd] of getVisibleSubcommandEntries(subCommands)) {
827
- const cmd = require_lazy.resolveSubCommandMeta(subCmd);
839
+ const cmd = require_subcommand_router.resolveSubCommandMeta(subCmd);
828
840
  const fullPath = parentPath ? `${parentPath} ${name}` : name;
829
841
  const desc = cmd?.description ?? "";
830
- lines.push(formatOption(styles.command(fullPath), desc, baseIndent));
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));
831
845
  if (cmd) {
832
846
  const optionLines = renderSubcommandOptionsCompact(cmd, baseIndent + 1);
833
847
  lines.push(...optionLines);
@@ -858,7 +872,9 @@ function generateHelp(command, options) {
858
872
  else if (context?.rootVersion) header += ` ${styles.version(`v${context.rootVersion}`)}`;
859
873
  sections.push(header);
860
874
  }
875
+ if (context?.aliasFor) sections.push(styles.dim(`Alias for ${styles.commandName(context.aliasFor)}`));
861
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(", ")}`);
862
878
  sections.push(`${styles.sectionHeader("Usage:")} ${renderUsageLine(command, context)}`);
863
879
  const optionsText = renderOptions(command, options.descriptions, context);
864
880
  if (optionsText) sections.push(`${styles.sectionHeader("Options:")}\n${optionsText}`);
@@ -872,9 +888,12 @@ function generateHelp(command, options) {
872
888
  } else {
873
889
  const subLines = [];
874
890
  for (const [name, subCmd] of Object.entries(visibleSubCommands)) {
875
- const desc = require_lazy.resolveSubCommandMeta(subCmd)?.description ?? "";
891
+ const cmd = require_subcommand_router.resolveSubCommandMeta(subCmd);
892
+ const desc = cmd?.description ?? "";
876
893
  const fullName = currentPath ? `${currentPath} ${name}` : name;
877
- subLines.push(formatOption(styles.command(fullName), desc));
894
+ const aliases = cmd?.aliases;
895
+ const displayName = aliases && aliases.length > 0 ? `${fullName}, ${aliases.join(", ")}` : fullName;
896
+ subLines.push(formatOption(styles.command(displayName), desc));
878
897
  }
879
898
  sections.push(`${styles.sectionHeader("Commands:")}\n${subLines.join("\n")}`);
880
899
  }
@@ -981,7 +1000,7 @@ function checkCaseVariantCollisions(extracted, commandPath) {
981
1000
  const errors = [];
982
1001
  const canonicalMap = /* @__PURE__ */ new Map();
983
1002
  for (const field of extracted.fields) {
984
- const camel = require_lazy.toCamelCase(field.name);
1003
+ const camel = require_subcommand_router.toCamelCase(field.name);
985
1004
  const existing = canonicalMap.get(camel);
986
1005
  if (existing && existing !== field.name) errors.push({
987
1006
  commandPath,
@@ -1000,22 +1019,36 @@ function checkDuplicateAliases(extracted, commandPath) {
1000
1019
  const errors = [];
1001
1020
  const seenAliases = /* @__PURE__ */ new Map();
1002
1021
  const fieldNames = new Set(extracted.fields.map((f) => f.name));
1003
- for (const field of extracted.fields) {
1004
- if (!field.alias) continue;
1005
- if (fieldNames.has(field.alias)) errors.push({
1022
+ const cliNames = new Set(extracted.fields.map((f) => f.cliName));
1023
+ const registerAlias = (alias, fieldName, isDerived) => {
1024
+ if (fieldNames.has(alias) || cliNames.has(alias)) errors.push({
1006
1025
  commandPath,
1007
1026
  type: "duplicate_alias",
1008
- message: `Alias "${field.alias}" for field "${field.name}" conflicts with existing field name "${field.alias}".`,
1009
- field: field.name
1010
- });
1011
- const existingField = seenAliases.get(field.alias);
1012
- if (existingField) errors.push({
1013
- commandPath,
1014
- type: "duplicate_alias",
1015
- message: `Duplicate alias "${field.alias}" detected. Both "${existingField}" and "${field.name}" use the same alias.`,
1016
- field: field.name
1027
+ message: `Alias "${alias}" for field "${fieldName}" conflicts with existing field name or CLI name "${alias}".`,
1028
+ field: fieldName
1017
1029
  });
1018
- seenAliases.set(field.alias, field.name);
1030
+ const existingField = seenAliases.get(alias);
1031
+ if (existingField && existingField !== fieldName) {
1032
+ const qualifier = isDerived ? " (derived camelCase variant)" : "";
1033
+ errors.push({
1034
+ commandPath,
1035
+ type: "duplicate_alias",
1036
+ message: `Duplicate alias "${alias}"${qualifier} detected. Both "${existingField}" and "${fieldName}" use the same alias.`,
1037
+ field: fieldName
1038
+ });
1039
+ }
1040
+ seenAliases.set(alias, fieldName);
1041
+ };
1042
+ for (const field of extracted.fields) {
1043
+ const allAliases = require_subcommand_router.getAllAliases(field);
1044
+ if (allAliases.length === 0) continue;
1045
+ for (const alias of allAliases) {
1046
+ registerAlias(alias, field.name, false);
1047
+ if (alias.length > 1 && alias.includes("-")) {
1048
+ const camelVariant = require_subcommand_router.toCamelCase(alias);
1049
+ if (camelVariant !== alias && !fieldNames.has(camelVariant)) registerAlias(camelVariant, field.name, true);
1050
+ }
1051
+ }
1019
1052
  }
1020
1053
  return errors;
1021
1054
  }
@@ -1056,12 +1089,15 @@ function checkPositionalConfig(extracted, commandPath) {
1056
1089
  */
1057
1090
  function checkReservedAliases(extracted, commandPath) {
1058
1091
  const errors = [];
1059
- for (const field of extracted.fields) if ((field.alias === "h" || field.alias === "H") && field.overrideBuiltinAlias !== true) errors.push({
1060
- commandPath,
1061
- type: "reserved_alias",
1062
- message: `Alias "${field.alias}" is reserved for --${field.alias === "h" ? "help" : "help-all"}.`,
1063
- field: field.name
1064
- });
1092
+ for (const field of extracted.fields) {
1093
+ if (field.overrideBuiltinAlias === true) continue;
1094
+ for (const alias of require_subcommand_router.getAllAliases(field)) if (alias === "h" || alias === "H") errors.push({
1095
+ commandPath,
1096
+ type: "reserved_alias",
1097
+ message: `Alias "${alias}" is reserved for --${alias === "h" ? "help" : "help-all"}.`,
1098
+ field: field.name
1099
+ });
1100
+ }
1065
1101
  return errors;
1066
1102
  }
1067
1103
  /**
@@ -1125,8 +1161,9 @@ function validateReservedAliases(extracted, _hasSubCommands) {
1125
1161
  const errors = checkReservedAliases(extracted, []);
1126
1162
  if (errors.length > 0) {
1127
1163
  const field = errors[0].field ?? "unknown";
1128
- const alias = extracted.fields.find((f) => f.name === field)?.alias ?? "h";
1129
- throw new ReservedAliasError(`Alias "${alias}" is reserved for --${alias === "h" ? "help" : "help-all"}. To override this, set { alias: "${alias}", overrideBuiltinAlias: true } for "${field}".`);
1164
+ const found = extracted.fields.find((f) => f.name === field);
1165
+ const alias = (found ? require_subcommand_router.getAllAliases(found) : []).find((a) => a === "h" || a === "H") ?? "h";
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).`);
1130
1167
  }
1131
1168
  }
1132
1169
  /**
@@ -1152,9 +1189,9 @@ function validateCaseVariantCollisions(extracted) {
1152
1189
  */
1153
1190
  function validateCrossSchemaCollisions(extractedA, extractedB) {
1154
1191
  const canonicalMap = /* @__PURE__ */ new Map();
1155
- for (const field of extractedA.fields) canonicalMap.set(require_lazy.toCamelCase(field.name), field.name);
1192
+ for (const field of extractedA.fields) canonicalMap.set(require_subcommand_router.toCamelCase(field.name), field.name);
1156
1193
  for (const field of extractedB.fields) {
1157
- const camel = require_lazy.toCamelCase(field.name);
1194
+ const camel = require_subcommand_router.toCamelCase(field.name);
1158
1195
  const existing = canonicalMap.get(camel);
1159
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.`);
1160
1197
  }
@@ -1172,6 +1209,57 @@ function collectSchemaErrors(extracted, _hasSubCommands, commandPath) {
1172
1209
  ];
1173
1210
  }
1174
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
+ /**
1175
1263
  * Validate a command and all its subcommands recursively
1176
1264
  *
1177
1265
  * This function collects all validation errors without throwing,
@@ -1194,9 +1282,10 @@ async function validateCommand(command, options = {}) {
1194
1282
  const errors = [];
1195
1283
  const hasSubCommands = command.subCommands ? Object.keys(command.subCommands).length > 0 : false;
1196
1284
  if (command.args) {
1197
- const extracted = require_lazy.extractFields(command.args);
1285
+ const extracted = require_subcommand_router.extractFields(command.args);
1198
1286
  errors.push(...collectSchemaErrors(extracted, hasSubCommands, commandPath));
1199
1287
  }
1288
+ errors.push(...checkSubCommandAliasConflicts(command, commandPath));
1200
1289
  if (command.subCommands) for (const [name, subCmd] of Object.entries(command.subCommands)) {
1201
1290
  const subResult = await validateCommand(await require_subcommand_router.resolveLazyCommand(subCmd), { commandPath: [...commandPath, name] });
1202
1291
  if (!subResult.valid) errors.push(...subResult.errors);
@@ -1371,8 +1460,14 @@ function buildParserOptions(extracted) {
1371
1460
  for (const field of extracted.fields) definedNames.add(field.name);
1372
1461
  for (const field of extracted.fields) {
1373
1462
  if (field.cliName !== field.name) aliasMap.set(field.cliName, field.name);
1374
- if (field.alias) aliasMap.set(field.alias, field.name);
1375
- const camelVariant = require_lazy.toCamelCase(field.name);
1463
+ for (const alias of require_subcommand_router.getAllAliases(field)) {
1464
+ aliasMap.set(alias, field.name);
1465
+ if (alias.length > 1 && alias.includes("-")) {
1466
+ const camelAlias = require_subcommand_router.toCamelCase(alias);
1467
+ if (camelAlias !== alias && !definedNames.has(camelAlias) && !aliasMap.has(camelAlias)) aliasMap.set(camelAlias, field.name);
1468
+ }
1469
+ }
1470
+ const camelVariant = require_subcommand_router.toCamelCase(field.name);
1376
1471
  if (camelVariant !== field.name && !definedNames.has(camelVariant) && !aliasMap.has(camelVariant)) aliasMap.set(camelVariant, field.name);
1377
1472
  if (field.type === "boolean") booleanFlags.add(field.name);
1378
1473
  if (field.type === "array") arrayFlags.add(field.name);
@@ -1413,12 +1508,14 @@ function mergeWithPositionals(parsed, extracted) {
1413
1508
  */
1414
1509
  function buildGlobalFlagLookup(globalExtracted) {
1415
1510
  const { aliasMap = /* @__PURE__ */ new Map(), booleanFlags = /* @__PURE__ */ new Set() } = buildParserOptions(globalExtracted);
1511
+ const shortAliases = /* @__PURE__ */ new Set();
1512
+ for (const field of globalExtracted.fields) for (const alias of require_subcommand_router.getAllAliases(field)) if (alias.length === 1) shortAliases.add(alias);
1416
1513
  return {
1417
1514
  aliasMap,
1418
1515
  booleanFlags,
1419
1516
  flagNames: new Set(globalExtracted.fields.map((f) => f.name)),
1420
1517
  cliNames: new Set(globalExtracted.fields.map((f) => f.cliName)),
1421
- aliases: new Set(globalExtracted.fields.filter((f) => f.alias).map((f) => f.alias))
1518
+ aliases: shortAliases
1422
1519
  };
1423
1520
  }
1424
1521
  /**
@@ -1561,7 +1658,8 @@ function findFirstPositional(argv, globalExtracted) {
1561
1658
  * @returns Parse result
1562
1659
  */
1563
1660
  function parseArgs(argv, command, options = {}) {
1564
- const subCommandNames = command.subCommands ? Object.keys(command.subCommands) : [];
1661
+ const subCommandNameSet = require_subcommand_router.listSubCommandNamesWithAliases(command);
1662
+ const subCommandNames = [...subCommandNameSet];
1565
1663
  const hasSubCommands = subCommandNames.length > 0;
1566
1664
  if (hasSubCommands && argv.length > 0) if (options.globalExtracted) {
1567
1665
  const scanResult = scanForSubcommand(argv, subCommandNames, options.globalExtracted);
@@ -1581,7 +1679,7 @@ function parseArgs(argv, command, options = {}) {
1581
1679
  }
1582
1680
  } else {
1583
1681
  const firstArg = argv[0];
1584
- if (firstArg && !firstArg.startsWith("-") && subCommandNames.includes(firstArg)) return {
1682
+ if (firstArg && !firstArg.startsWith("-") && subCommandNameSet.has(firstArg)) return {
1585
1683
  helpRequested: false,
1586
1684
  helpAllRequested: false,
1587
1685
  versionRequested: false,
@@ -1594,7 +1692,7 @@ function parseArgs(argv, command, options = {}) {
1594
1692
  }
1595
1693
  let extracted;
1596
1694
  if (command.args) {
1597
- extracted = require_lazy.extractFields(command.args);
1695
+ extracted = require_subcommand_router.extractFields(command.args);
1598
1696
  if (!options.skipValidation) {
1599
1697
  validateDuplicateFields(extracted);
1600
1698
  validateCaseVariantCollisions(extracted);
@@ -1604,8 +1702,8 @@ function parseArgs(argv, command, options = {}) {
1604
1702
  if (options.globalExtracted) validateCrossSchemaCollisions(options.globalExtracted, extracted);
1605
1703
  }
1606
1704
  }
1607
- const hasUserDefinedH = extracted?.fields.some((f) => f.alias === "H" && f.overrideBuiltinAlias === true) ?? false;
1608
- const hasUserDefinedh = extracted?.fields.some((f) => f.alias === "h" && f.overrideBuiltinAlias === true) ?? false;
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;
1609
1707
  const helpAllRequested = argv.includes("--help-all") || !hasUserDefinedH && argv.includes("-H");
1610
1708
  const helpRequested = !helpAllRequested && (argv.includes("--help") || !hasUserDefinedh && argv.includes("-h"));
1611
1709
  const versionRequested = argv.includes("--version");
@@ -1652,11 +1750,12 @@ function parseArgs(argv, command, options = {}) {
1652
1750
  }
1653
1751
  const knownFlags = new Set(extracted.fields.map((f) => f.name));
1654
1752
  const knownCliNames = new Set(extracted.fields.map((f) => f.cliName));
1655
- const knownAliases = new Set(extracted.fields.filter((f) => f.alias).map((f) => f.alias));
1753
+ const knownAliases = /* @__PURE__ */ new Set();
1754
+ for (const f of extracted.fields) for (const alias of require_subcommand_router.getAllAliases(f)) knownAliases.add(alias);
1656
1755
  if (options.globalExtracted) for (const f of options.globalExtracted.fields) {
1657
1756
  knownFlags.add(f.name);
1658
1757
  knownCliNames.add(f.cliName);
1659
- if (f.alias) knownAliases.add(f.alias);
1758
+ for (const alias of require_subcommand_router.getAllAliases(f)) knownAliases.add(alias);
1660
1759
  }
1661
1760
  const unknownFlags = [];
1662
1761
  for (const key of Object.keys(parsed.options)) if (!knownFlags.has(key) && !knownCliNames.has(key) && !knownAliases.has(key)) unknownFlags.push(key);
@@ -1694,8 +1793,9 @@ function parseGlobalArgs(tokens, globalExtracted) {
1694
1793
  */
1695
1794
  function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1696
1795
  const lookup = buildGlobalFlagLookup(globalExtracted);
1796
+ const localFieldNames = new Set(localExtracted?.fields.map((f) => f.name) ?? []);
1697
1797
  const localCliNames = new Set(localExtracted?.fields.map((f) => f.cliName) ?? []);
1698
- const localAliases = new Set(localExtracted?.fields.filter((f) => f.alias).map((f) => f.alias) ?? []);
1798
+ const localAliasMapKeys = localExtracted ? new Set(buildParserOptions(localExtracted).aliasMap?.keys() ?? []) : /* @__PURE__ */ new Set();
1699
1799
  const globalTokens = [];
1700
1800
  const commandTokens = [];
1701
1801
  for (let i = 0; i < argv.length; i++) {
@@ -1707,7 +1807,7 @@ function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1707
1807
  if (arg.startsWith("--")) {
1708
1808
  const { resolvedName, withoutDashes, isNegated, isGlobal } = resolveGlobalLongOption(arg, lookup);
1709
1809
  const flagName = isNegated ? withoutDashes.slice(3) : withoutDashes;
1710
- const isLocalCollision = localCliNames.has(withoutDashes) || localCliNames.has(flagName);
1810
+ const isLocalCollision = localFieldNames.has(withoutDashes) || localFieldNames.has(flagName) || localCliNames.has(withoutDashes) || localCliNames.has(flagName) || localAliasMapKeys.has(withoutDashes) || localAliasMapKeys.has(flagName);
1711
1811
  if (isGlobal && !isLocalCollision) {
1712
1812
  i += collectGlobalFlag(argv, i, resolvedName, isNegated, lookup.booleanFlags, globalTokens) - 1;
1713
1813
  continue;
@@ -1716,7 +1816,7 @@ function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1716
1816
  const withoutDash = arg.includes("=") ? arg.slice(1, arg.indexOf("=")) : arg.slice(1);
1717
1817
  if (withoutDash.length === 1) {
1718
1818
  const resolvedName = lookup.aliasMap.get(withoutDash) ?? withoutDash;
1719
- if ((lookup.aliases.has(withoutDash) || lookup.flagNames.has(resolvedName)) && !localAliases.has(withoutDash)) {
1819
+ if ((lookup.aliases.has(withoutDash) || lookup.flagNames.has(resolvedName)) && !localAliasMapKeys.has(withoutDash)) {
1720
1820
  i += collectGlobalFlag(argv, i, resolvedName, false, lookup.booleanFlags, globalTokens) - 1;
1721
1821
  continue;
1722
1822
  }
@@ -1847,7 +1947,7 @@ async function runEffects(validatedArgs, extracted, globalArgs) {
1847
1947
 
1848
1948
  //#endregion
1849
1949
  //#region src/core/runner.ts
1850
- var runner_exports = /* @__PURE__ */ require_subcommand_router.__exportAll({
1950
+ var runner_exports = /* @__PURE__ */ require_log_collector.__exportAll({
1851
1951
  runCommand: () => runCommand,
1852
1952
  runMain: () => runMain
1853
1953
  });
@@ -1887,7 +1987,7 @@ const defaultLogger = {
1887
1987
  async function runCommand(command, argv, options = {}) {
1888
1988
  const globalExtracted = extractAndValidateGlobal(options);
1889
1989
  const shouldCaptureLogs = options.captureLogs ?? false;
1890
- const globalCollector = shouldCaptureLogs ? require_subcommand_router.createLogCollector() : null;
1990
+ const globalCollector = shouldCaptureLogs ? require_log_collector.createLogCollector() : null;
1891
1991
  if (options.setup) {
1892
1992
  globalCollector?.start();
1893
1993
  try {
@@ -1902,7 +2002,7 @@ async function runCommand(command, argv, options = {}) {
1902
2002
  success: false,
1903
2003
  error,
1904
2004
  exitCode: 1,
1905
- logs: globalCollector?.getLogs() ?? require_subcommand_router.emptyLogs()
2005
+ logs: globalCollector?.getLogs() ?? require_log_collector.emptyLogs()
1906
2006
  };
1907
2007
  }
1908
2008
  globalCollector?.stop();
@@ -1915,7 +2015,7 @@ async function runCommand(command, argv, options = {}) {
1915
2015
  _existingLogs: globalCollector?.getLogs()
1916
2016
  });
1917
2017
  if (options.cleanup) {
1918
- const cleanupCollector = shouldCaptureLogs ? require_subcommand_router.createLogCollector() : null;
2018
+ const cleanupCollector = shouldCaptureLogs ? require_log_collector.createLogCollector() : null;
1919
2019
  cleanupCollector?.start();
1920
2020
  const cleanupCtx = { error: !result.success ? result.error : void 0 };
1921
2021
  try {
@@ -1928,15 +2028,15 @@ async function runCommand(command, argv, options = {}) {
1928
2028
  success: false,
1929
2029
  error,
1930
2030
  exitCode: 1,
1931
- logs: require_subcommand_router.mergeLogs(result.logs, cleanupCollector?.getLogs() ?? require_subcommand_router.emptyLogs())
2031
+ logs: require_log_collector.mergeLogs(result.logs, cleanupCollector?.getLogs() ?? require_log_collector.emptyLogs())
1932
2032
  };
1933
2033
  }
1934
2034
  }
1935
2035
  cleanupCollector?.stop();
1936
- const cleanupLogs = cleanupCollector?.getLogs() ?? require_subcommand_router.emptyLogs();
2036
+ const cleanupLogs = cleanupCollector?.getLogs() ?? require_log_collector.emptyLogs();
1937
2037
  if (cleanupLogs.entries.length > 0) return {
1938
2038
  ...result,
1939
- logs: require_subcommand_router.mergeLogs(result.logs, cleanupLogs)
2039
+ logs: require_log_collector.mergeLogs(result.logs, cleanupLogs)
1940
2040
  };
1941
2041
  }
1942
2042
  return result;
@@ -2013,10 +2113,10 @@ async function runCommandInternal(command, argv, options = {}) {
2013
2113
  rootName: command.name,
2014
2114
  globalExtracted: options._globalExtracted
2015
2115
  };
2016
- const collector = options.captureLogs ?? false ? require_subcommand_router.createLogCollector() : null;
2116
+ const collector = options.captureLogs ?? false ? require_log_collector.createLogCollector() : null;
2017
2117
  collector?.start();
2018
2118
  const getCurrentLogs = () => {
2019
- return require_subcommand_router.mergeLogs(options._existingLogs ?? require_subcommand_router.emptyLogs(), collector?.getLogs() ?? require_subcommand_router.emptyLogs());
2119
+ return require_log_collector.mergeLogs(options._existingLogs ?? require_log_collector.emptyLogs(), collector?.getLogs() ?? require_log_collector.emptyLogs());
2020
2120
  };
2021
2121
  try {
2022
2122
  const parseResult = parseArgs(argv, command, {
@@ -2030,9 +2130,10 @@ async function runCommandInternal(command, argv, options = {}) {
2030
2130
  if (parseResult.helpRequested || parseResult.helpAllRequested) {
2031
2131
  let hasUnknownSubcommand = false;
2032
2132
  const subCmdNames = require_subcommand_router.listSubCommands(command);
2133
+ const allSubCmdNameSet = require_subcommand_router.listSubCommandNamesWithAliases(command);
2033
2134
  if (subCmdNames.length > 0) {
2034
2135
  const potentialSubCmd = findFirstPositional(argv, context.globalExtracted);
2035
- if (potentialSubCmd && !subCmdNames.includes(potentialSubCmd)) hasUnknownSubcommand = true;
2136
+ if (potentialSubCmd && !allSubCmdNameSet.has(potentialSubCmd)) hasUnknownSubcommand = true;
2036
2137
  }
2037
2138
  const help = generateHelp(command, {
2038
2139
  showSubcommands: options.showSubcommands ?? true,
@@ -2043,7 +2144,7 @@ async function runCommandInternal(command, argv, options = {}) {
2043
2144
  collector?.stop();
2044
2145
  if (hasUnknownSubcommand) {
2045
2146
  const unknownCmd = findFirstPositional(argv, context.globalExtracted) ?? "";
2046
- const similar = findSimilar(unknownCmd, subCmdNames);
2147
+ const similar = findSimilar(unknownCmd, [...allSubCmdNameSet]);
2047
2148
  const suggestion = similar.length > 0 ? ` Did you mean: ${similar.join(", ")}?` : "";
2048
2149
  return {
2049
2150
  success: false,
@@ -2071,16 +2172,17 @@ async function runCommandInternal(command, argv, options = {}) {
2071
2172
  };
2072
2173
  }
2073
2174
  if (parseResult.subCommand) {
2074
- const subCmd = await require_subcommand_router.resolveSubcommand(command, parseResult.subCommand);
2075
- if (subCmd) {
2175
+ const resolved = await require_subcommand_router.resolveSubcommandWithAlias(command, parseResult.subCommand);
2176
+ if (resolved) {
2076
2177
  const subContext = {
2077
2178
  commandPath: [...context.commandPath ?? [], parseResult.subCommand],
2078
2179
  rootName: context.rootName,
2079
2180
  rootVersion: context.rootVersion,
2080
- globalExtracted: context.globalExtracted
2181
+ globalExtracted: context.globalExtracted,
2182
+ aliasFor: resolved.aliasFor
2081
2183
  };
2082
2184
  collector?.stop();
2083
- return runCommandInternal(subCmd, parseResult.remainingArgs, {
2185
+ return runCommandInternal(resolved.command, parseResult.remainingArgs, {
2084
2186
  ...options,
2085
2187
  _context: subContext,
2086
2188
  _existingLogs: getCurrentLogs(),
@@ -2205,7 +2307,7 @@ async function runCommandInternal(command, argv, options = {}) {
2205
2307
  */
2206
2308
  function extractAndValidateGlobal(options) {
2207
2309
  if (!options.globalArgs) return void 0;
2208
- const extracted = require_lazy.extractFields(options.globalArgs);
2310
+ const extracted = require_subcommand_router.extractFields(options.globalArgs);
2209
2311
  if (!options.skipValidation) {
2210
2312
  validateDuplicateFields(extracted);
2211
2313
  validateCaseVariantCollisions(extracted);
@@ -2380,4 +2482,4 @@ Object.defineProperty(exports, 'validateReservedAliases', {
2380
2482
  return validateReservedAliases;
2381
2483
  }
2382
2484
  });
2383
- //# sourceMappingURL=runner-DA48D-3K.cjs.map
2485
+ //# sourceMappingURL=runner-CriXJlm4.cjs.map