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,5 +1,5 @@
1
- import { a as getExtractedFields, c as toKebabCase, i as extractFields, r as resolveSubCommandMeta, s as toCamelCase } from "./lazy-xrzxwnru.js";
2
- import { a as emptyLogs, i as createLogCollector, n as resolveLazyCommand, o as mergeLogs, r as resolveSubcommand, t as listSubCommands } from "./subcommand-router-BhYVuS83.js";
1
+ import { a as resolveSubcommandWithAlias, c as resolveSubCommandMeta, d as getExtractedFields, l as extractFields, m as toKebabCase, n as listSubCommands, o as isLazyCommand, p as toCamelCase, r as resolveLazyCommand, t as listSubCommandNamesWithAliases, u as getAllAliases } from "./subcommand-router-ENeCymvX.js";
2
+ import { n as emptyLogs, r as mergeLogs, t as createLogCollector } from "./log-collector-Cu6MCtAx.js";
3
3
  import { styleText } from "node:util";
4
4
  import stringWidth from "string-width";
5
5
 
@@ -630,8 +630,8 @@ function renderOptions(command, descriptions = {}, context) {
630
630
  version: descriptions.version ?? defaultBuiltinDescriptions.version
631
631
  };
632
632
  const extracted = getExtractedFields(command);
633
- const hasUserDefinedh = extracted?.fields.some((f) => f.alias === "h" && f.overrideBuiltinAlias === true) ?? false;
634
- const hasUserDefinedH = extracted?.fields.some((f) => f.alias === "H" && f.overrideBuiltinAlias === true) ?? false;
633
+ const hasUserDefinedh = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && getAllAliases(f).includes("h")) ?? false;
634
+ const hasUserDefinedH = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && getAllAliases(f).includes("H")) ?? false;
635
635
  if (hasUserDefinedh) lines.push(formatOption(styles.option("--help"), desc.help));
636
636
  else lines.push(formatOption(`${styles.option("-h")}, ${styles.option("--help")}`, desc.help));
637
637
  if (hasUserDefinedH) lines.push(formatOption(styles.option("--help-all"), desc.helpAll));
@@ -754,13 +754,25 @@ function renderUnionOptions(extracted, _command, lines) {
754
754
  */
755
755
  function formatFlags(opt) {
756
756
  const parts = [];
757
- if (opt.alias) parts.push(styles.option(`-${opt.alias}`));
757
+ if (opt.alias) {
758
+ for (const alias of opt.alias) if (alias.length === 1) parts.push(styles.option(`-${alias}`));
759
+ }
758
760
  let longFlag = styles.option(`--${opt.cliName}`);
759
761
  if (opt.type !== "boolean") {
760
762
  const placeholder = opt.placeholder ?? opt.cliName.toUpperCase();
761
763
  longFlag += ` ${styles.placeholder(`<${placeholder}>`)}`;
762
764
  }
763
765
  parts.push(longFlag);
766
+ if (opt.alias) {
767
+ for (const alias of opt.alias) if (alias.length > 1) {
768
+ let longAlias = styles.option(`--${alias}`);
769
+ if (opt.type !== "boolean") {
770
+ const placeholder = opt.placeholder ?? opt.cliName.toUpperCase();
771
+ longAlias += ` ${styles.placeholder(`<${placeholder}>`)}`;
772
+ }
773
+ parts.push(longAlias);
774
+ }
775
+ }
764
776
  return parts.join(", ");
765
777
  }
766
778
  /**
@@ -843,7 +855,9 @@ function renderSubcommandsWithOptions(subCommands, parentPath, baseIndent) {
843
855
  const cmd = resolveSubCommandMeta(subCmd);
844
856
  const fullPath = parentPath ? `${parentPath} ${name}` : name;
845
857
  const desc = cmd?.description ?? "";
846
- lines.push(formatOption(styles.command(fullPath), desc, baseIndent));
858
+ const aliases = cmd?.aliases;
859
+ const displayName = aliases && aliases.length > 0 ? `${fullPath}, ${aliases.join(", ")}` : fullPath;
860
+ lines.push(formatOption(styles.command(displayName), desc, baseIndent));
847
861
  if (cmd) {
848
862
  const optionLines = renderSubcommandOptionsCompact(cmd, baseIndent + 1);
849
863
  lines.push(...optionLines);
@@ -874,7 +888,9 @@ function generateHelp(command, options) {
874
888
  else if (context?.rootVersion) header += ` ${styles.version(`v${context.rootVersion}`)}`;
875
889
  sections.push(header);
876
890
  }
891
+ if (context?.aliasFor) sections.push(styles.dim(`Alias for ${styles.commandName(context.aliasFor)}`));
877
892
  if (command.description) sections.push(command.description);
893
+ if (!context?.aliasFor && command.aliases && command.aliases.length > 0) sections.push(`${styles.sectionHeader("Aliases:")} ${command.aliases.map((a) => styles.command(a)).join(", ")}`);
878
894
  sections.push(`${styles.sectionHeader("Usage:")} ${renderUsageLine(command, context)}`);
879
895
  const optionsText = renderOptions(command, options.descriptions, context);
880
896
  if (optionsText) sections.push(`${styles.sectionHeader("Options:")}\n${optionsText}`);
@@ -888,9 +904,12 @@ function generateHelp(command, options) {
888
904
  } else {
889
905
  const subLines = [];
890
906
  for (const [name, subCmd] of Object.entries(visibleSubCommands)) {
891
- const desc = resolveSubCommandMeta(subCmd)?.description ?? "";
907
+ const cmd = resolveSubCommandMeta(subCmd);
908
+ const desc = cmd?.description ?? "";
892
909
  const fullName = currentPath ? `${currentPath} ${name}` : name;
893
- subLines.push(formatOption(styles.command(fullName), desc));
910
+ const aliases = cmd?.aliases;
911
+ const displayName = aliases && aliases.length > 0 ? `${fullName}, ${aliases.join(", ")}` : fullName;
912
+ subLines.push(formatOption(styles.command(displayName), desc));
894
913
  }
895
914
  sections.push(`${styles.sectionHeader("Commands:")}\n${subLines.join("\n")}`);
896
915
  }
@@ -1016,22 +1035,36 @@ function checkDuplicateAliases(extracted, commandPath) {
1016
1035
  const errors = [];
1017
1036
  const seenAliases = /* @__PURE__ */ new Map();
1018
1037
  const fieldNames = new Set(extracted.fields.map((f) => f.name));
1019
- for (const field of extracted.fields) {
1020
- if (!field.alias) continue;
1021
- if (fieldNames.has(field.alias)) errors.push({
1038
+ const cliNames = new Set(extracted.fields.map((f) => f.cliName));
1039
+ const registerAlias = (alias, fieldName, isDerived) => {
1040
+ if (fieldNames.has(alias) || cliNames.has(alias)) errors.push({
1022
1041
  commandPath,
1023
1042
  type: "duplicate_alias",
1024
- message: `Alias "${field.alias}" for field "${field.name}" conflicts with existing field name "${field.alias}".`,
1025
- field: field.name
1026
- });
1027
- const existingField = seenAliases.get(field.alias);
1028
- if (existingField) errors.push({
1029
- commandPath,
1030
- type: "duplicate_alias",
1031
- message: `Duplicate alias "${field.alias}" detected. Both "${existingField}" and "${field.name}" use the same alias.`,
1032
- field: field.name
1043
+ message: `Alias "${alias}" for field "${fieldName}" conflicts with existing field name or CLI name "${alias}".`,
1044
+ field: fieldName
1033
1045
  });
1034
- seenAliases.set(field.alias, field.name);
1046
+ const existingField = seenAliases.get(alias);
1047
+ if (existingField && existingField !== fieldName) {
1048
+ const qualifier = isDerived ? " (derived camelCase variant)" : "";
1049
+ errors.push({
1050
+ commandPath,
1051
+ type: "duplicate_alias",
1052
+ message: `Duplicate alias "${alias}"${qualifier} detected. Both "${existingField}" and "${fieldName}" use the same alias.`,
1053
+ field: fieldName
1054
+ });
1055
+ }
1056
+ seenAliases.set(alias, fieldName);
1057
+ };
1058
+ for (const field of extracted.fields) {
1059
+ const allAliases = getAllAliases(field);
1060
+ if (allAliases.length === 0) continue;
1061
+ for (const alias of allAliases) {
1062
+ registerAlias(alias, field.name, false);
1063
+ if (alias.length > 1 && alias.includes("-")) {
1064
+ const camelVariant = toCamelCase(alias);
1065
+ if (camelVariant !== alias && !fieldNames.has(camelVariant)) registerAlias(camelVariant, field.name, true);
1066
+ }
1067
+ }
1035
1068
  }
1036
1069
  return errors;
1037
1070
  }
@@ -1072,12 +1105,15 @@ function checkPositionalConfig(extracted, commandPath) {
1072
1105
  */
1073
1106
  function checkReservedAliases(extracted, commandPath) {
1074
1107
  const errors = [];
1075
- for (const field of extracted.fields) if ((field.alias === "h" || field.alias === "H") && field.overrideBuiltinAlias !== true) errors.push({
1076
- commandPath,
1077
- type: "reserved_alias",
1078
- message: `Alias "${field.alias}" is reserved for --${field.alias === "h" ? "help" : "help-all"}.`,
1079
- field: field.name
1080
- });
1108
+ for (const field of extracted.fields) {
1109
+ if (field.overrideBuiltinAlias === true) continue;
1110
+ for (const alias of getAllAliases(field)) if (alias === "h" || alias === "H") errors.push({
1111
+ commandPath,
1112
+ type: "reserved_alias",
1113
+ message: `Alias "${alias}" is reserved for --${alias === "h" ? "help" : "help-all"}.`,
1114
+ field: field.name
1115
+ });
1116
+ }
1081
1117
  return errors;
1082
1118
  }
1083
1119
  /**
@@ -1141,8 +1177,9 @@ function validateReservedAliases(extracted, _hasSubCommands) {
1141
1177
  const errors = checkReservedAliases(extracted, []);
1142
1178
  if (errors.length > 0) {
1143
1179
  const field = errors[0].field ?? "unknown";
1144
- const alias = extracted.fields.find((f) => f.name === field)?.alias ?? "h";
1145
- throw new ReservedAliasError(`Alias "${alias}" is reserved for --${alias === "h" ? "help" : "help-all"}. To override this, set { alias: "${alias}", overrideBuiltinAlias: true } for "${field}".`);
1180
+ const found = extracted.fields.find((f) => f.name === field);
1181
+ const alias = (found ? getAllAliases(found) : []).find((a) => a === "h" || a === "H") ?? "h";
1182
+ 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).`);
1146
1183
  }
1147
1184
  }
1148
1185
  /**
@@ -1188,6 +1225,57 @@ function collectSchemaErrors(extracted, _hasSubCommands, commandPath) {
1188
1225
  ];
1189
1226
  }
1190
1227
  /**
1228
+ * Check for alias conflicts within subcommands
1229
+ * - Aliases must not conflict with subcommand names
1230
+ * - Aliases must not conflict with other aliases
1231
+ */
1232
+ function checkSubCommandAliasConflicts(command, commandPath) {
1233
+ const errors = [];
1234
+ if (!command.subCommands) return errors;
1235
+ const nameToOwner = /* @__PURE__ */ new Map();
1236
+ for (const [name] of Object.entries(command.subCommands)) nameToOwner.set(name, name);
1237
+ for (const [name, subCmdValue] of Object.entries(command.subCommands)) {
1238
+ const resolved = isLazyCommand(subCmdValue) ? subCmdValue.meta : typeof subCmdValue !== "function" ? subCmdValue : null;
1239
+ if (!resolved?.aliases) continue;
1240
+ const subCommandPath = [...commandPath, name];
1241
+ for (const alias of resolved.aliases) {
1242
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(alias)) {
1243
+ errors.push({
1244
+ commandPath: subCommandPath,
1245
+ type: "invalid_alias",
1246
+ message: `Alias "${alias}" is invalid. Aliases must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores.`,
1247
+ field: name
1248
+ });
1249
+ continue;
1250
+ }
1251
+ if (alias === name) {
1252
+ errors.push({
1253
+ commandPath: subCommandPath,
1254
+ type: "duplicate_alias",
1255
+ message: `Alias "${alias}" conflicts with its own name.`,
1256
+ field: name
1257
+ });
1258
+ continue;
1259
+ }
1260
+ const existing = nameToOwner.get(alias);
1261
+ if (existing) if (existing === name) errors.push({
1262
+ commandPath: subCommandPath,
1263
+ type: "duplicate_alias",
1264
+ message: `Alias "${alias}" is duplicated within the alias list.`,
1265
+ field: name
1266
+ });
1267
+ else errors.push({
1268
+ commandPath: subCommandPath,
1269
+ type: "duplicate_alias",
1270
+ message: `Alias "${alias}" conflicts with existing subcommand or alias "${existing}".`,
1271
+ field: name
1272
+ });
1273
+ else nameToOwner.set(alias, name);
1274
+ }
1275
+ }
1276
+ return errors;
1277
+ }
1278
+ /**
1191
1279
  * Validate a command and all its subcommands recursively
1192
1280
  *
1193
1281
  * This function collects all validation errors without throwing,
@@ -1213,6 +1301,7 @@ async function validateCommand(command, options = {}) {
1213
1301
  const extracted = extractFields(command.args);
1214
1302
  errors.push(...collectSchemaErrors(extracted, hasSubCommands, commandPath));
1215
1303
  }
1304
+ errors.push(...checkSubCommandAliasConflicts(command, commandPath));
1216
1305
  if (command.subCommands) for (const [name, subCmd] of Object.entries(command.subCommands)) {
1217
1306
  const subResult = await validateCommand(await resolveLazyCommand(subCmd), { commandPath: [...commandPath, name] });
1218
1307
  if (!subResult.valid) errors.push(...subResult.errors);
@@ -1387,7 +1476,13 @@ function buildParserOptions(extracted) {
1387
1476
  for (const field of extracted.fields) definedNames.add(field.name);
1388
1477
  for (const field of extracted.fields) {
1389
1478
  if (field.cliName !== field.name) aliasMap.set(field.cliName, field.name);
1390
- if (field.alias) aliasMap.set(field.alias, field.name);
1479
+ for (const alias of getAllAliases(field)) {
1480
+ aliasMap.set(alias, field.name);
1481
+ if (alias.length > 1 && alias.includes("-")) {
1482
+ const camelAlias = toCamelCase(alias);
1483
+ if (camelAlias !== alias && !definedNames.has(camelAlias) && !aliasMap.has(camelAlias)) aliasMap.set(camelAlias, field.name);
1484
+ }
1485
+ }
1391
1486
  const camelVariant = toCamelCase(field.name);
1392
1487
  if (camelVariant !== field.name && !definedNames.has(camelVariant) && !aliasMap.has(camelVariant)) aliasMap.set(camelVariant, field.name);
1393
1488
  if (field.type === "boolean") booleanFlags.add(field.name);
@@ -1429,12 +1524,14 @@ function mergeWithPositionals(parsed, extracted) {
1429
1524
  */
1430
1525
  function buildGlobalFlagLookup(globalExtracted) {
1431
1526
  const { aliasMap = /* @__PURE__ */ new Map(), booleanFlags = /* @__PURE__ */ new Set() } = buildParserOptions(globalExtracted);
1527
+ const shortAliases = /* @__PURE__ */ new Set();
1528
+ for (const field of globalExtracted.fields) for (const alias of getAllAliases(field)) if (alias.length === 1) shortAliases.add(alias);
1432
1529
  return {
1433
1530
  aliasMap,
1434
1531
  booleanFlags,
1435
1532
  flagNames: new Set(globalExtracted.fields.map((f) => f.name)),
1436
1533
  cliNames: new Set(globalExtracted.fields.map((f) => f.cliName)),
1437
- aliases: new Set(globalExtracted.fields.filter((f) => f.alias).map((f) => f.alias))
1534
+ aliases: shortAliases
1438
1535
  };
1439
1536
  }
1440
1537
  /**
@@ -1577,7 +1674,8 @@ function findFirstPositional(argv, globalExtracted) {
1577
1674
  * @returns Parse result
1578
1675
  */
1579
1676
  function parseArgs(argv, command, options = {}) {
1580
- const subCommandNames = command.subCommands ? Object.keys(command.subCommands) : [];
1677
+ const subCommandNameSet = listSubCommandNamesWithAliases(command);
1678
+ const subCommandNames = [...subCommandNameSet];
1581
1679
  const hasSubCommands = subCommandNames.length > 0;
1582
1680
  if (hasSubCommands && argv.length > 0) if (options.globalExtracted) {
1583
1681
  const scanResult = scanForSubcommand(argv, subCommandNames, options.globalExtracted);
@@ -1597,7 +1695,7 @@ function parseArgs(argv, command, options = {}) {
1597
1695
  }
1598
1696
  } else {
1599
1697
  const firstArg = argv[0];
1600
- if (firstArg && !firstArg.startsWith("-") && subCommandNames.includes(firstArg)) return {
1698
+ if (firstArg && !firstArg.startsWith("-") && subCommandNameSet.has(firstArg)) return {
1601
1699
  helpRequested: false,
1602
1700
  helpAllRequested: false,
1603
1701
  versionRequested: false,
@@ -1620,8 +1718,8 @@ function parseArgs(argv, command, options = {}) {
1620
1718
  if (options.globalExtracted) validateCrossSchemaCollisions(options.globalExtracted, extracted);
1621
1719
  }
1622
1720
  }
1623
- const hasUserDefinedH = extracted?.fields.some((f) => f.alias === "H" && f.overrideBuiltinAlias === true) ?? false;
1624
- const hasUserDefinedh = extracted?.fields.some((f) => f.alias === "h" && f.overrideBuiltinAlias === true) ?? false;
1721
+ const hasUserDefinedH = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && getAllAliases(f).includes("H")) ?? false;
1722
+ const hasUserDefinedh = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && getAllAliases(f).includes("h")) ?? false;
1625
1723
  const helpAllRequested = argv.includes("--help-all") || !hasUserDefinedH && argv.includes("-H");
1626
1724
  const helpRequested = !helpAllRequested && (argv.includes("--help") || !hasUserDefinedh && argv.includes("-h"));
1627
1725
  const versionRequested = argv.includes("--version");
@@ -1668,11 +1766,12 @@ function parseArgs(argv, command, options = {}) {
1668
1766
  }
1669
1767
  const knownFlags = new Set(extracted.fields.map((f) => f.name));
1670
1768
  const knownCliNames = new Set(extracted.fields.map((f) => f.cliName));
1671
- const knownAliases = new Set(extracted.fields.filter((f) => f.alias).map((f) => f.alias));
1769
+ const knownAliases = /* @__PURE__ */ new Set();
1770
+ for (const f of extracted.fields) for (const alias of getAllAliases(f)) knownAliases.add(alias);
1672
1771
  if (options.globalExtracted) for (const f of options.globalExtracted.fields) {
1673
1772
  knownFlags.add(f.name);
1674
1773
  knownCliNames.add(f.cliName);
1675
- if (f.alias) knownAliases.add(f.alias);
1774
+ for (const alias of getAllAliases(f)) knownAliases.add(alias);
1676
1775
  }
1677
1776
  const unknownFlags = [];
1678
1777
  for (const key of Object.keys(parsed.options)) if (!knownFlags.has(key) && !knownCliNames.has(key) && !knownAliases.has(key)) unknownFlags.push(key);
@@ -1710,8 +1809,9 @@ function parseGlobalArgs(tokens, globalExtracted) {
1710
1809
  */
1711
1810
  function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1712
1811
  const lookup = buildGlobalFlagLookup(globalExtracted);
1812
+ const localFieldNames = new Set(localExtracted?.fields.map((f) => f.name) ?? []);
1713
1813
  const localCliNames = new Set(localExtracted?.fields.map((f) => f.cliName) ?? []);
1714
- const localAliases = new Set(localExtracted?.fields.filter((f) => f.alias).map((f) => f.alias) ?? []);
1814
+ const localAliasMapKeys = localExtracted ? new Set(buildParserOptions(localExtracted).aliasMap?.keys() ?? []) : /* @__PURE__ */ new Set();
1715
1815
  const globalTokens = [];
1716
1816
  const commandTokens = [];
1717
1817
  for (let i = 0; i < argv.length; i++) {
@@ -1723,7 +1823,7 @@ function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1723
1823
  if (arg.startsWith("--")) {
1724
1824
  const { resolvedName, withoutDashes, isNegated, isGlobal } = resolveGlobalLongOption(arg, lookup);
1725
1825
  const flagName = isNegated ? withoutDashes.slice(3) : withoutDashes;
1726
- const isLocalCollision = localCliNames.has(withoutDashes) || localCliNames.has(flagName);
1826
+ const isLocalCollision = localFieldNames.has(withoutDashes) || localFieldNames.has(flagName) || localCliNames.has(withoutDashes) || localCliNames.has(flagName) || localAliasMapKeys.has(withoutDashes) || localAliasMapKeys.has(flagName);
1727
1827
  if (isGlobal && !isLocalCollision) {
1728
1828
  i += collectGlobalFlag(argv, i, resolvedName, isNegated, lookup.booleanFlags, globalTokens) - 1;
1729
1829
  continue;
@@ -1732,7 +1832,7 @@ function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1732
1832
  const withoutDash = arg.includes("=") ? arg.slice(1, arg.indexOf("=")) : arg.slice(1);
1733
1833
  if (withoutDash.length === 1) {
1734
1834
  const resolvedName = lookup.aliasMap.get(withoutDash) ?? withoutDash;
1735
- if ((lookup.aliases.has(withoutDash) || lookup.flagNames.has(resolvedName)) && !localAliases.has(withoutDash)) {
1835
+ if ((lookup.aliases.has(withoutDash) || lookup.flagNames.has(resolvedName)) && !localAliasMapKeys.has(withoutDash)) {
1736
1836
  i += collectGlobalFlag(argv, i, resolvedName, false, lookup.booleanFlags, globalTokens) - 1;
1737
1837
  continue;
1738
1838
  }
@@ -2046,9 +2146,10 @@ async function runCommandInternal(command, argv, options = {}) {
2046
2146
  if (parseResult.helpRequested || parseResult.helpAllRequested) {
2047
2147
  let hasUnknownSubcommand = false;
2048
2148
  const subCmdNames = listSubCommands(command);
2149
+ const allSubCmdNameSet = listSubCommandNamesWithAliases(command);
2049
2150
  if (subCmdNames.length > 0) {
2050
2151
  const potentialSubCmd = findFirstPositional(argv, context.globalExtracted);
2051
- if (potentialSubCmd && !subCmdNames.includes(potentialSubCmd)) hasUnknownSubcommand = true;
2152
+ if (potentialSubCmd && !allSubCmdNameSet.has(potentialSubCmd)) hasUnknownSubcommand = true;
2052
2153
  }
2053
2154
  const help = generateHelp(command, {
2054
2155
  showSubcommands: options.showSubcommands ?? true,
@@ -2059,7 +2160,7 @@ async function runCommandInternal(command, argv, options = {}) {
2059
2160
  collector?.stop();
2060
2161
  if (hasUnknownSubcommand) {
2061
2162
  const unknownCmd = findFirstPositional(argv, context.globalExtracted) ?? "";
2062
- const similar = findSimilar(unknownCmd, subCmdNames);
2163
+ const similar = findSimilar(unknownCmd, [...allSubCmdNameSet]);
2063
2164
  const suggestion = similar.length > 0 ? ` Did you mean: ${similar.join(", ")}?` : "";
2064
2165
  return {
2065
2166
  success: false,
@@ -2087,16 +2188,17 @@ async function runCommandInternal(command, argv, options = {}) {
2087
2188
  };
2088
2189
  }
2089
2190
  if (parseResult.subCommand) {
2090
- const subCmd = await resolveSubcommand(command, parseResult.subCommand);
2091
- if (subCmd) {
2191
+ const resolved = await resolveSubcommandWithAlias(command, parseResult.subCommand);
2192
+ if (resolved) {
2092
2193
  const subContext = {
2093
2194
  commandPath: [...context.commandPath ?? [], parseResult.subCommand],
2094
2195
  rootName: context.rootName,
2095
2196
  rootVersion: context.rootVersion,
2096
- globalExtracted: context.globalExtracted
2197
+ globalExtracted: context.globalExtracted,
2198
+ aliasFor: resolved.aliasFor
2097
2199
  };
2098
2200
  collector?.stop();
2099
- return runCommandInternal(subCmd, parseResult.remainingArgs, {
2201
+ return runCommandInternal(resolved.command, parseResult.remainingArgs, {
2100
2202
  ...options,
2101
2203
  _context: subContext,
2102
2204
  _existingLogs: getCurrentLogs(),
@@ -2235,4 +2337,4 @@ function extractAndValidateGlobal(options) {
2235
2337
 
2236
2338
  //#endregion
2237
2339
  export { logger as C, createDualCaseProxy as D, symbols as E, isColorEnabled as S, styles as T, PositionalConfigError as _, parseArgv as a, renderInline as b, validateCommand as c, validateDuplicateFields as d, validatePositionalConfig as f, DuplicateFieldError as g, DuplicateAliasError as h, formatValidationErrors as i, validateCrossSchemaCollisions as l, CaseVariantCollisionError as m, runMain as n, formatCommandValidationErrors as o, validateReservedAliases as p, runner_exports as r, validateCaseVariantCollisions as s, runCommand as t, validateDuplicateAliases as u, ReservedAliasError as v, setColorEnabled as w, renderMarkdown as x, generateHelp as y };
2238
- //# sourceMappingURL=runner-CnG-Ncz0.js.map
2340
+ //# sourceMappingURL=runner-DKAQBNNh.js.map