politty 0.4.13 → 0.4.14

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 (65) hide show
  1. package/dist/{arg-registry-6E4C5MTC.d.ts → arg-registry-CkPDokIu.d.ts} +53 -14
  2. package/dist/arg-registry-CkPDokIu.d.ts.map +1 -0
  3. package/dist/{arg-registry-CeIRoLaB.d.cts → arg-registry-r5wYN6qd.d.cts} +53 -14
  4. package/dist/arg-registry-r5wYN6qd.d.cts.map +1 -0
  5. package/dist/augment.d.cts +3 -2
  6. package/dist/augment.d.cts.map +1 -1
  7. package/dist/augment.d.ts +3 -2
  8. package/dist/augment.d.ts.map +1 -1
  9. package/dist/completion/index.cjs +1 -1
  10. package/dist/completion/index.d.cts +1 -1
  11. package/dist/completion/index.d.ts +1 -1
  12. package/dist/completion/index.js +1 -1
  13. package/dist/{completion-D3LUac1o.cjs → completion-CAekGYS4.cjs} +24 -14
  14. package/dist/completion-CAekGYS4.cjs.map +1 -0
  15. package/dist/{completion-DzaT2YCN.js → completion-yHz8Pdr7.js} +23 -13
  16. package/dist/completion-yHz8Pdr7.js.map +1 -0
  17. package/dist/docs/index.cjs +21 -8
  18. package/dist/docs/index.cjs.map +1 -1
  19. package/dist/docs/index.d.cts +1 -1
  20. package/dist/docs/index.d.cts.map +1 -1
  21. package/dist/docs/index.d.ts +1 -1
  22. package/dist/docs/index.d.ts.map +1 -1
  23. package/dist/docs/index.js +21 -8
  24. package/dist/docs/index.js.map +1 -1
  25. package/dist/{index-BW02tH1-.d.cts → index-BLySW_2k.d.ts} +7 -4
  26. package/dist/index-BLySW_2k.d.ts.map +1 -0
  27. package/dist/{index-C3UtsvgY.d.ts → index-DPswv0Vt.d.cts} +7 -4
  28. package/dist/index-DPswv0Vt.d.cts.map +1 -0
  29. package/dist/index.cjs +3 -3
  30. package/dist/index.d.cts +2 -2
  31. package/dist/index.d.cts.map +1 -1
  32. package/dist/index.d.ts +2 -2
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +3 -3
  35. package/dist/{lazy-qPy4cMnv.cjs → lazy-AGV9Pkt5.cjs} +34 -3
  36. package/dist/lazy-AGV9Pkt5.cjs.map +1 -0
  37. package/dist/{lazy-xrzxwnru.js → lazy-DiMJSDMB.js} +28 -3
  38. package/dist/lazy-DiMJSDMB.js.map +1 -0
  39. package/dist/prompt/clack/index.cjs +1 -1
  40. package/dist/prompt/clack/index.d.cts +1 -1
  41. package/dist/prompt/clack/index.d.ts +1 -1
  42. package/dist/prompt/index.d.cts +1 -1
  43. package/dist/prompt/index.d.ts +1 -1
  44. package/dist/prompt/inquirer/index.cjs +1 -1
  45. package/dist/prompt/inquirer/index.d.cts +1 -1
  46. package/dist/prompt/inquirer/index.d.ts +1 -1
  47. package/dist/{runner-DA48D-3K.cjs → runner-CY5fOsSh.cjs} +76 -36
  48. package/dist/runner-CY5fOsSh.cjs.map +1 -0
  49. package/dist/{runner-CnG-Ncz0.js → runner-DSZw1AsW.js} +76 -36
  50. package/dist/runner-DSZw1AsW.js.map +1 -0
  51. package/dist/{subcommand-router-BhYVuS83.js → subcommand-router--EUt6ftA.js} +2 -2
  52. package/dist/{subcommand-router-BhYVuS83.js.map → subcommand-router--EUt6ftA.js.map} +1 -1
  53. package/dist/{subcommand-router-BnHpqyRk.cjs → subcommand-router-C9ONv6Nq.cjs} +2 -2
  54. package/dist/{subcommand-router-BnHpqyRk.cjs.map → subcommand-router-C9ONv6Nq.cjs.map} +1 -1
  55. package/package.json +12 -12
  56. package/dist/arg-registry-6E4C5MTC.d.ts.map +0 -1
  57. package/dist/arg-registry-CeIRoLaB.d.cts.map +0 -1
  58. package/dist/completion-D3LUac1o.cjs.map +0 -1
  59. package/dist/completion-DzaT2YCN.js.map +0 -1
  60. package/dist/index-BW02tH1-.d.cts.map +0 -1
  61. package/dist/index-C3UtsvgY.d.ts.map +0 -1
  62. package/dist/lazy-qPy4cMnv.cjs.map +0 -1
  63. package/dist/lazy-xrzxwnru.js.map +0 -1
  64. package/dist/runner-CnG-Ncz0.js.map +0 -1
  65. package/dist/runner-DA48D-3K.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 getAllAliases, c as toCamelCase, i as extractFields, l as toKebabCase, o as getExtractedFields, r as resolveSubCommandMeta } from "./lazy-DiMJSDMB.js";
2
+ import { a as emptyLogs, i as createLogCollector, n as resolveLazyCommand, o as mergeLogs, r as resolveSubcommand, t as listSubCommands } from "./subcommand-router--EUt6ftA.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
  /**
@@ -1016,22 +1028,36 @@ function checkDuplicateAliases(extracted, commandPath) {
1016
1028
  const errors = [];
1017
1029
  const seenAliases = /* @__PURE__ */ new Map();
1018
1030
  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({
1022
- commandPath,
1023
- 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({
1031
+ const cliNames = new Set(extracted.fields.map((f) => f.cliName));
1032
+ const registerAlias = (alias, fieldName, isDerived) => {
1033
+ if (fieldNames.has(alias) || cliNames.has(alias)) errors.push({
1029
1034
  commandPath,
1030
1035
  type: "duplicate_alias",
1031
- message: `Duplicate alias "${field.alias}" detected. Both "${existingField}" and "${field.name}" use the same alias.`,
1032
- field: field.name
1036
+ message: `Alias "${alias}" for field "${fieldName}" conflicts with existing field name or CLI name "${alias}".`,
1037
+ field: fieldName
1033
1038
  });
1034
- seenAliases.set(field.alias, field.name);
1039
+ const existingField = seenAliases.get(alias);
1040
+ if (existingField && existingField !== fieldName) {
1041
+ const qualifier = isDerived ? " (derived camelCase variant)" : "";
1042
+ errors.push({
1043
+ commandPath,
1044
+ type: "duplicate_alias",
1045
+ message: `Duplicate alias "${alias}"${qualifier} detected. Both "${existingField}" and "${fieldName}" use the same alias.`,
1046
+ field: fieldName
1047
+ });
1048
+ }
1049
+ seenAliases.set(alias, fieldName);
1050
+ };
1051
+ for (const field of extracted.fields) {
1052
+ const allAliases = getAllAliases(field);
1053
+ if (allAliases.length === 0) continue;
1054
+ for (const alias of allAliases) {
1055
+ registerAlias(alias, field.name, false);
1056
+ if (alias.length > 1 && alias.includes("-")) {
1057
+ const camelVariant = toCamelCase(alias);
1058
+ if (camelVariant !== alias && !fieldNames.has(camelVariant)) registerAlias(camelVariant, field.name, true);
1059
+ }
1060
+ }
1035
1061
  }
1036
1062
  return errors;
1037
1063
  }
@@ -1072,12 +1098,15 @@ function checkPositionalConfig(extracted, commandPath) {
1072
1098
  */
1073
1099
  function checkReservedAliases(extracted, commandPath) {
1074
1100
  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
- });
1101
+ for (const field of extracted.fields) {
1102
+ if (field.overrideBuiltinAlias === true) continue;
1103
+ for (const alias of getAllAliases(field)) if (alias === "h" || alias === "H") errors.push({
1104
+ commandPath,
1105
+ type: "reserved_alias",
1106
+ message: `Alias "${alias}" is reserved for --${alias === "h" ? "help" : "help-all"}.`,
1107
+ field: field.name
1108
+ });
1109
+ }
1081
1110
  return errors;
1082
1111
  }
1083
1112
  /**
@@ -1141,8 +1170,9 @@ function validateReservedAliases(extracted, _hasSubCommands) {
1141
1170
  const errors = checkReservedAliases(extracted, []);
1142
1171
  if (errors.length > 0) {
1143
1172
  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}".`);
1173
+ const found = extracted.fields.find((f) => f.name === field);
1174
+ const alias = (found ? getAllAliases(found) : []).find((a) => a === "h" || a === "H") ?? "h";
1175
+ 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
1176
  }
1147
1177
  }
1148
1178
  /**
@@ -1387,7 +1417,13 @@ function buildParserOptions(extracted) {
1387
1417
  for (const field of extracted.fields) definedNames.add(field.name);
1388
1418
  for (const field of extracted.fields) {
1389
1419
  if (field.cliName !== field.name) aliasMap.set(field.cliName, field.name);
1390
- if (field.alias) aliasMap.set(field.alias, field.name);
1420
+ for (const alias of getAllAliases(field)) {
1421
+ aliasMap.set(alias, field.name);
1422
+ if (alias.length > 1 && alias.includes("-")) {
1423
+ const camelAlias = toCamelCase(alias);
1424
+ if (camelAlias !== alias && !definedNames.has(camelAlias) && !aliasMap.has(camelAlias)) aliasMap.set(camelAlias, field.name);
1425
+ }
1426
+ }
1391
1427
  const camelVariant = toCamelCase(field.name);
1392
1428
  if (camelVariant !== field.name && !definedNames.has(camelVariant) && !aliasMap.has(camelVariant)) aliasMap.set(camelVariant, field.name);
1393
1429
  if (field.type === "boolean") booleanFlags.add(field.name);
@@ -1429,12 +1465,14 @@ function mergeWithPositionals(parsed, extracted) {
1429
1465
  */
1430
1466
  function buildGlobalFlagLookup(globalExtracted) {
1431
1467
  const { aliasMap = /* @__PURE__ */ new Map(), booleanFlags = /* @__PURE__ */ new Set() } = buildParserOptions(globalExtracted);
1468
+ const shortAliases = /* @__PURE__ */ new Set();
1469
+ for (const field of globalExtracted.fields) for (const alias of getAllAliases(field)) if (alias.length === 1) shortAliases.add(alias);
1432
1470
  return {
1433
1471
  aliasMap,
1434
1472
  booleanFlags,
1435
1473
  flagNames: new Set(globalExtracted.fields.map((f) => f.name)),
1436
1474
  cliNames: new Set(globalExtracted.fields.map((f) => f.cliName)),
1437
- aliases: new Set(globalExtracted.fields.filter((f) => f.alias).map((f) => f.alias))
1475
+ aliases: shortAliases
1438
1476
  };
1439
1477
  }
1440
1478
  /**
@@ -1620,8 +1658,8 @@ function parseArgs(argv, command, options = {}) {
1620
1658
  if (options.globalExtracted) validateCrossSchemaCollisions(options.globalExtracted, extracted);
1621
1659
  }
1622
1660
  }
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;
1661
+ const hasUserDefinedH = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && getAllAliases(f).includes("H")) ?? false;
1662
+ const hasUserDefinedh = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && getAllAliases(f).includes("h")) ?? false;
1625
1663
  const helpAllRequested = argv.includes("--help-all") || !hasUserDefinedH && argv.includes("-H");
1626
1664
  const helpRequested = !helpAllRequested && (argv.includes("--help") || !hasUserDefinedh && argv.includes("-h"));
1627
1665
  const versionRequested = argv.includes("--version");
@@ -1668,11 +1706,12 @@ function parseArgs(argv, command, options = {}) {
1668
1706
  }
1669
1707
  const knownFlags = new Set(extracted.fields.map((f) => f.name));
1670
1708
  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));
1709
+ const knownAliases = /* @__PURE__ */ new Set();
1710
+ for (const f of extracted.fields) for (const alias of getAllAliases(f)) knownAliases.add(alias);
1672
1711
  if (options.globalExtracted) for (const f of options.globalExtracted.fields) {
1673
1712
  knownFlags.add(f.name);
1674
1713
  knownCliNames.add(f.cliName);
1675
- if (f.alias) knownAliases.add(f.alias);
1714
+ for (const alias of getAllAliases(f)) knownAliases.add(alias);
1676
1715
  }
1677
1716
  const unknownFlags = [];
1678
1717
  for (const key of Object.keys(parsed.options)) if (!knownFlags.has(key) && !knownCliNames.has(key) && !knownAliases.has(key)) unknownFlags.push(key);
@@ -1710,8 +1749,9 @@ function parseGlobalArgs(tokens, globalExtracted) {
1710
1749
  */
1711
1750
  function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1712
1751
  const lookup = buildGlobalFlagLookup(globalExtracted);
1752
+ const localFieldNames = new Set(localExtracted?.fields.map((f) => f.name) ?? []);
1713
1753
  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) ?? []);
1754
+ const localAliasMapKeys = localExtracted ? new Set(buildParserOptions(localExtracted).aliasMap?.keys() ?? []) : /* @__PURE__ */ new Set();
1715
1755
  const globalTokens = [];
1716
1756
  const commandTokens = [];
1717
1757
  for (let i = 0; i < argv.length; i++) {
@@ -1723,7 +1763,7 @@ function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1723
1763
  if (arg.startsWith("--")) {
1724
1764
  const { resolvedName, withoutDashes, isNegated, isGlobal } = resolveGlobalLongOption(arg, lookup);
1725
1765
  const flagName = isNegated ? withoutDashes.slice(3) : withoutDashes;
1726
- const isLocalCollision = localCliNames.has(withoutDashes) || localCliNames.has(flagName);
1766
+ const isLocalCollision = localFieldNames.has(withoutDashes) || localFieldNames.has(flagName) || localCliNames.has(withoutDashes) || localCliNames.has(flagName) || localAliasMapKeys.has(withoutDashes) || localAliasMapKeys.has(flagName);
1727
1767
  if (isGlobal && !isLocalCollision) {
1728
1768
  i += collectGlobalFlag(argv, i, resolvedName, isNegated, lookup.booleanFlags, globalTokens) - 1;
1729
1769
  continue;
@@ -1732,7 +1772,7 @@ function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1732
1772
  const withoutDash = arg.includes("=") ? arg.slice(1, arg.indexOf("=")) : arg.slice(1);
1733
1773
  if (withoutDash.length === 1) {
1734
1774
  const resolvedName = lookup.aliasMap.get(withoutDash) ?? withoutDash;
1735
- if ((lookup.aliases.has(withoutDash) || lookup.flagNames.has(resolvedName)) && !localAliases.has(withoutDash)) {
1775
+ if ((lookup.aliases.has(withoutDash) || lookup.flagNames.has(resolvedName)) && !localAliasMapKeys.has(withoutDash)) {
1736
1776
  i += collectGlobalFlag(argv, i, resolvedName, false, lookup.booleanFlags, globalTokens) - 1;
1737
1777
  continue;
1738
1778
  }
@@ -2235,4 +2275,4 @@ function extractAndValidateGlobal(options) {
2235
2275
 
2236
2276
  //#endregion
2237
2277
  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
2278
+ //# sourceMappingURL=runner-DSZw1AsW.js.map