@contember/cli-common 2.2.0-alpha.2 → 2.2.0-alpha.20

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 (246) hide show
  1. package/dist/development/index.cjs +27 -0
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +29 -2
  4. package/dist/development/index.js.map +1 -1
  5. package/dist/development/src/application/Application.cjs +116 -59
  6. package/dist/development/src/application/Application.cjs.map +1 -1
  7. package/dist/development/src/application/Application.js +116 -59
  8. package/dist/development/src/application/Application.js.map +1 -1
  9. package/dist/development/src/application/CliError.cjs +104 -0
  10. package/dist/development/src/application/CliError.cjs.map +1 -0
  11. package/dist/development/src/application/CliError.js +104 -0
  12. package/dist/development/src/application/CliError.js.map +1 -0
  13. package/dist/development/src/application/Command.cjs +18 -5
  14. package/dist/development/src/application/Command.cjs.map +1 -1
  15. package/dist/development/src/application/Command.js +18 -5
  16. package/dist/development/src/application/Command.js.map +1 -1
  17. package/dist/development/src/application/CommandConfiguration.cjs +21 -3
  18. package/dist/development/src/application/CommandConfiguration.cjs.map +1 -1
  19. package/dist/development/src/application/CommandConfiguration.js +23 -5
  20. package/dist/development/src/application/CommandConfiguration.js.map +1 -1
  21. package/dist/development/src/application/CommandManager.cjs +139 -21
  22. package/dist/development/src/application/CommandManager.cjs.map +1 -1
  23. package/dist/development/src/application/CommandManager.js +139 -21
  24. package/dist/development/src/application/CommandManager.js.map +1 -1
  25. package/dist/development/src/application/ErrorRenderer.cjs +38 -0
  26. package/dist/development/src/application/ErrorRenderer.cjs.map +1 -0
  27. package/dist/development/src/application/ErrorRenderer.js +38 -0
  28. package/dist/development/src/application/ErrorRenderer.js.map +1 -0
  29. package/dist/development/src/application/GlobalOptions.cjs +54 -0
  30. package/dist/development/src/application/GlobalOptions.cjs.map +1 -0
  31. package/dist/development/src/application/GlobalOptions.js +54 -0
  32. package/dist/development/src/application/GlobalOptions.js.map +1 -0
  33. package/dist/development/src/application/Input.cjs +5 -0
  34. package/dist/development/src/application/Input.cjs.map +1 -1
  35. package/dist/development/src/application/Input.js +5 -0
  36. package/dist/development/src/application/Input.js.map +1 -1
  37. package/dist/development/src/application/InputParser.cjs +7 -3
  38. package/dist/development/src/application/InputParser.cjs.map +1 -1
  39. package/dist/development/src/application/InputParser.js +7 -3
  40. package/dist/development/src/application/InputParser.js.map +1 -1
  41. package/dist/development/src/application/Option.cjs +11 -0
  42. package/dist/development/src/application/Option.cjs.map +1 -1
  43. package/dist/development/src/application/Option.js +12 -1
  44. package/dist/development/src/application/Option.js.map +1 -1
  45. package/dist/development/src/application/Output.cjs +275 -0
  46. package/dist/development/src/application/Output.cjs.map +1 -0
  47. package/dist/development/src/application/Output.js +275 -0
  48. package/dist/development/src/application/Output.js.map +1 -0
  49. package/dist/development/src/application/colors.cjs +29 -0
  50. package/dist/development/src/application/colors.cjs.map +1 -0
  51. package/dist/development/src/application/colors.js +29 -0
  52. package/dist/development/src/application/colors.js.map +1 -0
  53. package/dist/development/src/application/exitProcess.cjs +7 -0
  54. package/dist/development/src/application/exitProcess.cjs.map +1 -0
  55. package/dist/development/src/application/exitProcess.js +7 -0
  56. package/dist/development/src/application/exitProcess.js.map +1 -0
  57. package/dist/development/src/application/table.cjs +23 -0
  58. package/dist/development/src/application/table.cjs.map +1 -0
  59. package/dist/development/src/application/table.js +23 -0
  60. package/dist/development/src/application/table.js.map +1 -0
  61. package/dist/development/src/npm/CommandRunner.cjs +126 -24
  62. package/dist/development/src/npm/CommandRunner.cjs.map +1 -1
  63. package/dist/development/src/npm/CommandRunner.js +126 -24
  64. package/dist/development/src/npm/CommandRunner.js.map +1 -1
  65. package/dist/development/src/npm/packageManagers/Bun.cjs +1 -2
  66. package/dist/development/src/npm/packageManagers/Bun.cjs.map +1 -1
  67. package/dist/development/src/npm/packageManagers/Bun.js +1 -2
  68. package/dist/development/src/npm/packageManagers/Bun.js.map +1 -1
  69. package/dist/development/src/npm/packageManagers/Npm.cjs +1 -2
  70. package/dist/development/src/npm/packageManagers/Npm.cjs.map +1 -1
  71. package/dist/development/src/npm/packageManagers/Npm.js +1 -2
  72. package/dist/development/src/npm/packageManagers/Npm.js.map +1 -1
  73. package/dist/development/src/npm/packageManagers/Pnpm.cjs +1 -2
  74. package/dist/development/src/npm/packageManagers/Pnpm.cjs.map +1 -1
  75. package/dist/development/src/npm/packageManagers/Pnpm.js +1 -2
  76. package/dist/development/src/npm/packageManagers/Pnpm.js.map +1 -1
  77. package/dist/development/src/npm/packageManagers/Yarn.cjs +1 -2
  78. package/dist/development/src/npm/packageManagers/Yarn.cjs.map +1 -1
  79. package/dist/development/src/npm/packageManagers/Yarn.js +1 -2
  80. package/dist/development/src/npm/packageManagers/Yarn.js.map +1 -1
  81. package/dist/development/src/npm/packageManagers/YarnClassic.cjs +1 -2
  82. package/dist/development/src/npm/packageManagers/YarnClassic.cjs.map +1 -1
  83. package/dist/development/src/npm/packageManagers/YarnClassic.js +1 -2
  84. package/dist/development/src/npm/packageManagers/YarnClassic.js.map +1 -1
  85. package/dist/production/index.cjs +27 -0
  86. package/dist/production/index.cjs.map +1 -1
  87. package/dist/production/index.js +29 -2
  88. package/dist/production/index.js.map +1 -1
  89. package/dist/production/src/application/Application.cjs +116 -59
  90. package/dist/production/src/application/Application.cjs.map +1 -1
  91. package/dist/production/src/application/Application.js +116 -59
  92. package/dist/production/src/application/Application.js.map +1 -1
  93. package/dist/production/src/application/CliError.cjs +104 -0
  94. package/dist/production/src/application/CliError.cjs.map +1 -0
  95. package/dist/production/src/application/CliError.js +104 -0
  96. package/dist/production/src/application/CliError.js.map +1 -0
  97. package/dist/production/src/application/Command.cjs +18 -5
  98. package/dist/production/src/application/Command.cjs.map +1 -1
  99. package/dist/production/src/application/Command.js +18 -5
  100. package/dist/production/src/application/Command.js.map +1 -1
  101. package/dist/production/src/application/CommandConfiguration.cjs +21 -3
  102. package/dist/production/src/application/CommandConfiguration.cjs.map +1 -1
  103. package/dist/production/src/application/CommandConfiguration.js +23 -5
  104. package/dist/production/src/application/CommandConfiguration.js.map +1 -1
  105. package/dist/production/src/application/CommandManager.cjs +139 -21
  106. package/dist/production/src/application/CommandManager.cjs.map +1 -1
  107. package/dist/production/src/application/CommandManager.js +139 -21
  108. package/dist/production/src/application/CommandManager.js.map +1 -1
  109. package/dist/production/src/application/ErrorRenderer.cjs +38 -0
  110. package/dist/production/src/application/ErrorRenderer.cjs.map +1 -0
  111. package/dist/production/src/application/ErrorRenderer.js +38 -0
  112. package/dist/production/src/application/ErrorRenderer.js.map +1 -0
  113. package/dist/production/src/application/GlobalOptions.cjs +54 -0
  114. package/dist/production/src/application/GlobalOptions.cjs.map +1 -0
  115. package/dist/production/src/application/GlobalOptions.js +54 -0
  116. package/dist/production/src/application/GlobalOptions.js.map +1 -0
  117. package/dist/production/src/application/Input.cjs +5 -0
  118. package/dist/production/src/application/Input.cjs.map +1 -1
  119. package/dist/production/src/application/Input.js +5 -0
  120. package/dist/production/src/application/Input.js.map +1 -1
  121. package/dist/production/src/application/InputParser.cjs +7 -3
  122. package/dist/production/src/application/InputParser.cjs.map +1 -1
  123. package/dist/production/src/application/InputParser.js +7 -3
  124. package/dist/production/src/application/InputParser.js.map +1 -1
  125. package/dist/production/src/application/Option.cjs +11 -0
  126. package/dist/production/src/application/Option.cjs.map +1 -1
  127. package/dist/production/src/application/Option.js +12 -1
  128. package/dist/production/src/application/Option.js.map +1 -1
  129. package/dist/production/src/application/Output.cjs +275 -0
  130. package/dist/production/src/application/Output.cjs.map +1 -0
  131. package/dist/production/src/application/Output.js +275 -0
  132. package/dist/production/src/application/Output.js.map +1 -0
  133. package/dist/production/src/application/colors.cjs +29 -0
  134. package/dist/production/src/application/colors.cjs.map +1 -0
  135. package/dist/production/src/application/colors.js +29 -0
  136. package/dist/production/src/application/colors.js.map +1 -0
  137. package/dist/production/src/application/exitProcess.cjs +7 -0
  138. package/dist/production/src/application/exitProcess.cjs.map +1 -0
  139. package/dist/production/src/application/exitProcess.js +7 -0
  140. package/dist/production/src/application/exitProcess.js.map +1 -0
  141. package/dist/production/src/application/table.cjs +23 -0
  142. package/dist/production/src/application/table.cjs.map +1 -0
  143. package/dist/production/src/application/table.js +23 -0
  144. package/dist/production/src/application/table.js.map +1 -0
  145. package/dist/production/src/npm/CommandRunner.cjs +126 -24
  146. package/dist/production/src/npm/CommandRunner.cjs.map +1 -1
  147. package/dist/production/src/npm/CommandRunner.js +126 -24
  148. package/dist/production/src/npm/CommandRunner.js.map +1 -1
  149. package/dist/production/src/npm/packageManagers/Bun.cjs +1 -2
  150. package/dist/production/src/npm/packageManagers/Bun.cjs.map +1 -1
  151. package/dist/production/src/npm/packageManagers/Bun.js +1 -2
  152. package/dist/production/src/npm/packageManagers/Bun.js.map +1 -1
  153. package/dist/production/src/npm/packageManagers/Npm.cjs +1 -2
  154. package/dist/production/src/npm/packageManagers/Npm.cjs.map +1 -1
  155. package/dist/production/src/npm/packageManagers/Npm.js +1 -2
  156. package/dist/production/src/npm/packageManagers/Npm.js.map +1 -1
  157. package/dist/production/src/npm/packageManagers/Pnpm.cjs +1 -2
  158. package/dist/production/src/npm/packageManagers/Pnpm.cjs.map +1 -1
  159. package/dist/production/src/npm/packageManagers/Pnpm.js +1 -2
  160. package/dist/production/src/npm/packageManagers/Pnpm.js.map +1 -1
  161. package/dist/production/src/npm/packageManagers/Yarn.cjs +1 -2
  162. package/dist/production/src/npm/packageManagers/Yarn.cjs.map +1 -1
  163. package/dist/production/src/npm/packageManagers/Yarn.js +1 -2
  164. package/dist/production/src/npm/packageManagers/Yarn.js.map +1 -1
  165. package/dist/production/src/npm/packageManagers/YarnClassic.cjs +1 -2
  166. package/dist/production/src/npm/packageManagers/YarnClassic.cjs.map +1 -1
  167. package/dist/production/src/npm/packageManagers/YarnClassic.js +1 -2
  168. package/dist/production/src/npm/packageManagers/YarnClassic.js.map +1 -1
  169. package/dist/types/application/Application.d.ts +22 -11
  170. package/dist/types/application/Application.d.ts.map +1 -1
  171. package/dist/types/application/Argument.d.ts.map +1 -1
  172. package/dist/types/application/CliError.d.ts +40 -0
  173. package/dist/types/application/CliError.d.ts.map +1 -0
  174. package/dist/types/application/Command.d.ts +12 -2
  175. package/dist/types/application/Command.d.ts.map +1 -1
  176. package/dist/types/application/CommandConfiguration.d.ts +7 -4
  177. package/dist/types/application/CommandConfiguration.d.ts.map +1 -1
  178. package/dist/types/application/CommandManager.d.ts +40 -2
  179. package/dist/types/application/CommandManager.d.ts.map +1 -1
  180. package/dist/types/application/ErrorRenderer.d.ts +8 -0
  181. package/dist/types/application/ErrorRenderer.d.ts.map +1 -0
  182. package/dist/types/application/GlobalOptions.d.ts +28 -0
  183. package/dist/types/application/GlobalOptions.d.ts.map +1 -0
  184. package/dist/types/application/Input.d.ts +2 -0
  185. package/dist/types/application/Input.d.ts.map +1 -1
  186. package/dist/types/application/InputParser.d.ts +5 -1
  187. package/dist/types/application/InputParser.d.ts.map +1 -1
  188. package/dist/types/application/Option.d.ts +2 -0
  189. package/dist/types/application/Option.d.ts.map +1 -1
  190. package/dist/types/application/Output.d.ts +96 -0
  191. package/dist/types/application/Output.d.ts.map +1 -0
  192. package/dist/types/application/UsageFormatter.d.ts.map +1 -1
  193. package/dist/types/application/colors.d.ts +10 -0
  194. package/dist/types/application/colors.d.ts.map +1 -0
  195. package/dist/types/application/exitProcess.d.ts +11 -0
  196. package/dist/types/application/exitProcess.d.ts.map +1 -0
  197. package/dist/types/application/index.d.ts +7 -0
  198. package/dist/types/application/index.d.ts.map +1 -1
  199. package/dist/types/application/table.d.ts +7 -0
  200. package/dist/types/application/table.d.ts.map +1 -0
  201. package/dist/types/index.d.ts +2 -2
  202. package/dist/types/index.d.ts.map +1 -1
  203. package/dist/types/npm/CommandRunner.d.ts +13 -0
  204. package/dist/types/npm/CommandRunner.d.ts.map +1 -1
  205. package/dist/types/npm/Package.d.ts.map +1 -1
  206. package/dist/types/npm/PackageWorkspace.d.ts.map +1 -1
  207. package/dist/types/npm/PackageWorkspaceResolver.d.ts.map +1 -1
  208. package/dist/types/npm/packageManagers/Bun.d.ts.map +1 -1
  209. package/dist/types/npm/packageManagers/Npm.d.ts.map +1 -1
  210. package/dist/types/npm/packageManagers/PackageManagerHelpers.d.ts.map +1 -1
  211. package/dist/types/npm/packageManagers/Pnpm.d.ts.map +1 -1
  212. package/dist/types/npm/packageManagers/Yarn.d.ts.map +1 -1
  213. package/dist/types/npm/packageManagers/YarnClassic.d.ts.map +1 -1
  214. package/dist/types/tsconfig.tsbuildinfo +1 -1
  215. package/dist/types/utils/findPackageRoot.d.ts.map +1 -1
  216. package/package.json +2 -6
  217. package/src/application/Application.ts +138 -76
  218. package/src/application/CliError.ts +117 -0
  219. package/src/application/Command.ts +27 -6
  220. package/src/application/CommandConfiguration.ts +22 -4
  221. package/src/application/CommandManager.ts +172 -22
  222. package/src/application/ErrorRenderer.ts +40 -0
  223. package/src/application/GlobalOptions.ts +76 -0
  224. package/src/application/Input.ts +6 -0
  225. package/src/application/InputParser.ts +13 -4
  226. package/src/application/Option.ts +12 -0
  227. package/src/application/Output.ts +365 -0
  228. package/src/application/colors.ts +36 -0
  229. package/src/application/exitProcess.ts +12 -0
  230. package/src/application/index.ts +7 -0
  231. package/src/application/table.ts +31 -0
  232. package/src/index.ts +47 -2
  233. package/src/npm/CommandRunner.ts +166 -23
  234. package/src/npm/packageManagers/Bun.ts +1 -2
  235. package/src/npm/packageManagers/Npm.ts +1 -2
  236. package/src/npm/packageManagers/Pnpm.ts +1 -2
  237. package/src/npm/packageManagers/Yarn.ts +1 -2
  238. package/src/npm/packageManagers/YarnClassic.ts +1 -2
  239. package/tests/cases/unit/application.test.ts +426 -0
  240. package/tests/cases/unit/cliError.test.ts +127 -0
  241. package/tests/cases/unit/colors.test.ts +49 -0
  242. package/tests/cases/unit/commandManager.test.ts +270 -0
  243. package/tests/cases/unit/commandRunner.test.ts +192 -0
  244. package/tests/cases/unit/inputParser.test.ts +21 -0
  245. package/tests/cases/unit/output.test.ts +434 -0
  246. package/tests/lib/testOutput.ts +43 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GlobalOptions.js","sources":["../../../../../packages/cli-common/src/application/GlobalOptions.ts"],"sourcesContent":["import { Option, OptionMode } from './Option.js'\n\nexport interface GlobalOptionValues {\n\treadonly json: boolean\n\treadonly quiet: boolean\n\t/** false when --no-color was passed */\n\treadonly color: boolean\n\treadonly help: boolean\n}\n\n/**\n * Options available on every command. Their names and shortcuts are reserved for the global parser.\n */\nexport const globalOptions: readonly Option[] = [\n\t{ name: 'json', required: false, deprecated: false, mode: OptionMode.VALUE_NONE, description: 'Print machine readable JSON to stdout' },\n\t{\n\t\tname: 'quiet',\n\t\tshortcut: 'q',\n\t\trequired: false,\n\t\tdeprecated: false,\n\t\tmode: OptionMode.VALUE_NONE,\n\t\tdescription: 'Print only the resulting data to stdout',\n\t},\n\t{ name: 'no-color', required: false, deprecated: false, mode: OptionMode.VALUE_NONE, description: 'Disable colored output' },\n\t{ name: 'help', shortcut: 'h', required: false, deprecated: false, mode: OptionMode.VALUE_NONE, description: 'Print help of the command' },\n]\n\nexport interface RawOptionReader {\n\tgetRawOption(name: string): string | boolean | string[] | undefined\n}\n\n/**\n * Reads the global options from a parsed input.\n */\nexport const readGlobalOptions = (input: RawOptionReader): GlobalOptionValues => ({\n\tjson: input.getRawOption('json') === true,\n\tquiet: input.getRawOption('quiet') === true,\n\tcolor: input.getRawOption('no-color') !== true,\n\thelp: input.getRawOption('help') === true,\n})\n\n/**\n * Reads the global options straight from argv, before the command parser runs. Only used to pick the\n * rendering mode early (so that a parse error is reported in the requested format) and to detect\n * --help. Nothing is removed from argv, so parsing semantics stay untouched. A token starting with a\n * dash can never be consumed as a value by {@link InputParser}, so this scan cannot misread a value.\n */\nexport const readGlobalOptionsFromArgs = (args: string[]): GlobalOptionValues => {\n\tlet json = false\n\tlet quiet = false\n\tlet color = true\n\tlet help = false\n\tfor (const arg of args) {\n\t\tif (!arg.startsWith('-')) {\n\t\t\tcontinue\n\t\t}\n\t\tconst token = arg.split('=', 2)[0]\n\t\tif (isGlobalOptionToken(token, 'json')) {\n\t\t\tjson = true\n\t\t} else if (isGlobalOptionToken(token, 'quiet')) {\n\t\t\tquiet = true\n\t\t} else if (isGlobalOptionToken(token, 'no-color')) {\n\t\t\tcolor = false\n\t\t} else if (isGlobalOptionToken(token, 'help')) {\n\t\t\thelp = true\n\t\t}\n\t}\n\treturn { json, quiet, color, help }\n}\n\nconst isGlobalOptionToken = (token: string, name: string): boolean => {\n\tconst option = globalOptions.find(item => item.name === name)\n\treturn option !== undefined && (token === `--${option.name}` || (option.shortcut !== undefined && token === `-${option.shortcut}`))\n}\n\nexport const hasHelpFlag = (args: string[]): boolean => readGlobalOptionsFromArgs(args).help\n"],"names":[],"mappings":";AAaO,MAAM,gBAAmC;AAAA,EAC/C,EAAE,MAAM,QAAQ,UAAU,OAAO,YAAY,OAAO,MAAM,WAAW,YAAY,aAAa,wCAAA;AAAA,EAC9F;AAAA,IACC,MAAM;AAAA,IACN,UAAU;AAAA,IACV,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,MAAM,WAAW;AAAA,IACjB,aAAa;AAAA,EAAA;AAAA,EAEd,EAAE,MAAM,YAAY,UAAU,OAAO,YAAY,OAAO,MAAM,WAAW,YAAY,aAAa,yBAAA;AAAA,EAClG,EAAE,MAAM,QAAQ,UAAU,KAAK,UAAU,OAAO,YAAY,OAAO,MAAM,WAAW,YAAY,aAAa,4BAAA;AAC9G;AASO,MAAM,oBAAoB,CAAC,WAAgD;AAAA,EACjF,MAAM,MAAM,aAAa,MAAM,MAAM;AAAA,EACrC,OAAO,MAAM,aAAa,OAAO,MAAM;AAAA,EACvC,OAAO,MAAM,aAAa,UAAU,MAAM;AAAA,EAC1C,MAAM,MAAM,aAAa,MAAM,MAAM;AACtC;AAQO,MAAM,4BAA4B,CAAC,SAAuC;AAChF,MAAI,OAAO;AACX,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,MAAI,OAAO;AACX,aAAW,OAAO,MAAM;AACvB,QAAI,CAAC,IAAI,WAAW,GAAG,GAAG;AACzB;AAAA,IACD;AACA,UAAM,QAAQ,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;AACjC,QAAI,oBAAoB,OAAO,MAAM,GAAG;AACvC,aAAO;AAAA,IACR,WAAW,oBAAoB,OAAO,OAAO,GAAG;AAC/C,cAAQ;AAAA,IACT,WAAW,oBAAoB,OAAO,UAAU,GAAG;AAClD,cAAQ;AAAA,IACT,WAAW,oBAAoB,OAAO,MAAM,GAAG;AAC9C,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO,EAAE,MAAM,OAAO,OAAO,KAAA;AAC9B;AAEA,MAAM,sBAAsB,CAAC,OAAe,SAA0B;AACrE,QAAM,SAAS,cAAc,KAAK,CAAA,SAAQ,KAAK,SAAS,IAAI;AAC5D,SAAO,WAAW,WAAc,UAAU,KAAK,OAAO,IAAI,MAAO,OAAO,aAAa,UAAa,UAAU,IAAI,OAAO,QAAQ;AAChI;AAEO,MAAM,cAAc,CAAC,SAA4B,0BAA0B,IAAI,EAAE;"}
@@ -8,6 +8,11 @@ class Input {
8
8
  getOption(name) {
9
9
  return this.options[name];
10
10
  }
11
+ /** Reads an option that is not part of the command signature — the global ones parsed in the same pass. */
12
+ getRawOption(name) {
13
+ const options = this.options;
14
+ return options[name];
15
+ }
11
16
  getArgument(name) {
12
17
  return this.args[name];
13
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Input.cjs","sources":["../../../../../packages/cli-common/src/application/Input.ts"],"sourcesContent":["export type Arguments = Record<string, string | string[] | undefined>\nexport type Options = Record<string, string | boolean | string[] | undefined>\n\nexport class Input<Args extends Arguments = Arguments, Opts extends Options = Options> {\n\tconstructor(private readonly args: Args, private readonly options: Opts) {}\n\n\tgetOption<Name extends keyof Opts>(name: Name): Opts[Name] {\n\t\treturn this.options[name]\n\t}\n\n\tgetArgument<Name extends keyof Args>(name: Name): Args[Name] {\n\t\treturn this.args[name]\n\t}\n}\n"],"names":[],"mappings":";;AAGO,MAAM,MAA0E;AAAA,EACtF,YAA6B,MAA6B,SAAe;AAA5C,SAAA,OAAA;AAA6B,SAAA,UAAA;AAAA,EAAgB;AAAA,EAE1E,UAAmC,MAAwB;AAC1D,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA,EAEA,YAAqC,MAAwB;AAC5D,WAAO,KAAK,KAAK,IAAI;AAAA,EACtB;AACD;;"}
1
+ {"version":3,"file":"Input.cjs","sources":["../../../../../packages/cli-common/src/application/Input.ts"],"sourcesContent":["export type Arguments = Record<string, string | string[] | undefined>\nexport type Options = Record<string, string | boolean | string[] | undefined>\n\nexport class Input<Args extends Arguments = Arguments, Opts extends Options = Options> {\n\tconstructor(private readonly args: Args, private readonly options: Opts) {}\n\n\tgetOption<Name extends keyof Opts>(name: Name): Opts[Name] {\n\t\treturn this.options[name]\n\t}\n\n\t/** Reads an option that is not part of the command signature — the global ones parsed in the same pass. */\n\tgetRawOption(name: string): string | boolean | string[] | undefined {\n\t\tconst options: Options = this.options\n\t\treturn options[name]\n\t}\n\n\tgetArgument<Name extends keyof Args>(name: Name): Args[Name] {\n\t\treturn this.args[name]\n\t}\n}\n"],"names":[],"mappings":";;AAGO,MAAM,MAA0E;AAAA,EACtF,YAA6B,MAA6B,SAAe;AAA5C,SAAA,OAAA;AAA6B,SAAA,UAAA;AAAA,EAAgB;AAAA,EAE1E,UAAmC,MAAwB;AAC1D,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA,EAGA,aAAa,MAAuD;AACnE,UAAM,UAAmB,KAAK;AAC9B,WAAO,QAAQ,IAAI;AAAA,EACpB;AAAA,EAEA,YAAqC,MAAwB;AAC5D,WAAO,KAAK,KAAK,IAAI;AAAA,EACtB;AACD;;"}
@@ -6,6 +6,11 @@ class Input {
6
6
  getOption(name) {
7
7
  return this.options[name];
8
8
  }
9
+ /** Reads an option that is not part of the command signature — the global ones parsed in the same pass. */
10
+ getRawOption(name) {
11
+ const options = this.options;
12
+ return options[name];
13
+ }
9
14
  getArgument(name) {
10
15
  return this.args[name];
11
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Input.js","sources":["../../../../../packages/cli-common/src/application/Input.ts"],"sourcesContent":["export type Arguments = Record<string, string | string[] | undefined>\nexport type Options = Record<string, string | boolean | string[] | undefined>\n\nexport class Input<Args extends Arguments = Arguments, Opts extends Options = Options> {\n\tconstructor(private readonly args: Args, private readonly options: Opts) {}\n\n\tgetOption<Name extends keyof Opts>(name: Name): Opts[Name] {\n\t\treturn this.options[name]\n\t}\n\n\tgetArgument<Name extends keyof Args>(name: Name): Args[Name] {\n\t\treturn this.args[name]\n\t}\n}\n"],"names":[],"mappings":"AAGO,MAAM,MAA0E;AAAA,EACtF,YAA6B,MAA6B,SAAe;AAA5C,SAAA,OAAA;AAA6B,SAAA,UAAA;AAAA,EAAgB;AAAA,EAE1E,UAAmC,MAAwB;AAC1D,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA,EAEA,YAAqC,MAAwB;AAC5D,WAAO,KAAK,KAAK,IAAI;AAAA,EACtB;AACD;"}
1
+ {"version":3,"file":"Input.js","sources":["../../../../../packages/cli-common/src/application/Input.ts"],"sourcesContent":["export type Arguments = Record<string, string | string[] | undefined>\nexport type Options = Record<string, string | boolean | string[] | undefined>\n\nexport class Input<Args extends Arguments = Arguments, Opts extends Options = Options> {\n\tconstructor(private readonly args: Args, private readonly options: Opts) {}\n\n\tgetOption<Name extends keyof Opts>(name: Name): Opts[Name] {\n\t\treturn this.options[name]\n\t}\n\n\t/** Reads an option that is not part of the command signature — the global ones parsed in the same pass. */\n\tgetRawOption(name: string): string | boolean | string[] | undefined {\n\t\tconst options: Options = this.options\n\t\treturn options[name]\n\t}\n\n\tgetArgument<Name extends keyof Args>(name: Name): Args[Name] {\n\t\treturn this.args[name]\n\t}\n}\n"],"names":[],"mappings":"AAGO,MAAM,MAA0E;AAAA,EACtF,YAA6B,MAA6B,SAAe;AAA5C,SAAA,OAAA;AAA6B,SAAA,UAAA;AAAA,EAAgB;AAAA,EAE1E,UAAmC,MAAwB;AAC1D,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA,EAGA,aAAa,MAAuD;AACnE,UAAM,UAAmB,KAAK;AAC9B,WAAO,QAAQ,IAAI;AAAA,EACpB;AAAA,EAEA,YAAqC,MAAwB;AAC5D,WAAO,KAAK,KAAK,IAAI;AAAA,EACtB;AACD;"}
@@ -8,9 +8,13 @@ class InputParser {
8
8
  this.options = options;
9
9
  }
10
10
  parse(args) {
11
- args = args.reduce((acc, arg) => [...acc, ...arg.startsWith("-") ? arg.split("=", 2) : [arg]], []);
11
+ args = args.flatMap((arg) => {
12
+ const separator = arg.startsWith("-") ? arg.indexOf("=") : -1;
13
+ return separator === -1 ? [arg] : [arg.slice(0, separator), arg.slice(separator + 1)];
14
+ });
12
15
  let options = {};
13
16
  let argumentValues = {};
17
+ const diagnostics = [];
14
18
  let i = 0;
15
19
  let argumentNumber = 0;
16
20
  const variadicArg = this._arguments[this._arguments.length - 1]?.variadic ? this._arguments[this._arguments.length - 1] : void 0;
@@ -59,7 +63,7 @@ class InputParser {
59
63
  }
60
64
  if (option) {
61
65
  if (option.deprecated) {
62
- console.warn(`Option ${option.name} is deprecated.`);
66
+ diagnostics.push(`Option --${option.name} is deprecated.`);
63
67
  }
64
68
  if (option.mode === Option.OptionMode.VALUE_NONE) {
65
69
  options[option.name] = true;
@@ -95,7 +99,7 @@ class InputParser {
95
99
  options[option.name] = void 0;
96
100
  }
97
101
  }
98
- return new Input.Input(argumentValues, options);
102
+ return { input: new Input.Input(argumentValues, options), diagnostics };
99
103
  }
100
104
  tryParseValue(arg) {
101
105
  if (arg === void 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"InputParser.cjs","sources":["../../../../../packages/cli-common/src/application/InputParser.ts"],"sourcesContent":["import { Argument } from './Argument.js'\nimport { Option, OptionMode } from './Option.js'\nimport { Arguments, Input, Options } from './Input.js'\n\nexport class InputParser {\n\tconstructor(private _arguments: Argument[], private options: Option[]) {}\n\n\tparse<Args extends Arguments, Opts extends Options>(args: string[]): Input<Args, Opts> {\n\t\targs = args.reduce<string[]>((acc, arg) => [...acc, ...(arg.startsWith('-') ? arg.split('=', 2) : [arg])], [])\n\t\tlet options: Options = {}\n\t\tlet argumentValues: Arguments = {}\n\n\t\tlet i = 0\n\t\tlet argumentNumber = 0\n\t\tconst variadicArg = this._arguments[this._arguments.length - 1]?.variadic\n\t\t\t? this._arguments[this._arguments.length - 1]\n\t\t\t: undefined\n\t\tfor (; i < args.length; i++) {\n\t\t\tconst value = this.tryParseValue(args[i])\n\t\t\tif (value === undefined) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tconst argument = this._arguments[argumentNumber] || variadicArg\n\t\t\tif (!argument) {\n\t\t\t\tthrow new InvalidInputError(`Unresolved argument for value \"${value}\"`)\n\t\t\t}\n\t\t\tif (argument.validator && !argument.validator(value)) {\n\t\t\t\tthrow new InvalidInputError(`Invalid value \"${value}\" for argument ${argument.name}`)\n\t\t\t}\n\t\t\tif (argument.variadic) {\n\t\t\t\targumentValues[argument.name] = argumentValues[argument.name] || []\n\t\t\t\t;(argumentValues[argument.name] as Array<string>).push(value)\n\t\t\t} else {\n\t\t\t\targumentValues[argument.name] = value\n\t\t\t}\n\t\t\targumentNumber++\n\t\t}\n\t\tfor (; argumentNumber < this._arguments.length; argumentNumber++) {\n\t\t\tif (!this._arguments[argumentNumber].optional) {\n\t\t\t\tthrow new InvalidInputError(`Argument ${this._arguments[argumentNumber].name} is required`)\n\t\t\t} else {\n\t\t\t\targumentValues[this._arguments[argumentNumber].name] = undefined\n\t\t\t}\n\t\t}\n\n\t\tfor (; i < args.length; i++) {\n\t\t\tlet option: Option | undefined\n\t\t\tif (args[i].startsWith('--')) {\n\t\t\t\toption = this.options.find(it => it.name === args[i].slice(2))\n\t\t\t\tif (!option) {\n\t\t\t\t\tthrow new InvalidInputError(`Undefined option ${args[i]}`)\n\t\t\t\t}\n\t\t\t} else if (args[i].startsWith('-')) {\n\t\t\t\toption = this.options.find(it => it.shortcut === args[i].slice(1))\n\t\t\t\tif (!option) {\n\t\t\t\t\tthrow new InvalidInputError(`Undefined option ${args[i]}`)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!option) {\n\t\t\t\tthrow new InvalidInputError(`Unexpected value \"${args[i]}\"`)\n\t\t\t}\n\t\t\tif (option) {\n\t\t\t\tif (option.deprecated) {\n\t\t\t\t\tconsole.warn(`Option ${option.name} is deprecated.`)\n\t\t\t\t}\n\t\t\t\tif (option.mode === OptionMode.VALUE_NONE) {\n\t\t\t\t\toptions[option.name] = true\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst value = this.tryParseValue(args[i + 1])\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\ti++\n\t\t\t\t}\n\t\t\t\tif (option.mode === OptionMode.VALUE_ARRAY) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tthrow new InvalidInputError(`Undefined value for option --${option.name}`)\n\t\t\t\t\t}\n\t\t\t\t\toptions[option.name] = options[option.name] || []\n\t\t\t\t\t;(options[option.name] as Array<string>).push(value)\n\t\t\t\t} else if (option.mode === OptionMode.VALUE_REQUIRED) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tthrow new InvalidInputError(`Undefined value for option --${option.name}`)\n\t\t\t\t\t}\n\t\t\t\t\toptions[option.name] = value\n\t\t\t\t} else if (option.mode === OptionMode.VALUE_OPTIONAL) {\n\t\t\t\t\toptions[option.name] = value === undefined ? true : value\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (let option of this.options) {\n\t\t\tif (options[option.name] !== undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (option.required) {\n\t\t\t\tthrow new InvalidInputError(`Option --${option.name} is required`)\n\t\t\t} else {\n\t\t\t\toptions[option.name] = undefined\n\t\t\t}\n\t\t}\n\n\t\treturn new Input<Args, Opts>(argumentValues as Args, options as Opts)\n\t}\n\n\tprivate tryParseValue(arg: string | undefined): string | undefined {\n\t\tif (arg === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (arg.startsWith('-')) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (arg.startsWith('\\\\-')) {\n\t\t\treturn '-' + arg.slice(1)\n\t\t}\n\t\treturn arg\n\t}\n}\n\nexport class InvalidInputError extends Error {}\n"],"names":["OptionMode","Input"],"mappings":";;;;AAIO,MAAM,YAAY;AAAA,EACxB,YAAoB,YAAgC,SAAmB;AAAnD,SAAA,aAAA;AAAgC,SAAA,UAAA;AAAA,EAAoB;AAAA,EAExE,MAAoD,MAAmC;AACtF,WAAO,KAAK,OAAiB,CAAC,KAAK,QAAQ,CAAC,GAAG,KAAK,GAAI,IAAI,WAAW,GAAG,IAAI,IAAI,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAE,GAAG,EAAE;AAC7G,QAAI,UAAmB,CAAA;AACvB,QAAI,iBAA4B,CAAA;AAEhC,QAAI,IAAI;AACR,QAAI,iBAAiB;AACrB,UAAM,cAAc,KAAK,WAAW,KAAK,WAAW,SAAS,CAAC,GAAG,WAC9D,KAAK,WAAW,KAAK,WAAW,SAAS,CAAC,IAC1C;AACH,WAAO,IAAI,KAAK,QAAQ,KAAK;AAC5B,YAAM,QAAQ,KAAK,cAAc,KAAK,CAAC,CAAC;AACxC,UAAI,UAAU,QAAW;AACxB;AAAA,MACD;AACA,YAAM,WAAW,KAAK,WAAW,cAAc,KAAK;AACpD,UAAI,CAAC,UAAU;AACd,cAAM,IAAI,kBAAkB,kCAAkC,KAAK,GAAG;AAAA,MACvE;AACA,UAAI,SAAS,aAAa,CAAC,SAAS,UAAU,KAAK,GAAG;AACrD,cAAM,IAAI,kBAAkB,kBAAkB,KAAK,kBAAkB,SAAS,IAAI,EAAE;AAAA,MACrF;AACA,UAAI,SAAS,UAAU;AACtB,uBAAe,SAAS,IAAI,IAAI,eAAe,S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
1
+ {"version":3,"file":"InputParser.cjs","sources":["../../../../../packages/cli-common/src/application/InputParser.ts"],"sourcesContent":["import { Argument } from './Argument.js'\nimport { Option, OptionMode } from './Option.js'\nimport { Arguments, Input, Options } from './Input.js'\n\nexport interface InputParserResult<Args extends Arguments, Opts extends Options> {\n\treadonly input: Input<Args, Opts>\n\treadonly diagnostics: readonly string[]\n}\n\nexport class InputParser {\n\tconstructor(private _arguments: Argument[], private options: Option[]) {}\n\n\tparse<Args extends Arguments, Opts extends Options>(args: string[]): InputParserResult<Args, Opts> {\n\t\targs = args.flatMap(arg => {\n\t\t\tconst separator = arg.startsWith('-') ? arg.indexOf('=') : -1\n\t\t\treturn separator === -1 ? [arg] : [arg.slice(0, separator), arg.slice(separator + 1)]\n\t\t})\n\t\tlet options: Options = {}\n\t\tlet argumentValues: Arguments = {}\n\t\tconst diagnostics: string[] = []\n\n\t\tlet i = 0\n\t\tlet argumentNumber = 0\n\t\tconst variadicArg = this._arguments[this._arguments.length - 1]?.variadic\n\t\t\t? this._arguments[this._arguments.length - 1]\n\t\t\t: undefined\n\t\tfor (; i < args.length; i++) {\n\t\t\tconst value = this.tryParseValue(args[i])\n\t\t\tif (value === undefined) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tconst argument = this._arguments[argumentNumber] || variadicArg\n\t\t\tif (!argument) {\n\t\t\t\tthrow new InvalidInputError(`Unresolved argument for value \"${value}\"`)\n\t\t\t}\n\t\t\tif (argument.validator && !argument.validator(value)) {\n\t\t\t\tthrow new InvalidInputError(`Invalid value \"${value}\" for argument ${argument.name}`)\n\t\t\t}\n\t\t\tif (argument.variadic) {\n\t\t\t\targumentValues[argument.name] = argumentValues[argument.name] || []\n\t\t\t\t;(argumentValues[argument.name] as Array<string>).push(value)\n\t\t\t} else {\n\t\t\t\targumentValues[argument.name] = value\n\t\t\t}\n\t\t\targumentNumber++\n\t\t}\n\t\tfor (; argumentNumber < this._arguments.length; argumentNumber++) {\n\t\t\tif (!this._arguments[argumentNumber].optional) {\n\t\t\t\tthrow new InvalidInputError(`Argument ${this._arguments[argumentNumber].name} is required`)\n\t\t\t} else {\n\t\t\t\targumentValues[this._arguments[argumentNumber].name] = undefined\n\t\t\t}\n\t\t}\n\n\t\tfor (; i < args.length; i++) {\n\t\t\tlet option: Option | undefined\n\t\t\tif (args[i].startsWith('--')) {\n\t\t\t\toption = this.options.find(it => it.name === args[i].slice(2))\n\t\t\t\tif (!option) {\n\t\t\t\t\tthrow new InvalidInputError(`Undefined option ${args[i]}`)\n\t\t\t\t}\n\t\t\t} else if (args[i].startsWith('-')) {\n\t\t\t\toption = this.options.find(it => it.shortcut === args[i].slice(1))\n\t\t\t\tif (!option) {\n\t\t\t\t\tthrow new InvalidInputError(`Undefined option ${args[i]}`)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!option) {\n\t\t\t\tthrow new InvalidInputError(`Unexpected value \"${args[i]}\"`)\n\t\t\t}\n\t\t\tif (option) {\n\t\t\t\tif (option.deprecated) {\n\t\t\t\t\tdiagnostics.push(`Option --${option.name} is deprecated.`)\n\t\t\t\t}\n\t\t\t\tif (option.mode === OptionMode.VALUE_NONE) {\n\t\t\t\t\toptions[option.name] = true\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst value = this.tryParseValue(args[i + 1])\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\ti++\n\t\t\t\t}\n\t\t\t\tif (option.mode === OptionMode.VALUE_ARRAY) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tthrow new InvalidInputError(`Undefined value for option --${option.name}`)\n\t\t\t\t\t}\n\t\t\t\t\toptions[option.name] = options[option.name] || []\n\t\t\t\t\t;(options[option.name] as Array<string>).push(value)\n\t\t\t\t} else if (option.mode === OptionMode.VALUE_REQUIRED) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tthrow new InvalidInputError(`Undefined value for option --${option.name}`)\n\t\t\t\t\t}\n\t\t\t\t\toptions[option.name] = value\n\t\t\t\t} else if (option.mode === OptionMode.VALUE_OPTIONAL) {\n\t\t\t\t\toptions[option.name] = value === undefined ? true : value\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (let option of this.options) {\n\t\t\tif (options[option.name] !== undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (option.required) {\n\t\t\t\tthrow new InvalidInputError(`Option --${option.name} is required`)\n\t\t\t} else {\n\t\t\t\toptions[option.name] = undefined\n\t\t\t}\n\t\t}\n\n\t\treturn { input: new Input<Args, Opts>(argumentValues as Args, options as Opts), diagnostics }\n\t}\n\n\tprivate tryParseValue(arg: string | undefined): string | undefined {\n\t\tif (arg === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (arg.startsWith('-')) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (arg.startsWith('\\\\-')) {\n\t\t\treturn '-' + arg.slice(1)\n\t\t}\n\t\treturn arg\n\t}\n}\n\nexport class InvalidInputError extends Error {}\n"],"names":["OptionMode","Input"],"mappings":";;;;AASO,MAAM,YAAY;AAAA,EACxB,YAAoB,YAAgC,SAAmB;AAAnD,SAAA,aAAA;AAAgC,SAAA,UAAA;AAAA,EAAoB;AAAA,EAExE,MAAoD,MAA+C;AAClG,WAAO,KAAK,QAAQ,CAAA,QAAO;AAC1B,YAAM,YAAY,IAAI,WAAW,GAAG,IAAI,IAAI,QAAQ,GAAG,IAAI;AAC3D,aAAO,cAAc,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,MAAM,GAAG,SAAS,GAAG,IAAI,MAAM,YAAY,CAAC,CAAC;AAAA,IACrF,CAAC;AACD,QAAI,UAAmB,CAAA;AACvB,QAAI,iBAA4B,CAAA;AAChC,UAAM,cAAwB,CAAA;AAE9B,QAAI,IAAI;AACR,QAAI,iBAAiB;AACrB,UAAM,cAAc,KAAK,WAAW,KAAK,WAAW,SAAS,CAAC,GAAG,WAC9D,KAAK,WAAW,KAAK,WAAW,SAAS,CAAC,IAC1C;AACH,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B,YAAY,OAAO,IAAI,cAAc;AAAA,MAClE,OAAO;AACN,gBAAQ,OAAO,IAAI,IAAI;AAAA,MACxB;AAAA,IACD;AAEA,WAAO,EAAE,OAAO,IAAIC,MAAAA,MAAkB,gBAAwB,OAAe,GAAG,YAAA;AAAA,EACjF;AAAA,EAEQ,cAAc,KAA6C;AAClE,QAAI,QAAQ,QAAW;AACtB,aAAO;AAAA,IACR;AACA,QAAI,IAAI,WAAW,GAAG,GAAG;AACxB,aAAO;AAAA,IACR;AACA,QAAI,IAAI,WAAW,KAAK,GAAG;AAC1B,aAAO,MAAM,IAAI,MAAM,CAAC;AAAA,IACzB;AACA,WAAO;AAAA,EACR;AACD;AAEO,MAAM,0BAA0B,MAAM;AAAC;;;"}
@@ -6,9 +6,13 @@ class InputParser {
6
6
  this.options = options;
7
7
  }
8
8
  parse(args) {
9
- args = args.reduce((acc, arg) => [...acc, ...arg.startsWith("-") ? arg.split("=", 2) : [arg]], []);
9
+ args = args.flatMap((arg) => {
10
+ const separator = arg.startsWith("-") ? arg.indexOf("=") : -1;
11
+ return separator === -1 ? [arg] : [arg.slice(0, separator), arg.slice(separator + 1)];
12
+ });
10
13
  let options = {};
11
14
  let argumentValues = {};
15
+ const diagnostics = [];
12
16
  let i = 0;
13
17
  let argumentNumber = 0;
14
18
  const variadicArg = this._arguments[this._arguments.length - 1]?.variadic ? this._arguments[this._arguments.length - 1] : void 0;
@@ -57,7 +61,7 @@ class InputParser {
57
61
  }
58
62
  if (option) {
59
63
  if (option.deprecated) {
60
- console.warn(`Option ${option.name} is deprecated.`);
64
+ diagnostics.push(`Option --${option.name} is deprecated.`);
61
65
  }
62
66
  if (option.mode === OptionMode.VALUE_NONE) {
63
67
  options[option.name] = true;
@@ -93,7 +97,7 @@ class InputParser {
93
97
  options[option.name] = void 0;
94
98
  }
95
99
  }
96
- return new Input(argumentValues, options);
100
+ return { input: new Input(argumentValues, options), diagnostics };
97
101
  }
98
102
  tryParseValue(arg) {
99
103
  if (arg === void 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"InputParser.js","sources":["../../../../../packages/cli-common/src/application/InputParser.ts"],"sourcesContent":["import { Argument } from './Argument.js'\nimport { Option, OptionMode } from './Option.js'\nimport { Arguments, Input, Options } from './Input.js'\n\nexport class InputParser {\n\tconstructor(private _arguments: Argument[], private options: Option[]) {}\n\n\tparse<Args extends Arguments, Opts extends Options>(args: string[]): Input<Args, Opts> {\n\t\targs = args.reduce<string[]>((acc, arg) => [...acc, ...(arg.startsWith('-') ? arg.split('=', 2) : [arg])], [])\n\t\tlet options: Options = {}\n\t\tlet argumentValues: Arguments = {}\n\n\t\tlet i = 0\n\t\tlet argumentNumber = 0\n\t\tconst variadicArg = this._arguments[this._arguments.length - 1]?.variadic\n\t\t\t? this._arguments[this._arguments.length - 1]\n\t\t\t: undefined\n\t\tfor (; i < args.length; i++) {\n\t\t\tconst value = this.tryParseValue(args[i])\n\t\t\tif (value === undefined) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tconst argument = this._arguments[argumentNumber] || variadicArg\n\t\t\tif (!argument) {\n\t\t\t\tthrow new InvalidInputError(`Unresolved argument for value \"${value}\"`)\n\t\t\t}\n\t\t\tif (argument.validator && !argument.validator(value)) {\n\t\t\t\tthrow new InvalidInputError(`Invalid value \"${value}\" for argument ${argument.name}`)\n\t\t\t}\n\t\t\tif (argument.variadic) {\n\t\t\t\targumentValues[argument.name] = argumentValues[argument.name] || []\n\t\t\t\t;(argumentValues[argument.name] as Array<string>).push(value)\n\t\t\t} else {\n\t\t\t\targumentValues[argument.name] = value\n\t\t\t}\n\t\t\targumentNumber++\n\t\t}\n\t\tfor (; argumentNumber < this._arguments.length; argumentNumber++) {\n\t\t\tif (!this._arguments[argumentNumber].optional) {\n\t\t\t\tthrow new InvalidInputError(`Argument ${this._arguments[argumentNumber].name} is required`)\n\t\t\t} else {\n\t\t\t\targumentValues[this._arguments[argumentNumber].name] = undefined\n\t\t\t}\n\t\t}\n\n\t\tfor (; i < args.length; i++) {\n\t\t\tlet option: Option | undefined\n\t\t\tif (args[i].startsWith('--')) {\n\t\t\t\toption = this.options.find(it => it.name === args[i].slice(2))\n\t\t\t\tif (!option) {\n\t\t\t\t\tthrow new InvalidInputError(`Undefined option ${args[i]}`)\n\t\t\t\t}\n\t\t\t} else if (args[i].startsWith('-')) {\n\t\t\t\toption = this.options.find(it => it.shortcut === args[i].slice(1))\n\t\t\t\tif (!option) {\n\t\t\t\t\tthrow new InvalidInputError(`Undefined option ${args[i]}`)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!option) {\n\t\t\t\tthrow new InvalidInputError(`Unexpected value \"${args[i]}\"`)\n\t\t\t}\n\t\t\tif (option) {\n\t\t\t\tif (option.deprecated) {\n\t\t\t\t\tconsole.warn(`Option ${option.name} is deprecated.`)\n\t\t\t\t}\n\t\t\t\tif (option.mode === OptionMode.VALUE_NONE) {\n\t\t\t\t\toptions[option.name] = true\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst value = this.tryParseValue(args[i + 1])\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\ti++\n\t\t\t\t}\n\t\t\t\tif (option.mode === OptionMode.VALUE_ARRAY) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tthrow new InvalidInputError(`Undefined value for option --${option.name}`)\n\t\t\t\t\t}\n\t\t\t\t\toptions[option.name] = options[option.name] || []\n\t\t\t\t\t;(options[option.name] as Array<string>).push(value)\n\t\t\t\t} else if (option.mode === OptionMode.VALUE_REQUIRED) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tthrow new InvalidInputError(`Undefined value for option --${option.name}`)\n\t\t\t\t\t}\n\t\t\t\t\toptions[option.name] = value\n\t\t\t\t} else if (option.mode === OptionMode.VALUE_OPTIONAL) {\n\t\t\t\t\toptions[option.name] = value === undefined ? true : value\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (let option of this.options) {\n\t\t\tif (options[option.name] !== undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (option.required) {\n\t\t\t\tthrow new InvalidInputError(`Option --${option.name} is required`)\n\t\t\t} else {\n\t\t\t\toptions[option.name] = undefined\n\t\t\t}\n\t\t}\n\n\t\treturn new Input<Args, Opts>(argumentValues as Args, options as Opts)\n\t}\n\n\tprivate tryParseValue(arg: string | undefined): string | undefined {\n\t\tif (arg === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (arg.startsWith('-')) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (arg.startsWith('\\\\-')) {\n\t\t\treturn '-' + arg.slice(1)\n\t\t}\n\t\treturn arg\n\t}\n}\n\nexport class InvalidInputError extends Error {}\n"],"names":[],"mappings":";;AAIO,MAAM,YAAY;AAAA,EACxB,YAAoB,YAAgC,SAAmB;AAAnD,SAAA,aAAA;AAAgC,SAAA,UAAA;AAAA,EAAoB;AAAA,EAExE,MAAoD,MAAmC;AACtF,WAAO,KAAK,OAAiB,CAAC,KAAK,QAAQ,CAAC,GAAG,KAAK,GAAI,IAAI,WAAW,GAAG,IAAI,IAAI,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAE,GAAG,EAAE;AAC7G,QAAI,UAAmB,CAAA;AACvB,QAAI,iBAA4B,CAAA;AAEhC,QAAI,IAAI;AACR,QAAI,iBAAiB;AACrB,UAAM,cAAc,KAAK,WAAW,KAAK,WAAW,SAAS,CAAC,GAAG,WAC9D,KAAK,WAAW,KAAK,WAAW,SAAS,CAAC,IAC1C;AACH,WAAO,IAAI,KAAK,QAAQ,KAAK;AAC5B,YAAM,QAAQ,KAAK,cAAc,KAAK,CAAC,CAAC;AACxC,UAAI,UAAU,QAAW;AACxB;AAAA,MACD;AACA,YAAM,WAAW,KAAK,WAAW,cAAc,KAAK;AACpD,UAAI,CAAC,UAAU;AACd,cAAM,IAAI,kBAAkB,kCAAkC,KAAK,GAAG;AAAA,MACvE;AACA,UAAI,SAAS,aAAa,CAAC,SAAS,UAAU,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G;AAC1B,aAAO,MAAM,IAAI,MAAM,CAAC;AAAA,IACzB;AACA,WAAO;AAAA,EACR;AACD;AAEO,MAAM,0BAA0B,MAAM;AAAC;"}
1
+ {"version":3,"file":"InputParser.js","sources":["../../../../../packages/cli-common/src/application/InputParser.ts"],"sourcesContent":["import { Argument } from './Argument.js'\nimport { Option, OptionMode } from './Option.js'\nimport { Arguments, Input, Options } from './Input.js'\n\nexport interface InputParserResult<Args extends Arguments, Opts extends Options> {\n\treadonly input: Input<Args, Opts>\n\treadonly diagnostics: readonly string[]\n}\n\nexport class InputParser {\n\tconstructor(private _arguments: Argument[], private options: Option[]) {}\n\n\tparse<Args extends Arguments, Opts extends Options>(args: string[]): InputParserResult<Args, Opts> {\n\t\targs = args.flatMap(arg => {\n\t\t\tconst separator = arg.startsWith('-') ? arg.indexOf('=') : -1\n\t\t\treturn separator === -1 ? [arg] : [arg.slice(0, separator), arg.slice(separator + 1)]\n\t\t})\n\t\tlet options: Options = {}\n\t\tlet argumentValues: Arguments = {}\n\t\tconst diagnostics: string[] = []\n\n\t\tlet i = 0\n\t\tlet argumentNumber = 0\n\t\tconst variadicArg = this._arguments[this._arguments.length - 1]?.variadic\n\t\t\t? this._arguments[this._arguments.length - 1]\n\t\t\t: undefined\n\t\tfor (; i < args.length; i++) {\n\t\t\tconst value = this.tryParseValue(args[i])\n\t\t\tif (value === undefined) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tconst argument = this._arguments[argumentNumber] || variadicArg\n\t\t\tif (!argument) {\n\t\t\t\tthrow new InvalidInputError(`Unresolved argument for value \"${value}\"`)\n\t\t\t}\n\t\t\tif (argument.validator && !argument.validator(value)) {\n\t\t\t\tthrow new InvalidInputError(`Invalid value \"${value}\" for argument ${argument.name}`)\n\t\t\t}\n\t\t\tif (argument.variadic) {\n\t\t\t\targumentValues[argument.name] = argumentValues[argument.name] || []\n\t\t\t\t;(argumentValues[argument.name] as Array<string>).push(value)\n\t\t\t} else {\n\t\t\t\targumentValues[argument.name] = value\n\t\t\t}\n\t\t\targumentNumber++\n\t\t}\n\t\tfor (; argumentNumber < this._arguments.length; argumentNumber++) {\n\t\t\tif (!this._arguments[argumentNumber].optional) {\n\t\t\t\tthrow new InvalidInputError(`Argument ${this._arguments[argumentNumber].name} is required`)\n\t\t\t} else {\n\t\t\t\targumentValues[this._arguments[argumentNumber].name] = undefined\n\t\t\t}\n\t\t}\n\n\t\tfor (; i < args.length; i++) {\n\t\t\tlet option: Option | undefined\n\t\t\tif (args[i].startsWith('--')) {\n\t\t\t\toption = this.options.find(it => it.name === args[i].slice(2))\n\t\t\t\tif (!option) {\n\t\t\t\t\tthrow new InvalidInputError(`Undefined option ${args[i]}`)\n\t\t\t\t}\n\t\t\t} else if (args[i].startsWith('-')) {\n\t\t\t\toption = this.options.find(it => it.shortcut === args[i].slice(1))\n\t\t\t\tif (!option) {\n\t\t\t\t\tthrow new InvalidInputError(`Undefined option ${args[i]}`)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!option) {\n\t\t\t\tthrow new InvalidInputError(`Unexpected value \"${args[i]}\"`)\n\t\t\t}\n\t\t\tif (option) {\n\t\t\t\tif (option.deprecated) {\n\t\t\t\t\tdiagnostics.push(`Option --${option.name} is deprecated.`)\n\t\t\t\t}\n\t\t\t\tif (option.mode === OptionMode.VALUE_NONE) {\n\t\t\t\t\toptions[option.name] = true\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst value = this.tryParseValue(args[i + 1])\n\t\t\t\tif (value !== undefined) {\n\t\t\t\t\ti++\n\t\t\t\t}\n\t\t\t\tif (option.mode === OptionMode.VALUE_ARRAY) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tthrow new InvalidInputError(`Undefined value for option --${option.name}`)\n\t\t\t\t\t}\n\t\t\t\t\toptions[option.name] = options[option.name] || []\n\t\t\t\t\t;(options[option.name] as Array<string>).push(value)\n\t\t\t\t} else if (option.mode === OptionMode.VALUE_REQUIRED) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tthrow new InvalidInputError(`Undefined value for option --${option.name}`)\n\t\t\t\t\t}\n\t\t\t\t\toptions[option.name] = value\n\t\t\t\t} else if (option.mode === OptionMode.VALUE_OPTIONAL) {\n\t\t\t\t\toptions[option.name] = value === undefined ? true : value\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (let option of this.options) {\n\t\t\tif (options[option.name] !== undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (option.required) {\n\t\t\t\tthrow new InvalidInputError(`Option --${option.name} is required`)\n\t\t\t} else {\n\t\t\t\toptions[option.name] = undefined\n\t\t\t}\n\t\t}\n\n\t\treturn { input: new Input<Args, Opts>(argumentValues as Args, options as Opts), diagnostics }\n\t}\n\n\tprivate tryParseValue(arg: string | undefined): string | undefined {\n\t\tif (arg === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (arg.startsWith('-')) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (arg.startsWith('\\\\-')) {\n\t\t\treturn '-' + arg.slice(1)\n\t\t}\n\t\treturn arg\n\t}\n}\n\nexport class InvalidInputError extends Error {}\n"],"names":[],"mappings":";;AASO,MAAM,YAAY;AAAA,EACxB,YAAoB,YAAgC,SAAmB;AAAnD,SAAA,aAAA;AAAgC,SAAA,UAAA;AAAA,EAAoB;AAAA,EAExE,MAAoD,MAA+C;AAClG,WAAO,KAAK,QAAQ,CAAA,QAAO;AAC1B,YAAM,YAAY,IAAI,WAAW,GAAG,IAAI,IAAI,QAAQ,GAAG,IAAI;AAC3D,aAAO,cAAc,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,MAAM,GAAG,SAAS,GAAG,IAAI,MAAM,YAAY,CAAC,CAAC;AAAA,IACrF,CAAC;AACD,QAAI,UAAmB,CAAA;AACvB,QAAI,iBAA4B,CAAA;AAChC,UAAM,cAAwB,CAAA;AAE9B,QAAI,IAAI;AACR,QAAI,iBAAiB;AACrB,UAAM,cAAc,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AAW;AACvC;AAAA,MACD;AACA,UAAI,OAAO,UAAU;AACpB,cAAM,IAAI,kBAAkB,YAAY,OAAO,IAAI,cAAc;AAAA,MAClE,OAAO;AACN,gBAAQ,OAAO,IAAI,IAAI;AAAA,MACxB;AAAA,IACD;AAEA,WAAO,EAAE,OAAO,IAAI,MAAkB,gBAAwB,OAAe,GAAG,YAAA;AAAA,EACjF;AAAA,EAEQ,cAAc,KAA6C;AAClE,QAAI,QAAQ,QAAW;AACtB,aAAO;AAAA,IACR;AACA,QAAI,IAAI,WAAW,GAAG,GAAG;AACxB,aAAO;AAAA,IACR;AACA,QAAI,IAAI,WAAW,KAAK,GAAG;AAC1B,aAAO,MAAM,IAAI,MAAM,CAAC;AAAA,IACzB;AACA,WAAO;AAAA,EACR;AACD;AAEO,MAAM,0BAA0B,MAAM;AAAC;"}
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const mergeOptions = (options, extra) => {
4
+ const result = [...options];
5
+ for (const option of extra) {
6
+ const shadowed = result.some((it) => it.name === option.name || option.shortcut !== void 0 && it.shortcut === option.shortcut);
7
+ if (!shadowed) {
8
+ result.push(option);
9
+ }
10
+ }
11
+ return result;
12
+ };
3
13
  var OptionMode = /* @__PURE__ */ ((OptionMode2) => {
4
14
  OptionMode2["VALUE_NONE"] = "value_none";
5
15
  OptionMode2["VALUE_OPTIONAL"] = "value_optional";
@@ -46,4 +56,5 @@ class OptionConfiguration {
46
56
  }
47
57
  exports.OptionConfiguration = OptionConfiguration;
48
58
  exports.OptionMode = OptionMode;
59
+ exports.mergeOptions = mergeOptions;
49
60
  //# sourceMappingURL=Option.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Option.cjs","sources":["../../../../../packages/cli-common/src/application/Option.ts"],"sourcesContent":["export type Option = {\n\tname: string\n\tdescription?: string\n\tshortcut?: string\n\trequired: boolean\n\tdeprecated: boolean\n\tmode: OptionMode\n}\n\nexport enum OptionMode {\n\tVALUE_NONE = 'value_none',\n\tVALUE_OPTIONAL = 'value_optional',\n\tVALUE_REQUIRED = 'value_required',\n\tVALUE_ARRAY = 'value_array',\n}\n\nexport class OptionConfiguration {\n\tconstructor(private readonly option: Option) {}\n\n\tpublic shortcut(shortcut: string) {\n\t\tthis.option.shortcut = shortcut\n\t\treturn this\n\t}\n\n\tpublic description(description: string) {\n\t\tthis.option.description = description\n\t\treturn this\n\t}\n\n\tpublic required(required: boolean = true) {\n\t\tthis.option.required = required\n\t\treturn this\n\t}\n\n\tpublic valueRequired() {\n\t\tthis.option.mode = OptionMode.VALUE_REQUIRED\n\t\treturn this\n\t}\n\n\tpublic valueNone() {\n\t\tthis.option.mode = OptionMode.VALUE_NONE\n\t\treturn this\n\t}\n\n\tpublic valueOptional() {\n\t\tthis.option.mode = OptionMode.VALUE_OPTIONAL\n\t\treturn this\n\t}\n\n\tpublic valueArray() {\n\t\tthis.option.mode = OptionMode.VALUE_ARRAY\n\t\treturn this\n\t}\n\n\tpublic deprecated() {\n\t\tthis.option.deprecated = true\n\t\treturn this\n\t}\n}\n"],"names":["OptionMode"],"mappings":";;AASO,IAAK,+BAAAA,gBAAL;AACNA,cAAA,YAAA,IAAa;AACbA,cAAA,gBAAA,IAAiB;AACjBA,cAAA,gBAAA,IAAiB;AACjBA,cAAA,aAAA,IAAc;AAJH,SAAAA;AAAA,GAAA,cAAA,CAAA,CAAA;AAOL,MAAM,oBAAoB;AAAA,EAChC,YAA6B,QAAgB;AAAhB,SAAA,SAAA;AAAA,EAAiB;AAAA,EAEvC,SAAS,UAAkB;AACjC,SAAK,OAAO,WAAW;AACvB,WAAO;AAAA,EACR;AAAA,EAEO,YAAY,aAAqB;AACvC,SAAK,OAAO,cAAc;AAC1B,WAAO;AAAA,EACR;AAAA,EAEO,SAAS,WAAoB,MAAM;AACzC,SAAK,OAAO,WAAW;AACvB,WAAO;AAAA,EACR;AAAA,EAEO,gBAAgB;AACtB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,YAAY;AAClB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,gBAAgB;AACtB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,aAAa;AACnB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,aAAa;AACnB,SAAK,OAAO,aAAa;AACzB,WAAO;AAAA,EACR;AACD;;;"}
1
+ {"version":3,"file":"Option.cjs","sources":["../../../../../packages/cli-common/src/application/Option.ts"],"sourcesContent":["export type Option = {\n\tname: string\n\tdescription?: string\n\tshortcut?: string\n\trequired: boolean\n\tdeprecated: boolean\n\tmode: OptionMode\n}\n\n/** Combines option sets while omitting duplicate definitions. */\nexport const mergeOptions = (options: readonly Option[], extra: readonly Option[]): Option[] => {\n\tconst result = [...options]\n\tfor (const option of extra) {\n\t\tconst shadowed = result.some(it => it.name === option.name || (option.shortcut !== undefined && it.shortcut === option.shortcut))\n\t\tif (!shadowed) {\n\t\t\tresult.push(option)\n\t\t}\n\t}\n\treturn result\n}\n\nexport enum OptionMode {\n\tVALUE_NONE = 'value_none',\n\tVALUE_OPTIONAL = 'value_optional',\n\tVALUE_REQUIRED = 'value_required',\n\tVALUE_ARRAY = 'value_array',\n}\n\nexport class OptionConfiguration {\n\tconstructor(private readonly option: Option) {}\n\n\tpublic shortcut(shortcut: string) {\n\t\tthis.option.shortcut = shortcut\n\t\treturn this\n\t}\n\n\tpublic description(description: string) {\n\t\tthis.option.description = description\n\t\treturn this\n\t}\n\n\tpublic required(required: boolean = true) {\n\t\tthis.option.required = required\n\t\treturn this\n\t}\n\n\tpublic valueRequired() {\n\t\tthis.option.mode = OptionMode.VALUE_REQUIRED\n\t\treturn this\n\t}\n\n\tpublic valueNone() {\n\t\tthis.option.mode = OptionMode.VALUE_NONE\n\t\treturn this\n\t}\n\n\tpublic valueOptional() {\n\t\tthis.option.mode = OptionMode.VALUE_OPTIONAL\n\t\treturn this\n\t}\n\n\tpublic valueArray() {\n\t\tthis.option.mode = OptionMode.VALUE_ARRAY\n\t\treturn this\n\t}\n\n\tpublic deprecated() {\n\t\tthis.option.deprecated = true\n\t\treturn this\n\t}\n}\n"],"names":["OptionMode"],"mappings":";;AAUO,MAAM,eAAe,CAAC,SAA4B,UAAuC;AAC/F,QAAM,SAAS,CAAC,GAAG,OAAO;AAC1B,aAAW,UAAU,OAAO;AAC3B,UAAM,WAAW,OAAO,KAAK,CAAA,OAAM,GAAG,SAAS,OAAO,QAAS,OAAO,aAAa,UAAa,GAAG,aAAa,OAAO,QAAS;AAChI,QAAI,CAAC,UAAU;AACd,aAAO,KAAK,MAAM;AAAA,IACnB;AAAA,EACD;AACA,SAAO;AACR;AAEO,IAAK,+BAAAA,gBAAL;AACNA,cAAA,YAAA,IAAa;AACbA,cAAA,gBAAA,IAAiB;AACjBA,cAAA,gBAAA,IAAiB;AACjBA,cAAA,aAAA,IAAc;AAJH,SAAAA;AAAA,GAAA,cAAA,CAAA,CAAA;AAOL,MAAM,oBAAoB;AAAA,EAChC,YAA6B,QAAgB;AAAhB,SAAA,SAAA;AAAA,EAAiB;AAAA,EAEvC,SAAS,UAAkB;AACjC,SAAK,OAAO,WAAW;AACvB,WAAO;AAAA,EACR;AAAA,EAEO,YAAY,aAAqB;AACvC,SAAK,OAAO,cAAc;AAC1B,WAAO;AAAA,EACR;AAAA,EAEO,SAAS,WAAoB,MAAM;AACzC,SAAK,OAAO,WAAW;AACvB,WAAO;AAAA,EACR;AAAA,EAEO,gBAAgB;AACtB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,YAAY;AAClB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,gBAAgB;AACtB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,aAAa;AACnB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,aAAa;AACnB,SAAK,OAAO,aAAa;AACzB,WAAO;AAAA,EACR;AACD;;;;"}
@@ -1,3 +1,13 @@
1
+ const mergeOptions = (options, extra) => {
2
+ const result = [...options];
3
+ for (const option of extra) {
4
+ const shadowed = result.some((it) => it.name === option.name || option.shortcut !== void 0 && it.shortcut === option.shortcut);
5
+ if (!shadowed) {
6
+ result.push(option);
7
+ }
8
+ }
9
+ return result;
10
+ };
1
11
  var OptionMode = /* @__PURE__ */ ((OptionMode2) => {
2
12
  OptionMode2["VALUE_NONE"] = "value_none";
3
13
  OptionMode2["VALUE_OPTIONAL"] = "value_optional";
@@ -44,6 +54,7 @@ class OptionConfiguration {
44
54
  }
45
55
  export {
46
56
  OptionConfiguration,
47
- OptionMode
57
+ OptionMode,
58
+ mergeOptions
48
59
  };
49
60
  //# sourceMappingURL=Option.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Option.js","sources":["../../../../../packages/cli-common/src/application/Option.ts"],"sourcesContent":["export type Option = {\n\tname: string\n\tdescription?: string\n\tshortcut?: string\n\trequired: boolean\n\tdeprecated: boolean\n\tmode: OptionMode\n}\n\nexport enum OptionMode {\n\tVALUE_NONE = 'value_none',\n\tVALUE_OPTIONAL = 'value_optional',\n\tVALUE_REQUIRED = 'value_required',\n\tVALUE_ARRAY = 'value_array',\n}\n\nexport class OptionConfiguration {\n\tconstructor(private readonly option: Option) {}\n\n\tpublic shortcut(shortcut: string) {\n\t\tthis.option.shortcut = shortcut\n\t\treturn this\n\t}\n\n\tpublic description(description: string) {\n\t\tthis.option.description = description\n\t\treturn this\n\t}\n\n\tpublic required(required: boolean = true) {\n\t\tthis.option.required = required\n\t\treturn this\n\t}\n\n\tpublic valueRequired() {\n\t\tthis.option.mode = OptionMode.VALUE_REQUIRED\n\t\treturn this\n\t}\n\n\tpublic valueNone() {\n\t\tthis.option.mode = OptionMode.VALUE_NONE\n\t\treturn this\n\t}\n\n\tpublic valueOptional() {\n\t\tthis.option.mode = OptionMode.VALUE_OPTIONAL\n\t\treturn this\n\t}\n\n\tpublic valueArray() {\n\t\tthis.option.mode = OptionMode.VALUE_ARRAY\n\t\treturn this\n\t}\n\n\tpublic deprecated() {\n\t\tthis.option.deprecated = true\n\t\treturn this\n\t}\n}\n"],"names":["OptionMode"],"mappings":"AASO,IAAK,+BAAAA,gBAAL;AACNA,cAAA,YAAA,IAAa;AACbA,cAAA,gBAAA,IAAiB;AACjBA,cAAA,gBAAA,IAAiB;AACjBA,cAAA,aAAA,IAAc;AAJH,SAAAA;AAAA,GAAA,cAAA,CAAA,CAAA;AAOL,MAAM,oBAAoB;AAAA,EAChC,YAA6B,QAAgB;AAAhB,SAAA,SAAA;AAAA,EAAiB;AAAA,EAEvC,SAAS,UAAkB;AACjC,SAAK,OAAO,WAAW;AACvB,WAAO;AAAA,EACR;AAAA,EAEO,YAAY,aAAqB;AACvC,SAAK,OAAO,cAAc;AAC1B,WAAO;AAAA,EACR;AAAA,EAEO,SAAS,WAAoB,MAAM;AACzC,SAAK,OAAO,WAAW;AACvB,WAAO;AAAA,EACR;AAAA,EAEO,gBAAgB;AACtB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,YAAY;AAClB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,gBAAgB;AACtB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,aAAa;AACnB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,aAAa;AACnB,SAAK,OAAO,aAAa;AACzB,WAAO;AAAA,EACR;AACD;"}
1
+ {"version":3,"file":"Option.js","sources":["../../../../../packages/cli-common/src/application/Option.ts"],"sourcesContent":["export type Option = {\n\tname: string\n\tdescription?: string\n\tshortcut?: string\n\trequired: boolean\n\tdeprecated: boolean\n\tmode: OptionMode\n}\n\n/** Combines option sets while omitting duplicate definitions. */\nexport const mergeOptions = (options: readonly Option[], extra: readonly Option[]): Option[] => {\n\tconst result = [...options]\n\tfor (const option of extra) {\n\t\tconst shadowed = result.some(it => it.name === option.name || (option.shortcut !== undefined && it.shortcut === option.shortcut))\n\t\tif (!shadowed) {\n\t\t\tresult.push(option)\n\t\t}\n\t}\n\treturn result\n}\n\nexport enum OptionMode {\n\tVALUE_NONE = 'value_none',\n\tVALUE_OPTIONAL = 'value_optional',\n\tVALUE_REQUIRED = 'value_required',\n\tVALUE_ARRAY = 'value_array',\n}\n\nexport class OptionConfiguration {\n\tconstructor(private readonly option: Option) {}\n\n\tpublic shortcut(shortcut: string) {\n\t\tthis.option.shortcut = shortcut\n\t\treturn this\n\t}\n\n\tpublic description(description: string) {\n\t\tthis.option.description = description\n\t\treturn this\n\t}\n\n\tpublic required(required: boolean = true) {\n\t\tthis.option.required = required\n\t\treturn this\n\t}\n\n\tpublic valueRequired() {\n\t\tthis.option.mode = OptionMode.VALUE_REQUIRED\n\t\treturn this\n\t}\n\n\tpublic valueNone() {\n\t\tthis.option.mode = OptionMode.VALUE_NONE\n\t\treturn this\n\t}\n\n\tpublic valueOptional() {\n\t\tthis.option.mode = OptionMode.VALUE_OPTIONAL\n\t\treturn this\n\t}\n\n\tpublic valueArray() {\n\t\tthis.option.mode = OptionMode.VALUE_ARRAY\n\t\treturn this\n\t}\n\n\tpublic deprecated() {\n\t\tthis.option.deprecated = true\n\t\treturn this\n\t}\n}\n"],"names":["OptionMode"],"mappings":"AAUO,MAAM,eAAe,CAAC,SAA4B,UAAuC;AAC/F,QAAM,SAAS,CAAC,GAAG,OAAO;AAC1B,aAAW,UAAU,OAAO;AAC3B,UAAM,WAAW,OAAO,KAAK,CAAA,OAAM,GAAG,SAAS,OAAO,QAAS,OAAO,aAAa,UAAa,GAAG,aAAa,OAAO,QAAS;AAChI,QAAI,CAAC,UAAU;AACd,aAAO,KAAK,MAAM;AAAA,IACnB;AAAA,EACD;AACA,SAAO;AACR;AAEO,IAAK,+BAAAA,gBAAL;AACNA,cAAA,YAAA,IAAa;AACbA,cAAA,gBAAA,IAAiB;AACjBA,cAAA,gBAAA,IAAiB;AACjBA,cAAA,aAAA,IAAc;AAJH,SAAAA;AAAA,GAAA,cAAA,CAAA,CAAA;AAOL,MAAM,oBAAoB;AAAA,EAChC,YAA6B,QAAgB;AAAhB,SAAA,SAAA;AAAA,EAAiB;AAAA,EAEvC,SAAS,UAAkB;AACjC,SAAK,OAAO,WAAW;AACvB,WAAO;AAAA,EACR;AAAA,EAEO,YAAY,aAAqB;AACvC,SAAK,OAAO,cAAc;AAC1B,WAAO;AAAA,EACR;AAAA,EAEO,SAAS,WAAoB,MAAM;AACzC,SAAK,OAAO,WAAW;AACvB,WAAO;AAAA,EACR;AAAA,EAEO,gBAAgB;AACtB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,YAAY;AAClB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,gBAAgB;AACtB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,aAAa;AACnB,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA,EAEO,aAAa;AACnB,SAAK,OAAO,aAAa;AACzB,WAAO;AAAA,EACR;AACD;"}
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const node_readline = require("node:readline");
4
+ const CliError = require("./CliError.cjs");
5
+ const colors = require("./colors.cjs");
6
+ const table = require("./table.cjs");
7
+ var __defProp = Object.defineProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
+ const resolveOutputMode = (globals) => {
11
+ if (globals.json) {
12
+ return "json";
13
+ }
14
+ if (globals.quiet) {
15
+ return "quiet";
16
+ }
17
+ return "human";
18
+ };
19
+ class Output {
20
+ constructor(options = {}) {
21
+ __publicField(this, "currentMode", "human");
22
+ __publicField(this, "progressVisible", false);
23
+ __publicField(this, "stdout");
24
+ __publicField(this, "stderr");
25
+ __publicField(this, "stdinIsTty");
26
+ __publicField(this, "readPromptLine");
27
+ this.stdout = options.stdout ?? createProcessStream(process.stdout);
28
+ this.stderr = options.stderr ?? createProcessStream(process.stderr);
29
+ this.stdinIsTty = options.isStdinTty ?? (() => process.stdin.isTTY === true);
30
+ this.readPromptLine = options.readPromptLine ?? readStdinLine;
31
+ this.stdout.onError?.(handleStreamError);
32
+ this.stderr.onError?.(handleStreamError);
33
+ }
34
+ get mode() {
35
+ return this.currentMode;
36
+ }
37
+ get isJson() {
38
+ return this.currentMode === "json";
39
+ }
40
+ get isQuiet() {
41
+ return this.currentMode === "quiet";
42
+ }
43
+ /** Set by `Application` once the global options are parsed. */
44
+ setMode(mode) {
45
+ this.currentMode = mode;
46
+ }
47
+ applyGlobalOptions(globals) {
48
+ this.setMode(resolveOutputMode(globals));
49
+ colors.setColorsEnabled(globals.color && this.currentMode === "human" && colors.terminalSupportsColor);
50
+ }
51
+ data(value, rendering) {
52
+ const human = typeof rendering === "function" ? rendering : rendering?.human;
53
+ if (this.currentMode === "json") {
54
+ this.writeStdout(JSON.stringify(value ?? null, null, 2));
55
+ return;
56
+ }
57
+ if (this.currentMode === "quiet") {
58
+ const quietValue = typeof rendering === "object" && rendering.quiet ? rendering.quiet(value) : value;
59
+ for (const line of toScalarLines(quietValue)) {
60
+ this.writeStdout(line);
61
+ }
62
+ return;
63
+ }
64
+ this.writeStdout(human ? human(value) : JSON.stringify(value ?? null, null, 2));
65
+ }
66
+ table(columns, rows, quietField) {
67
+ if (this.currentMode === "json") {
68
+ this.writeStdout(JSON.stringify(rows, null, 2));
69
+ return;
70
+ }
71
+ if (this.currentMode === "quiet") {
72
+ const field = quietField ?? columns[0]?.field;
73
+ if (field === void 0) {
74
+ return;
75
+ }
76
+ for (const row of rows) {
77
+ this.writeStdout(formatCell(row[field]));
78
+ }
79
+ return;
80
+ }
81
+ if (rows.length === 0) {
82
+ return;
83
+ }
84
+ const data = rows.map((row) => {
85
+ const cells = {};
86
+ for (const column of columns) {
87
+ cells[column.field] = renderTableCell(column, row);
88
+ }
89
+ return cells;
90
+ });
91
+ this.writeStdout(table.formatTable(columns.map((it) => ({ field: it.field, name: it.name })), data));
92
+ }
93
+ // DIAGNOSTICS → stderr
94
+ info(message) {
95
+ this.writeDiagnostic(message);
96
+ }
97
+ warn(message) {
98
+ this.writeDiagnostic(message, (text) => colors.style("yellow", text));
99
+ }
100
+ error(message) {
101
+ this.writeDiagnostic(message, (text) => colors.style("red", text));
102
+ }
103
+ // PROGRESS → stderr
104
+ progress(message) {
105
+ if (this.currentMode !== "human" || !this.stderr.isTty) {
106
+ return;
107
+ }
108
+ this.clearProgress();
109
+ writeStream(this.stderr, escapeTerminalText(message));
110
+ this.progressVisible = true;
111
+ }
112
+ clearProgress() {
113
+ if (!this.progressVisible) {
114
+ return;
115
+ }
116
+ this.progressVisible = false;
117
+ writeStream(this.stderr, "\r\x1B[K");
118
+ }
119
+ /** False unless both sides of an interactive prompt are TTYs in human mode. */
120
+ canPrompt() {
121
+ return this.currentMode === "human" && this.stdinIsTty() && this.stderr.isTty;
122
+ }
123
+ /** Writes `question` to stderr and reads one answer line. */
124
+ prompt(question) {
125
+ if (!this.canPrompt()) {
126
+ throw new CliError.CliError("TTY not available. Pass --yes to confirm.", { code: "TTY_UNAVAILABLE", exitCode: CliError.ExitCode.InputError });
127
+ }
128
+ this.clearProgress();
129
+ writeStream(this.stderr, question);
130
+ return this.readPromptLine();
131
+ }
132
+ /**
133
+ * Writes a line to stderr regardless of the mode. Reserved for content the user explicitly asked for
134
+ * (help) or must always see (a fatal error) — everything else belongs to the methods above.
135
+ */
136
+ writeStderr(text) {
137
+ this.clearProgress();
138
+ writeStream(this.stderr, text + "\n");
139
+ }
140
+ writeStdout(text) {
141
+ this.clearProgress();
142
+ writeStream(this.stdout, text + "\n");
143
+ }
144
+ writeDiagnostic(message, format = (text) => text) {
145
+ if (this.currentMode !== "human") {
146
+ return;
147
+ }
148
+ this.clearProgress();
149
+ writeStream(this.stderr, format(escapeTerminalText(message)) + "\n");
150
+ }
151
+ }
152
+ const createProcessStream = (stream) => ({
153
+ write: (text) => {
154
+ stream.write(text);
155
+ },
156
+ get isTty() {
157
+ return stream.isTTY === true;
158
+ },
159
+ get columns() {
160
+ return stream.columns;
161
+ },
162
+ onError: (listener) => {
163
+ stream.on("error", (error) => listener(error));
164
+ }
165
+ });
166
+ let stdinReader;
167
+ const readStdinLine = () => {
168
+ stdinReader ?? (stdinReader = new LineReader(process.stdin));
169
+ return stdinReader.read();
170
+ };
171
+ class LineReader {
172
+ constructor(input) {
173
+ this.input = input;
174
+ __publicField(this, "reader");
175
+ __publicField(this, "lines", []);
176
+ __publicField(this, "waiting");
177
+ __publicField(this, "closed", false);
178
+ }
179
+ read() {
180
+ if (this.waiting) {
181
+ throw new Error("LineReader: a read is already pending");
182
+ }
183
+ const line = this.lines.shift();
184
+ if (line !== void 0) {
185
+ return Promise.resolve(line);
186
+ }
187
+ if (this.closed || this.input.readableEnded) {
188
+ this.closed = true;
189
+ return Promise.resolve(void 0);
190
+ }
191
+ return new Promise((resolve) => {
192
+ this.waiting = resolve;
193
+ this.open().resume();
194
+ });
195
+ }
196
+ open() {
197
+ if (this.reader) {
198
+ return this.reader;
199
+ }
200
+ const reader = node_readline.createInterface({ input: this.input, terminal: false });
201
+ reader.on("line", (line) => this.settle(line));
202
+ reader.on("close", () => {
203
+ this.closed = true;
204
+ this.settle(void 0);
205
+ });
206
+ this.reader = reader;
207
+ return reader;
208
+ }
209
+ settle(line) {
210
+ const waiting = this.waiting;
211
+ if (!waiting) {
212
+ if (line !== void 0) {
213
+ this.lines.push(line);
214
+ }
215
+ return;
216
+ }
217
+ this.waiting = void 0;
218
+ if (!this.closed) {
219
+ this.reader?.pause();
220
+ }
221
+ waiting(line);
222
+ }
223
+ }
224
+ const writeStream = (stream, text) => {
225
+ try {
226
+ stream.write(text);
227
+ } catch (error) {
228
+ handleStreamError(error);
229
+ }
230
+ };
231
+ const handleStreamError = (error) => {
232
+ if (typeof error === "object" && error !== null && "code" in error && error.code === "EPIPE") {
233
+ return;
234
+ }
235
+ throw error;
236
+ };
237
+ const escapeTerminalText = (value) => {
238
+ let escaped = "";
239
+ for (const character of value) {
240
+ if (!isTerminalControl(character)) {
241
+ escaped += character;
242
+ }
243
+ }
244
+ return escaped;
245
+ };
246
+ const isTerminalControl = (character) => {
247
+ const codePoint = character.codePointAt(0);
248
+ return codePoint !== void 0 && (codePoint <= 31 || codePoint >= 127 && codePoint <= 159);
249
+ };
250
+ const renderTableCell = (column, row) => column.format ? column.format(row[column.field], row) : formatCell(row[column.field]);
251
+ const formatCell = (value) => {
252
+ if (value === void 0 || value === null) {
253
+ return "";
254
+ }
255
+ if (typeof value === "string") {
256
+ return escapeTerminalText(value);
257
+ }
258
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
259
+ return String(value);
260
+ }
261
+ return JSON.stringify(value) ?? "";
262
+ };
263
+ const toScalarLines = (value) => {
264
+ const values = Array.isArray(value) ? value : [value];
265
+ if (!values.every(isOutputScalar)) {
266
+ throw new TypeError("Quiet output requires a scalar value or an array of scalar values. Pass an explicit quiet projection for structured data.");
267
+ }
268
+ return values.filter((it) => it !== void 0 && it !== null).map(formatCell);
269
+ };
270
+ const isOutputScalar = (value) => value === null || value === void 0 || ["string", "number", "boolean", "bigint"].includes(typeof value);
271
+ exports.LineReader = LineReader;
272
+ exports.Output = Output;
273
+ exports.escapeTerminalText = escapeTerminalText;
274
+ exports.resolveOutputMode = resolveOutputMode;
275
+ //# sourceMappingURL=Output.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Output.cjs","sources":["../../../../../packages/cli-common/src/application/Output.ts"],"sourcesContent":["import { createInterface, type Interface } from 'node:readline'\nimport type { Readable } from 'node:stream'\nimport { CliError, ExitCode } from './CliError.js'\nimport { setColorsEnabled, style, terminalSupportsColor } from './colors.js'\nimport type { GlobalOptionValues } from './GlobalOptions.js'\nimport { formatTable } from './table.js'\n\nexport type OutputMode = 'human' | 'json' | 'quiet'\n\nexport interface OutputStream {\n\twrite(text: string): void\n\treadonly isTty: boolean\n\treadonly columns?: number\n\tonError?(listener: (error: unknown) => void): void\n}\n\n/** Reads one line of the user's answer, or `undefined` when the input is closed. */\nexport type PromptLineReader = () => Promise<string | undefined>\n\nexport interface OutputOptions {\n\tstdout?: OutputStream\n\tstderr?: OutputStream\n\tisStdinTty?: () => boolean\n\treadPromptLine?: PromptLineReader\n}\n\nexport type OutputScalar = string | number | boolean | bigint | null | undefined\n\nexport interface OutputDataOptions<T> {\n\thuman?: (value: T) => string\n\tquiet?: (value: T) => OutputScalar | readonly OutputScalar[]\n}\n\n/**\n * Per field column specs, so that each `format` sees the exact type of its own field. Indexed by the\n * field name only to let {@link Output.table} render a cell without widening the union.\n */\nexport type OutputTableColumns<T> = {\n\t[K in keyof T & string]: {\n\t\tfield: K\n\t\tname: string\n\t\t/** Human mode only — `--json` still emits the raw row and `--quiet` the raw value. */\n\t\tformat?: (value: T[K], row: T) => string\n\t}\n}\n\nexport type OutputTableColumn<T> = OutputTableColumns<T>[keyof T & string]\n\nexport const resolveOutputMode = (globals: GlobalOptionValues): OutputMode => {\n\tif (globals.json) {\n\t\treturn 'json'\n\t}\n\tif (globals.quiet) {\n\t\treturn 'quiet'\n\t}\n\treturn 'human'\n}\n\n/**\n * The single output channel of the CLI: stdout carries data, stderr carries everything a human reads.\n *\n * The instance is created before argv is parsed, so the mode is mutable and set by `Application` once\n * the global options are known. Every consumer holds the same instance.\n */\nexport class Output {\n\tprivate currentMode: OutputMode = 'human'\n\tprivate progressVisible = false\n\tprivate readonly stdout: OutputStream\n\tprivate readonly stderr: OutputStream\n\tprivate readonly stdinIsTty: () => boolean\n\tprivate readonly readPromptLine: PromptLineReader\n\n\tconstructor(options: OutputOptions = {}) {\n\t\tthis.stdout = options.stdout ?? createProcessStream(process.stdout)\n\t\tthis.stderr = options.stderr ?? createProcessStream(process.stderr)\n\t\tthis.stdinIsTty = options.isStdinTty ?? (() => process.stdin.isTTY === true)\n\t\tthis.readPromptLine = options.readPromptLine ?? readStdinLine\n\t\tthis.stdout.onError?.(handleStreamError)\n\t\tthis.stderr.onError?.(handleStreamError)\n\t}\n\n\tpublic get mode(): OutputMode {\n\t\treturn this.currentMode\n\t}\n\n\tpublic get isJson(): boolean {\n\t\treturn this.currentMode === 'json'\n\t}\n\n\tpublic get isQuiet(): boolean {\n\t\treturn this.currentMode === 'quiet'\n\t}\n\n\t/** Set by `Application` once the global options are parsed. */\n\tpublic setMode(mode: OutputMode): void {\n\t\tthis.currentMode = mode\n\t}\n\n\tpublic applyGlobalOptions(globals: GlobalOptionValues): void {\n\t\tthis.setMode(resolveOutputMode(globals))\n\t\tsetColorsEnabled(globals.color && this.currentMode === 'human' && terminalSupportsColor)\n\t}\n\n\t// DATA → stdout\n\n\t/** Prints command data with optional mode-specific projections. JSON always receives the raw value. */\n\tpublic data<T>(value: T, human?: (value: T) => string): void\n\tpublic data<T>(value: T, options?: OutputDataOptions<T>): void\n\tpublic data<T>(value: T, rendering?: ((value: T) => string) | OutputDataOptions<T>): void {\n\t\tconst human = typeof rendering === 'function' ? rendering : rendering?.human\n\t\tif (this.currentMode === 'json') {\n\t\t\tthis.writeStdout(JSON.stringify(value ?? null, null, 2))\n\t\t\treturn\n\t\t}\n\t\tif (this.currentMode === 'quiet') {\n\t\t\tconst quietValue = typeof rendering === 'object' && rendering.quiet ? rendering.quiet(value) : value\n\t\t\tfor (const line of toScalarLines(quietValue)) {\n\t\t\t\tthis.writeStdout(line)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tthis.writeStdout(human ? human(value) : JSON.stringify(value ?? null, null, 2))\n\t}\n\n\tpublic table<T>(columns: OutputTableColumn<T>[], rows: T[], quietField?: keyof T & string): void {\n\t\tif (this.currentMode === 'json') {\n\t\t\tthis.writeStdout(JSON.stringify(rows, null, 2))\n\t\t\treturn\n\t\t}\n\t\tif (this.currentMode === 'quiet') {\n\t\t\tconst field = quietField ?? columns[0]?.field\n\t\t\tif (field === undefined) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tfor (const row of rows) {\n\t\t\t\tthis.writeStdout(formatCell(row[field]))\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (rows.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tconst data = rows.map(row => {\n\t\t\tconst cells: Partial<Record<keyof T & string, string>> = {}\n\t\t\tfor (const column of columns) {\n\t\t\t\tcells[column.field] = renderTableCell(column, row)\n\t\t\t}\n\t\t\treturn cells\n\t\t})\n\t\tthis.writeStdout(formatTable(columns.map(it => ({ field: it.field, name: it.name })), data))\n\t}\n\n\t// DIAGNOSTICS → stderr\n\n\tpublic info(message: string): void {\n\t\tthis.writeDiagnostic(message)\n\t}\n\n\tpublic warn(message: string): void {\n\t\tthis.writeDiagnostic(message, text => style('yellow', text))\n\t}\n\n\tpublic error(message: string): void {\n\t\tthis.writeDiagnostic(message, text => style('red', text))\n\t}\n\n\t// PROGRESS → stderr\n\n\tpublic progress(message: string): void {\n\t\tif (this.currentMode !== 'human' || !this.stderr.isTty) {\n\t\t\treturn\n\t\t}\n\t\tthis.clearProgress()\n\t\twriteStream(this.stderr, escapeTerminalText(message))\n\t\tthis.progressVisible = true\n\t}\n\n\tpublic clearProgress(): void {\n\t\tif (!this.progressVisible) {\n\t\t\treturn\n\t\t}\n\t\tthis.progressVisible = false\n\t\twriteStream(this.stderr, '\\r\\u001b[K')\n\t}\n\n\t/** False unless both sides of an interactive prompt are TTYs in human mode. */\n\tpublic canPrompt(): boolean {\n\t\treturn this.currentMode === 'human' && this.stdinIsTty() && this.stderr.isTty\n\t}\n\n\t/** Writes `question` to stderr and reads one answer line. */\n\tpublic prompt(question: string): Promise<string | undefined> {\n\t\tif (!this.canPrompt()) {\n\t\t\tthrow new CliError('TTY not available. Pass --yes to confirm.', { code: 'TTY_UNAVAILABLE', exitCode: ExitCode.InputError })\n\t\t}\n\t\tthis.clearProgress()\n\t\twriteStream(this.stderr, question)\n\t\treturn this.readPromptLine()\n\t}\n\n\t/**\n\t * Writes a line to stderr regardless of the mode. Reserved for content the user explicitly asked for\n\t * (help) or must always see (a fatal error) — everything else belongs to the methods above.\n\t */\n\tpublic writeStderr(text: string): void {\n\t\tthis.clearProgress()\n\t\twriteStream(this.stderr, text + '\\n')\n\t}\n\n\tprivate writeStdout(text: string): void {\n\t\tthis.clearProgress()\n\t\twriteStream(this.stdout, text + '\\n')\n\t}\n\n\tprivate writeDiagnostic(message: string, format: (text: string) => string = text => text): void {\n\t\tif (this.currentMode !== 'human') {\n\t\t\treturn\n\t\t}\n\t\tthis.clearProgress()\n\t\twriteStream(this.stderr, format(escapeTerminalText(message)) + '\\n')\n\t}\n}\n\nconst createProcessStream = (stream: NodeJS.WriteStream): OutputStream => ({\n\twrite: text => {\n\t\tstream.write(text)\n\t},\n\tget isTty() {\n\t\treturn stream.isTTY === true\n\t},\n\tget columns() {\n\t\treturn stream.columns\n\t},\n\tonError: listener => {\n\t\tstream.on('error', error => listener(error))\n\t},\n})\n\nlet stdinReader: LineReader | undefined\nconst readStdinLine: PromptLineReader = () => {\n\tstdinReader ??= new LineReader(process.stdin)\n\treturn stdinReader.read()\n}\n\n/**\n * Reads answer lines from one input for all prompts, so that a line typed or pasted ahead of the next prompt is kept\n * and an input that already ended reads as closed. Not in readline's terminal mode: the TTY handles line editing and\n * echo, and Ctrl+C stays a plain SIGINT.\n */\nexport class LineReader {\n\tprivate reader: Interface | undefined\n\tprivate readonly lines: string[] = []\n\tprivate waiting: ((line: string | undefined) => void) | undefined\n\tprivate closed = false\n\n\tconstructor(private readonly input: Readable) {}\n\n\tpublic read(): Promise<string | undefined> {\n\t\tif (this.waiting) {\n\t\t\tthrow new Error('LineReader: a read is already pending')\n\t\t}\n\t\tconst line = this.lines.shift()\n\t\tif (line !== undefined) {\n\t\t\treturn Promise.resolve(line)\n\t\t}\n\t\t// readline never reports `close` for an input that ended before it was attached (Bun does not set readableEnded)\n\t\tif (this.closed || this.input.readableEnded) {\n\t\t\tthis.closed = true\n\t\t\treturn Promise.resolve(undefined)\n\t\t}\n\t\treturn new Promise(resolve => {\n\t\t\tthis.waiting = resolve\n\t\t\tthis.open().resume()\n\t\t})\n\t}\n\n\tprivate open(): Interface {\n\t\tif (this.reader) {\n\t\t\treturn this.reader\n\t\t}\n\t\tconst reader = createInterface({ input: this.input, terminal: false })\n\t\treader.on('line', line => this.settle(line))\n\t\treader.on('close', () => {\n\t\t\tthis.closed = true\n\t\t\tthis.settle(undefined)\n\t\t})\n\t\tthis.reader = reader\n\t\treturn reader\n\t}\n\n\tprivate settle(line: string | undefined): void {\n\t\tconst waiting = this.waiting\n\t\tif (!waiting) {\n\t\t\tif (line !== undefined) {\n\t\t\t\tthis.lines.push(line)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tthis.waiting = undefined\n\t\tif (!this.closed) {\n\t\t\t// a paused TTY does not keep the process alive between prompts; Node throws when pausing a closed interface\n\t\t\tthis.reader?.pause()\n\t\t}\n\t\twaiting(line)\n\t}\n}\n\nconst writeStream = (stream: OutputStream, text: string): void => {\n\ttry {\n\t\tstream.write(text)\n\t} catch (error) {\n\t\thandleStreamError(error)\n\t}\n}\n\nconst handleStreamError = (error: unknown): void => {\n\tif (typeof error === 'object' && error !== null && 'code' in error && error.code === 'EPIPE') {\n\t\treturn\n\t}\n\tthrow error\n}\n\n/** Removes terminal control characters from untrusted human-readable text. */\nexport const escapeTerminalText = (value: string): string => {\n\tlet escaped = ''\n\tfor (const character of value) {\n\t\tif (!isTerminalControl(character)) {\n\t\t\tescaped += character\n\t\t}\n\t}\n\treturn escaped\n}\n\nconst isTerminalControl = (character: string): boolean => {\n\tconst codePoint = character.codePointAt(0)\n\treturn codePoint !== undefined && (codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f))\n}\n\n// generic in the field so that `format` is a single signature here, not a union of them\nconst renderTableCell = <T, K extends keyof T & string>(column: OutputTableColumns<T>[K], row: T): string =>\n\tcolumn.format ? column.format(row[column.field], row) : formatCell(row[column.field])\n\nconst formatCell = (value: unknown): string => {\n\tif (value === undefined || value === null) {\n\t\treturn ''\n\t}\n\tif (typeof value === 'string') {\n\t\treturn escapeTerminalText(value)\n\t}\n\tif (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {\n\t\treturn String(value)\n\t}\n\treturn JSON.stringify(value) ?? ''\n}\n\nconst toScalarLines = (value: unknown): string[] => {\n\tconst values: unknown[] = Array.isArray(value) ? value : [value]\n\tif (!values.every(isOutputScalar)) {\n\t\tthrow new TypeError('Quiet output requires a scalar value or an array of scalar values. Pass an explicit quiet projection for structured data.')\n\t}\n\treturn values.filter(it => it !== undefined && it !== null).map(formatCell)\n}\n\nconst isOutputScalar = (value: unknown): value is OutputScalar =>\n\tvalue === null || value === undefined || ['string', 'number', 'boolean', 'bigint'].includes(typeof value)\n"],"names":["setColorsEnabled","terminalSupportsColor","formatTable","style","CliError","ExitCode","createInterface"],"mappings":";;;;;;;;;AAgDO,MAAM,oBAAoB,CAAC,YAA4C;AAC7E,MAAI,QAAQ,MAAM;AACjB,WAAO;AAAA,EACR;AACA,MAAI,QAAQ,OAAO;AAClB,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAQO,MAAM,OAAO;AAAA,EAQnB,YAAY,UAAyB,IAAI;AAPzC,kBAAA,MAAQ,eAA0B,OAAA;AAClC,kBAAA,MAAQ,mBAAkB,KAAA;AAC1B,kBAAA,MAAiB,QAAA;AACjB,kBAAA,MAAiB,QAAA;AACjB,kBAAA,MAAiB,YAAA;AACjB,kBAAA,MAAiB,gBAAA;AAGhB,SAAK,SAAS,QAAQ,UAAU,oBAAoB,QAAQ,MAAM;AAClE,SAAK,SAAS,QAAQ,UAAU,oBAAoB,QAAQ,MAAM;AAClE,SAAK,aAAa,QAAQ,eAAe,MAAM,QAAQ,MAAM,U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