@contember/cli-common 2.2.0-alpha.1 → 2.2.0-alpha.10

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 (224) hide show
  1. package/dist/development/index.cjs +20 -0
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +22 -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 +242 -0
  46. package/dist/development/src/application/Output.cjs.map +1 -0
  47. package/dist/development/src/application/Output.js +242 -0
  48. package/dist/development/src/application/Output.js.map +1 -0
  49. package/dist/development/src/application/exitProcess.cjs +7 -0
  50. package/dist/development/src/application/exitProcess.cjs.map +1 -0
  51. package/dist/development/src/application/exitProcess.js +7 -0
  52. package/dist/development/src/application/exitProcess.js.map +1 -0
  53. package/dist/development/src/npm/CommandRunner.cjs +126 -24
  54. package/dist/development/src/npm/CommandRunner.cjs.map +1 -1
  55. package/dist/development/src/npm/CommandRunner.js +126 -24
  56. package/dist/development/src/npm/CommandRunner.js.map +1 -1
  57. package/dist/development/src/npm/packageManagers/Bun.cjs +1 -2
  58. package/dist/development/src/npm/packageManagers/Bun.cjs.map +1 -1
  59. package/dist/development/src/npm/packageManagers/Bun.js +1 -2
  60. package/dist/development/src/npm/packageManagers/Bun.js.map +1 -1
  61. package/dist/development/src/npm/packageManagers/Npm.cjs +1 -2
  62. package/dist/development/src/npm/packageManagers/Npm.cjs.map +1 -1
  63. package/dist/development/src/npm/packageManagers/Npm.js +1 -2
  64. package/dist/development/src/npm/packageManagers/Npm.js.map +1 -1
  65. package/dist/development/src/npm/packageManagers/Pnpm.cjs +1 -2
  66. package/dist/development/src/npm/packageManagers/Pnpm.cjs.map +1 -1
  67. package/dist/development/src/npm/packageManagers/Pnpm.js +1 -2
  68. package/dist/development/src/npm/packageManagers/Pnpm.js.map +1 -1
  69. package/dist/development/src/npm/packageManagers/Yarn.cjs +1 -2
  70. package/dist/development/src/npm/packageManagers/Yarn.cjs.map +1 -1
  71. package/dist/development/src/npm/packageManagers/Yarn.js +1 -2
  72. package/dist/development/src/npm/packageManagers/Yarn.js.map +1 -1
  73. package/dist/development/src/npm/packageManagers/YarnClassic.cjs +1 -2
  74. package/dist/development/src/npm/packageManagers/YarnClassic.cjs.map +1 -1
  75. package/dist/development/src/npm/packageManagers/YarnClassic.js +1 -2
  76. package/dist/development/src/npm/packageManagers/YarnClassic.js.map +1 -1
  77. package/dist/production/index.cjs +20 -0
  78. package/dist/production/index.cjs.map +1 -1
  79. package/dist/production/index.js +22 -2
  80. package/dist/production/index.js.map +1 -1
  81. package/dist/production/src/application/Application.cjs +116 -59
  82. package/dist/production/src/application/Application.cjs.map +1 -1
  83. package/dist/production/src/application/Application.js +116 -59
  84. package/dist/production/src/application/Application.js.map +1 -1
  85. package/dist/production/src/application/CliError.cjs +104 -0
  86. package/dist/production/src/application/CliError.cjs.map +1 -0
  87. package/dist/production/src/application/CliError.js +104 -0
  88. package/dist/production/src/application/CliError.js.map +1 -0
  89. package/dist/production/src/application/Command.cjs +18 -5
  90. package/dist/production/src/application/Command.cjs.map +1 -1
  91. package/dist/production/src/application/Command.js +18 -5
  92. package/dist/production/src/application/Command.js.map +1 -1
  93. package/dist/production/src/application/CommandConfiguration.cjs +21 -3
  94. package/dist/production/src/application/CommandConfiguration.cjs.map +1 -1
  95. package/dist/production/src/application/CommandConfiguration.js +23 -5
  96. package/dist/production/src/application/CommandConfiguration.js.map +1 -1
  97. package/dist/production/src/application/CommandManager.cjs +139 -21
  98. package/dist/production/src/application/CommandManager.cjs.map +1 -1
  99. package/dist/production/src/application/CommandManager.js +139 -21
  100. package/dist/production/src/application/CommandManager.js.map +1 -1
  101. package/dist/production/src/application/ErrorRenderer.cjs +38 -0
  102. package/dist/production/src/application/ErrorRenderer.cjs.map +1 -0
  103. package/dist/production/src/application/ErrorRenderer.js +38 -0
  104. package/dist/production/src/application/ErrorRenderer.js.map +1 -0
  105. package/dist/production/src/application/GlobalOptions.cjs +54 -0
  106. package/dist/production/src/application/GlobalOptions.cjs.map +1 -0
  107. package/dist/production/src/application/GlobalOptions.js +54 -0
  108. package/dist/production/src/application/GlobalOptions.js.map +1 -0
  109. package/dist/production/src/application/Input.cjs +5 -0
  110. package/dist/production/src/application/Input.cjs.map +1 -1
  111. package/dist/production/src/application/Input.js +5 -0
  112. package/dist/production/src/application/Input.js.map +1 -1
  113. package/dist/production/src/application/InputParser.cjs +7 -3
  114. package/dist/production/src/application/InputParser.cjs.map +1 -1
  115. package/dist/production/src/application/InputParser.js +7 -3
  116. package/dist/production/src/application/InputParser.js.map +1 -1
  117. package/dist/production/src/application/Option.cjs +11 -0
  118. package/dist/production/src/application/Option.cjs.map +1 -1
  119. package/dist/production/src/application/Option.js +12 -1
  120. package/dist/production/src/application/Option.js.map +1 -1
  121. package/dist/production/src/application/Output.cjs +242 -0
  122. package/dist/production/src/application/Output.cjs.map +1 -0
  123. package/dist/production/src/application/Output.js +242 -0
  124. package/dist/production/src/application/Output.js.map +1 -0
  125. package/dist/production/src/application/exitProcess.cjs +7 -0
  126. package/dist/production/src/application/exitProcess.cjs.map +1 -0
  127. package/dist/production/src/application/exitProcess.js +7 -0
  128. package/dist/production/src/application/exitProcess.js.map +1 -0
  129. package/dist/production/src/npm/CommandRunner.cjs +126 -24
  130. package/dist/production/src/npm/CommandRunner.cjs.map +1 -1
  131. package/dist/production/src/npm/CommandRunner.js +126 -24
  132. package/dist/production/src/npm/CommandRunner.js.map +1 -1
  133. package/dist/production/src/npm/packageManagers/Bun.cjs +1 -2
  134. package/dist/production/src/npm/packageManagers/Bun.cjs.map +1 -1
  135. package/dist/production/src/npm/packageManagers/Bun.js +1 -2
  136. package/dist/production/src/npm/packageManagers/Bun.js.map +1 -1
  137. package/dist/production/src/npm/packageManagers/Npm.cjs +1 -2
  138. package/dist/production/src/npm/packageManagers/Npm.cjs.map +1 -1
  139. package/dist/production/src/npm/packageManagers/Npm.js +1 -2
  140. package/dist/production/src/npm/packageManagers/Npm.js.map +1 -1
  141. package/dist/production/src/npm/packageManagers/Pnpm.cjs +1 -2
  142. package/dist/production/src/npm/packageManagers/Pnpm.cjs.map +1 -1
  143. package/dist/production/src/npm/packageManagers/Pnpm.js +1 -2
  144. package/dist/production/src/npm/packageManagers/Pnpm.js.map +1 -1
  145. package/dist/production/src/npm/packageManagers/Yarn.cjs +1 -2
  146. package/dist/production/src/npm/packageManagers/Yarn.cjs.map +1 -1
  147. package/dist/production/src/npm/packageManagers/Yarn.js +1 -2
  148. package/dist/production/src/npm/packageManagers/Yarn.js.map +1 -1
  149. package/dist/production/src/npm/packageManagers/YarnClassic.cjs +1 -2
  150. package/dist/production/src/npm/packageManagers/YarnClassic.cjs.map +1 -1
  151. package/dist/production/src/npm/packageManagers/YarnClassic.js +1 -2
  152. package/dist/production/src/npm/packageManagers/YarnClassic.js.map +1 -1
  153. package/dist/types/application/Application.d.ts +22 -11
  154. package/dist/types/application/Application.d.ts.map +1 -1
  155. package/dist/types/application/Argument.d.ts.map +1 -1
  156. package/dist/types/application/CliError.d.ts +40 -0
  157. package/dist/types/application/CliError.d.ts.map +1 -0
  158. package/dist/types/application/Command.d.ts +12 -2
  159. package/dist/types/application/Command.d.ts.map +1 -1
  160. package/dist/types/application/CommandConfiguration.d.ts +7 -4
  161. package/dist/types/application/CommandConfiguration.d.ts.map +1 -1
  162. package/dist/types/application/CommandManager.d.ts +40 -2
  163. package/dist/types/application/CommandManager.d.ts.map +1 -1
  164. package/dist/types/application/ErrorRenderer.d.ts +8 -0
  165. package/dist/types/application/ErrorRenderer.d.ts.map +1 -0
  166. package/dist/types/application/GlobalOptions.d.ts +28 -0
  167. package/dist/types/application/GlobalOptions.d.ts.map +1 -0
  168. package/dist/types/application/Input.d.ts +2 -0
  169. package/dist/types/application/Input.d.ts.map +1 -1
  170. package/dist/types/application/InputParser.d.ts +5 -1
  171. package/dist/types/application/InputParser.d.ts.map +1 -1
  172. package/dist/types/application/Option.d.ts +2 -0
  173. package/dist/types/application/Option.d.ts.map +1 -1
  174. package/dist/types/application/Output.d.ts +81 -0
  175. package/dist/types/application/Output.d.ts.map +1 -0
  176. package/dist/types/application/UsageFormatter.d.ts.map +1 -1
  177. package/dist/types/application/exitProcess.d.ts +11 -0
  178. package/dist/types/application/exitProcess.d.ts.map +1 -0
  179. package/dist/types/application/index.d.ts +5 -0
  180. package/dist/types/application/index.d.ts.map +1 -1
  181. package/dist/types/index.d.ts +2 -2
  182. package/dist/types/index.d.ts.map +1 -1
  183. package/dist/types/npm/CommandRunner.d.ts +13 -0
  184. package/dist/types/npm/CommandRunner.d.ts.map +1 -1
  185. package/dist/types/npm/Package.d.ts.map +1 -1
  186. package/dist/types/npm/PackageWorkspace.d.ts.map +1 -1
  187. package/dist/types/npm/PackageWorkspaceResolver.d.ts.map +1 -1
  188. package/dist/types/npm/packageManagers/Bun.d.ts.map +1 -1
  189. package/dist/types/npm/packageManagers/Npm.d.ts.map +1 -1
  190. package/dist/types/npm/packageManagers/PackageManagerHelpers.d.ts.map +1 -1
  191. package/dist/types/npm/packageManagers/Pnpm.d.ts.map +1 -1
  192. package/dist/types/npm/packageManagers/Yarn.d.ts.map +1 -1
  193. package/dist/types/npm/packageManagers/YarnClassic.d.ts.map +1 -1
  194. package/dist/types/tsconfig.tsbuildinfo +1 -1
  195. package/dist/types/utils/findPackageRoot.d.ts.map +1 -1
  196. package/package.json +3 -2
  197. package/src/application/Application.ts +137 -75
  198. package/src/application/CliError.ts +117 -0
  199. package/src/application/Command.ts +27 -6
  200. package/src/application/CommandConfiguration.ts +22 -4
  201. package/src/application/CommandManager.ts +172 -22
  202. package/src/application/ErrorRenderer.ts +40 -0
  203. package/src/application/GlobalOptions.ts +76 -0
  204. package/src/application/Input.ts +6 -0
  205. package/src/application/InputParser.ts +13 -4
  206. package/src/application/Option.ts +12 -0
  207. package/src/application/Output.ts +329 -0
  208. package/src/application/exitProcess.ts +12 -0
  209. package/src/application/index.ts +5 -0
  210. package/src/index.ts +40 -2
  211. package/src/npm/CommandRunner.ts +166 -23
  212. package/src/npm/packageManagers/Bun.ts +1 -2
  213. package/src/npm/packageManagers/Npm.ts +1 -2
  214. package/src/npm/packageManagers/Pnpm.ts +1 -2
  215. package/src/npm/packageManagers/Yarn.ts +1 -2
  216. package/src/npm/packageManagers/YarnClassic.ts +1 -2
  217. package/tests/cases/unit/application.test.ts +426 -0
  218. package/tests/cases/unit/cliError.test.ts +127 -0
  219. package/tests/cases/unit/commandManager.test.ts +270 -0
  220. package/tests/cases/unit/commandRunner.test.ts +192 -0
  221. package/tests/cases/unit/inputParser.test.ts +21 -0
  222. package/tests/cases/unit/output.test.ts +393 -0
  223. package/tests/lib/testOutput.ts +35 -0
  224. package/types/chalk-table/index.d.ts +9 -0
@@ -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,242 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const chalk = require("chalk");
4
+ const chalkTable = require("chalk-table");
5
+ const node_stream = require("node:stream");
6
+ var __defProp = Object.defineProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
+ let supportedChalkLevel = chalk.level;
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, "promptStderr");
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.promptStderr = options.stderr === void 0 ? process.stderr : createPromptStream(this.stderr);
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
+ if (globals.color && this.currentMode === "human") {
50
+ if (chalk.level === 0) {
51
+ chalk.level = supportedChalkLevel;
52
+ } else {
53
+ supportedChalkLevel = chalk.level;
54
+ }
55
+ } else {
56
+ if (chalk.level !== 0) {
57
+ supportedChalkLevel = chalk.level;
58
+ }
59
+ chalk.level = 0;
60
+ }
61
+ }
62
+ data(value, rendering) {
63
+ const human = typeof rendering === "function" ? rendering : rendering?.human;
64
+ if (this.currentMode === "json") {
65
+ this.writeStdout(JSON.stringify(value ?? null, null, 2));
66
+ return;
67
+ }
68
+ if (this.currentMode === "quiet") {
69
+ const quietValue = typeof rendering === "object" && rendering.quiet ? rendering.quiet(value) : value;
70
+ for (const line of toScalarLines(quietValue)) {
71
+ this.writeStdout(line);
72
+ }
73
+ return;
74
+ }
75
+ this.writeStdout(human ? human(value) : JSON.stringify(value ?? null, null, 2));
76
+ }
77
+ table(columns, rows, quietField) {
78
+ if (this.currentMode === "json") {
79
+ this.writeStdout(JSON.stringify(rows, null, 2));
80
+ return;
81
+ }
82
+ if (this.currentMode === "quiet") {
83
+ const field = quietField ?? columns[0]?.field;
84
+ if (field === void 0) {
85
+ return;
86
+ }
87
+ for (const row of rows) {
88
+ this.writeStdout(formatCell(row[field]));
89
+ }
90
+ return;
91
+ }
92
+ if (rows.length === 0) {
93
+ return;
94
+ }
95
+ const data = rows.map((row) => {
96
+ const cells = {};
97
+ for (const column of columns) {
98
+ cells[column.field] = renderTableCell(column, row);
99
+ }
100
+ return cells;
101
+ });
102
+ this.writeStdout(chalkTable({ columns: columns.map((it) => ({ field: it.field, name: it.name })) }, data));
103
+ }
104
+ // DIAGNOSTICS → stderr
105
+ info(message) {
106
+ this.writeDiagnostic(message);
107
+ }
108
+ warn(message) {
109
+ this.writeDiagnostic(message, (text) => chalk.yellow(text));
110
+ }
111
+ error(message) {
112
+ this.writeDiagnostic(message, (text) => chalk.red(text));
113
+ }
114
+ // PROGRESS → stderr
115
+ progress(message) {
116
+ if (this.currentMode !== "human" || !this.stderr.isTty) {
117
+ return;
118
+ }
119
+ this.clearProgress();
120
+ writeStream(this.stderr, escapeTerminalText(message));
121
+ this.progressVisible = true;
122
+ }
123
+ clearProgress() {
124
+ if (!this.progressVisible) {
125
+ return;
126
+ }
127
+ this.progressVisible = false;
128
+ writeStream(this.stderr, "\r\x1B[K");
129
+ }
130
+ /** False unless both sides of an interactive prompt are TTYs in human mode. */
131
+ canPrompt() {
132
+ return this.currentMode === "human" && this.stdinIsTty() && this.stderr.isTty;
133
+ }
134
+ /** A real Writable suitable for the `stdout` option of interactive prompt libraries. */
135
+ get promptOutput() {
136
+ return this.promptStderr;
137
+ }
138
+ /**
139
+ * Writes a line to stderr regardless of the mode. Reserved for content the user explicitly asked for
140
+ * (help) or must always see (a fatal error) — everything else belongs to the methods above.
141
+ */
142
+ writeStderr(text) {
143
+ this.clearProgress();
144
+ writeStream(this.stderr, text + "\n");
145
+ }
146
+ writeStdout(text) {
147
+ this.clearProgress();
148
+ writeStream(this.stdout, text + "\n");
149
+ }
150
+ writeDiagnostic(message, format = (text) => text) {
151
+ if (this.currentMode !== "human") {
152
+ return;
153
+ }
154
+ this.clearProgress();
155
+ writeStream(this.stderr, format(escapeTerminalText(message)) + "\n");
156
+ }
157
+ }
158
+ const createProcessStream = (stream) => ({
159
+ write: (text) => {
160
+ stream.write(text);
161
+ },
162
+ get isTty() {
163
+ return stream.isTTY === true;
164
+ },
165
+ get columns() {
166
+ return stream.columns;
167
+ },
168
+ onError: (listener) => {
169
+ stream.on("error", (error) => listener(error));
170
+ }
171
+ });
172
+ class PromptWritable extends node_stream.Writable {
173
+ constructor(stream) {
174
+ super({ decodeStrings: false });
175
+ this.stream = stream;
176
+ __publicField(this, "isTTY");
177
+ this.isTTY = stream.isTty;
178
+ }
179
+ get columns() {
180
+ return this.stream.columns ?? 80;
181
+ }
182
+ _write(chunk, encoding, callback) {
183
+ try {
184
+ writeStream(this.stream, typeof chunk === "string" ? chunk : Buffer.from(chunk).toString(encoding));
185
+ callback();
186
+ } catch (error) {
187
+ callback(error instanceof Error ? error : new Error(String(error)));
188
+ }
189
+ }
190
+ }
191
+ const createPromptStream = (stream) => new PromptWritable(stream);
192
+ const writeStream = (stream, text) => {
193
+ try {
194
+ stream.write(text);
195
+ } catch (error) {
196
+ handleStreamError(error);
197
+ }
198
+ };
199
+ const handleStreamError = (error) => {
200
+ if (typeof error === "object" && error !== null && "code" in error && error.code === "EPIPE") {
201
+ return;
202
+ }
203
+ throw error;
204
+ };
205
+ const escapeTerminalText = (value) => {
206
+ let escaped = "";
207
+ for (const character of value) {
208
+ if (!isTerminalControl(character)) {
209
+ escaped += character;
210
+ }
211
+ }
212
+ return escaped;
213
+ };
214
+ const isTerminalControl = (character) => {
215
+ const codePoint = character.codePointAt(0);
216
+ return codePoint !== void 0 && (codePoint <= 31 || codePoint >= 127 && codePoint <= 159);
217
+ };
218
+ const renderTableCell = (column, row) => column.format ? column.format(row[column.field], row) : formatCell(row[column.field]);
219
+ const formatCell = (value) => {
220
+ if (value === void 0 || value === null) {
221
+ return "";
222
+ }
223
+ if (typeof value === "string") {
224
+ return escapeTerminalText(value);
225
+ }
226
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
227
+ return String(value);
228
+ }
229
+ return JSON.stringify(value) ?? "";
230
+ };
231
+ const toScalarLines = (value) => {
232
+ const values = Array.isArray(value) ? value : [value];
233
+ if (!values.every(isOutputScalar)) {
234
+ throw new TypeError("Quiet output requires a scalar value or an array of scalar values. Pass an explicit quiet projection for structured data.");
235
+ }
236
+ return values.filter((it) => it !== void 0 && it !== null).map(formatCell);
237
+ };
238
+ const isOutputScalar = (value) => value === null || value === void 0 || ["string", "number", "boolean", "bigint"].includes(typeof value);
239
+ exports.Output = Output;
240
+ exports.escapeTerminalText = escapeTerminalText;
241
+ exports.resolveOutputMode = resolveOutputMode;
242
+ //# sourceMappingURL=Output.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Output.cjs","sources":["../../../../../packages/cli-common/src/application/Output.ts"],"sourcesContent":["/// <reference path=\"../../types/chalk-table/index.d.ts\" />\n\nimport chalk from 'chalk'\nimport chalkTable from 'chalk-table'\nimport { Writable } from 'node:stream'\nimport type { GlobalOptionValues } from './GlobalOptions.js'\n\nexport type OutputMode = 'human' | 'json' | 'quiet'\n\nlet supportedChalkLevel = chalk.level\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\nexport interface OutputOptions {\n\tstdout?: OutputStream\n\tstderr?: OutputStream\n\tisStdinTty?: () => boolean\n}\n\nexport interface PromptOutputStream extends Writable {\n\treadonly isTTY: boolean\n\treadonly columns: number\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 promptStderr: PromptOutputStream\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.promptStderr = options.stderr === undefined ? process.stderr : createPromptStream(this.stderr)\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\tif (globals.color && this.currentMode === 'human') {\n\t\t\tif (chalk.level === 0) {\n\t\t\t\tchalk.level = supportedChalkLevel\n\t\t\t} else {\n\t\t\t\tsupportedChalkLevel = chalk.level\n\t\t\t}\n\t\t} else {\n\t\t\tif (chalk.level !== 0) {\n\t\t\t\tsupportedChalkLevel = chalk.level\n\t\t\t}\n\t\t\tchalk.level = 0\n\t\t}\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: Record<string, string>[] = rows.map(row => {\n\t\t\tconst cells: Record<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(chalkTable<string>({ columns: 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 => chalk.yellow(text))\n\t}\n\n\tpublic error(message: string): void {\n\t\tthis.writeDiagnostic(message, text => chalk.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/** A real Writable suitable for the `stdout` option of interactive prompt libraries. */\n\tpublic get promptOutput(): PromptOutputStream {\n\t\treturn this.promptStderr\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\nclass PromptWritable extends Writable {\n\tpublic readonly isTTY: boolean\n\n\tconstructor(private readonly stream: OutputStream) {\n\t\tsuper({ decodeStrings: false })\n\t\tthis.isTTY = stream.isTty\n\t}\n\n\tpublic get columns(): number {\n\t\treturn this.stream.columns ?? 80\n\t}\n\n\tpublic override _write(chunk: string | Uint8Array, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n\t\ttry {\n\t\t\twriteStream(this.stream, typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString(encoding))\n\t\t\tcallback()\n\t\t} catch (error) {\n\t\t\tcallback(error instanceof Error ? error : new Error(String(error)))\n\t\t}\n\t}\n}\n\nconst createPromptStream = (stream: OutputStream): PromptOutputStream => new PromptWritable(stream)\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":["Writable"],"mappings":";;;;;;;;AASA,IAAI,sBAAsB,MAAM;AA0CzB,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,cAAA;AAGhB,SAAK,SAAS,QAAQ,UAAU,oBAAoB,QAAQ,MAAM;AAClE,SAAK,SAAS,QAAQ,UAAU,oBAAoB,QAAQ,MAAM;AAClE,SAAK,aAAa,QAAQ,eA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O,UAAU,YAAY,OAAO,UAAU,aAAa,OAAO,UAAU,UAAU;AACzF,WAAO,OAAO,KAAK;AAAA,EACpB;AACA,SAAO,KAAK,UAAU,KAAK,KAAK;AACjC;AAEA,MAAM,gBAAgB,CAAC,UAA6B;AACnD,QAAM,SAAoB,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;AAC/D,MAAI,CAAC,OAAO,MAAM,cAAc,GAAG;AAClC,UAAM,IAAI,UAAU,2HAA2H;AAAA,EAChJ;AACA,SAAO,OAAO,OAAO,CAAA,OAAM,OAAO,UAAa,OAAO,IAAI,EAAE,IAAI,UAAU;AAC3E;AAEA,MAAM,iBAAiB,CAAC,UACvB,UAAU,QAAQ,UAAU,UAAa,CAAC,UAAU,UAAU,WAAW,QAAQ,EAAE,SAAS,OAAO,KAAK;;;;"}
@@ -0,0 +1,242 @@
1
+ import chalk from "chalk";
2
+ import chalkTable from "chalk-table";
3
+ import { Writable } from "node:stream";
4
+ var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ let supportedChalkLevel = chalk.level;
8
+ const resolveOutputMode = (globals) => {
9
+ if (globals.json) {
10
+ return "json";
11
+ }
12
+ if (globals.quiet) {
13
+ return "quiet";
14
+ }
15
+ return "human";
16
+ };
17
+ class Output {
18
+ constructor(options = {}) {
19
+ __publicField(this, "currentMode", "human");
20
+ __publicField(this, "progressVisible", false);
21
+ __publicField(this, "stdout");
22
+ __publicField(this, "stderr");
23
+ __publicField(this, "stdinIsTty");
24
+ __publicField(this, "promptStderr");
25
+ this.stdout = options.stdout ?? createProcessStream(process.stdout);
26
+ this.stderr = options.stderr ?? createProcessStream(process.stderr);
27
+ this.stdinIsTty = options.isStdinTty ?? (() => process.stdin.isTTY === true);
28
+ this.promptStderr = options.stderr === void 0 ? process.stderr : createPromptStream(this.stderr);
29
+ this.stdout.onError?.(handleStreamError);
30
+ this.stderr.onError?.(handleStreamError);
31
+ }
32
+ get mode() {
33
+ return this.currentMode;
34
+ }
35
+ get isJson() {
36
+ return this.currentMode === "json";
37
+ }
38
+ get isQuiet() {
39
+ return this.currentMode === "quiet";
40
+ }
41
+ /** Set by `Application` once the global options are parsed. */
42
+ setMode(mode) {
43
+ this.currentMode = mode;
44
+ }
45
+ applyGlobalOptions(globals) {
46
+ this.setMode(resolveOutputMode(globals));
47
+ if (globals.color && this.currentMode === "human") {
48
+ if (chalk.level === 0) {
49
+ chalk.level = supportedChalkLevel;
50
+ } else {
51
+ supportedChalkLevel = chalk.level;
52
+ }
53
+ } else {
54
+ if (chalk.level !== 0) {
55
+ supportedChalkLevel = chalk.level;
56
+ }
57
+ chalk.level = 0;
58
+ }
59
+ }
60
+ data(value, rendering) {
61
+ const human = typeof rendering === "function" ? rendering : rendering?.human;
62
+ if (this.currentMode === "json") {
63
+ this.writeStdout(JSON.stringify(value ?? null, null, 2));
64
+ return;
65
+ }
66
+ if (this.currentMode === "quiet") {
67
+ const quietValue = typeof rendering === "object" && rendering.quiet ? rendering.quiet(value) : value;
68
+ for (const line of toScalarLines(quietValue)) {
69
+ this.writeStdout(line);
70
+ }
71
+ return;
72
+ }
73
+ this.writeStdout(human ? human(value) : JSON.stringify(value ?? null, null, 2));
74
+ }
75
+ table(columns, rows, quietField) {
76
+ if (this.currentMode === "json") {
77
+ this.writeStdout(JSON.stringify(rows, null, 2));
78
+ return;
79
+ }
80
+ if (this.currentMode === "quiet") {
81
+ const field = quietField ?? columns[0]?.field;
82
+ if (field === void 0) {
83
+ return;
84
+ }
85
+ for (const row of rows) {
86
+ this.writeStdout(formatCell(row[field]));
87
+ }
88
+ return;
89
+ }
90
+ if (rows.length === 0) {
91
+ return;
92
+ }
93
+ const data = rows.map((row) => {
94
+ const cells = {};
95
+ for (const column of columns) {
96
+ cells[column.field] = renderTableCell(column, row);
97
+ }
98
+ return cells;
99
+ });
100
+ this.writeStdout(chalkTable({ columns: columns.map((it) => ({ field: it.field, name: it.name })) }, data));
101
+ }
102
+ // DIAGNOSTICS → stderr
103
+ info(message) {
104
+ this.writeDiagnostic(message);
105
+ }
106
+ warn(message) {
107
+ this.writeDiagnostic(message, (text) => chalk.yellow(text));
108
+ }
109
+ error(message) {
110
+ this.writeDiagnostic(message, (text) => chalk.red(text));
111
+ }
112
+ // PROGRESS → stderr
113
+ progress(message) {
114
+ if (this.currentMode !== "human" || !this.stderr.isTty) {
115
+ return;
116
+ }
117
+ this.clearProgress();
118
+ writeStream(this.stderr, escapeTerminalText(message));
119
+ this.progressVisible = true;
120
+ }
121
+ clearProgress() {
122
+ if (!this.progressVisible) {
123
+ return;
124
+ }
125
+ this.progressVisible = false;
126
+ writeStream(this.stderr, "\r\x1B[K");
127
+ }
128
+ /** False unless both sides of an interactive prompt are TTYs in human mode. */
129
+ canPrompt() {
130
+ return this.currentMode === "human" && this.stdinIsTty() && this.stderr.isTty;
131
+ }
132
+ /** A real Writable suitable for the `stdout` option of interactive prompt libraries. */
133
+ get promptOutput() {
134
+ return this.promptStderr;
135
+ }
136
+ /**
137
+ * Writes a line to stderr regardless of the mode. Reserved for content the user explicitly asked for
138
+ * (help) or must always see (a fatal error) — everything else belongs to the methods above.
139
+ */
140
+ writeStderr(text) {
141
+ this.clearProgress();
142
+ writeStream(this.stderr, text + "\n");
143
+ }
144
+ writeStdout(text) {
145
+ this.clearProgress();
146
+ writeStream(this.stdout, text + "\n");
147
+ }
148
+ writeDiagnostic(message, format = (text) => text) {
149
+ if (this.currentMode !== "human") {
150
+ return;
151
+ }
152
+ this.clearProgress();
153
+ writeStream(this.stderr, format(escapeTerminalText(message)) + "\n");
154
+ }
155
+ }
156
+ const createProcessStream = (stream) => ({
157
+ write: (text) => {
158
+ stream.write(text);
159
+ },
160
+ get isTty() {
161
+ return stream.isTTY === true;
162
+ },
163
+ get columns() {
164
+ return stream.columns;
165
+ },
166
+ onError: (listener) => {
167
+ stream.on("error", (error) => listener(error));
168
+ }
169
+ });
170
+ class PromptWritable extends Writable {
171
+ constructor(stream) {
172
+ super({ decodeStrings: false });
173
+ this.stream = stream;
174
+ __publicField(this, "isTTY");
175
+ this.isTTY = stream.isTty;
176
+ }
177
+ get columns() {
178
+ return this.stream.columns ?? 80;
179
+ }
180
+ _write(chunk, encoding, callback) {
181
+ try {
182
+ writeStream(this.stream, typeof chunk === "string" ? chunk : Buffer.from(chunk).toString(encoding));
183
+ callback();
184
+ } catch (error) {
185
+ callback(error instanceof Error ? error : new Error(String(error)));
186
+ }
187
+ }
188
+ }
189
+ const createPromptStream = (stream) => new PromptWritable(stream);
190
+ const writeStream = (stream, text) => {
191
+ try {
192
+ stream.write(text);
193
+ } catch (error) {
194
+ handleStreamError(error);
195
+ }
196
+ };
197
+ const handleStreamError = (error) => {
198
+ if (typeof error === "object" && error !== null && "code" in error && error.code === "EPIPE") {
199
+ return;
200
+ }
201
+ throw error;
202
+ };
203
+ const escapeTerminalText = (value) => {
204
+ let escaped = "";
205
+ for (const character of value) {
206
+ if (!isTerminalControl(character)) {
207
+ escaped += character;
208
+ }
209
+ }
210
+ return escaped;
211
+ };
212
+ const isTerminalControl = (character) => {
213
+ const codePoint = character.codePointAt(0);
214
+ return codePoint !== void 0 && (codePoint <= 31 || codePoint >= 127 && codePoint <= 159);
215
+ };
216
+ const renderTableCell = (column, row) => column.format ? column.format(row[column.field], row) : formatCell(row[column.field]);
217
+ const formatCell = (value) => {
218
+ if (value === void 0 || value === null) {
219
+ return "";
220
+ }
221
+ if (typeof value === "string") {
222
+ return escapeTerminalText(value);
223
+ }
224
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
225
+ return String(value);
226
+ }
227
+ return JSON.stringify(value) ?? "";
228
+ };
229
+ const toScalarLines = (value) => {
230
+ const values = Array.isArray(value) ? value : [value];
231
+ if (!values.every(isOutputScalar)) {
232
+ throw new TypeError("Quiet output requires a scalar value or an array of scalar values. Pass an explicit quiet projection for structured data.");
233
+ }
234
+ return values.filter((it) => it !== void 0 && it !== null).map(formatCell);
235
+ };
236
+ const isOutputScalar = (value) => value === null || value === void 0 || ["string", "number", "boolean", "bigint"].includes(typeof value);
237
+ export {
238
+ Output,
239
+ escapeTerminalText,
240
+ resolveOutputMode
241
+ };
242
+ //# sourceMappingURL=Output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Output.js","sources":["../../../../../packages/cli-common/src/application/Output.ts"],"sourcesContent":["/// <reference path=\"../../types/chalk-table/index.d.ts\" />\n\nimport chalk from 'chalk'\nimport chalkTable from 'chalk-table'\nimport { Writable } from 'node:stream'\nimport type { GlobalOptionValues } from './GlobalOptions.js'\n\nexport type OutputMode = 'human' | 'json' | 'quiet'\n\nlet supportedChalkLevel = chalk.level\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\nexport interface OutputOptions {\n\tstdout?: OutputStream\n\tstderr?: OutputStream\n\tisStdinTty?: () => boolean\n}\n\nexport interface PromptOutputStream extends Writable {\n\treadonly isTTY: boolean\n\treadonly columns: number\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 promptStderr: PromptOutputStream\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.promptStderr = options.stderr === undefined ? process.stderr : createPromptStream(this.stderr)\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\tif (globals.color && this.currentMode === 'human') {\n\t\t\tif (chalk.level === 0) {\n\t\t\t\tchalk.level = supportedChalkLevel\n\t\t\t} else {\n\t\t\t\tsupportedChalkLevel = chalk.level\n\t\t\t}\n\t\t} else {\n\t\t\tif (chalk.level !== 0) {\n\t\t\t\tsupportedChalkLevel = chalk.level\n\t\t\t}\n\t\t\tchalk.level = 0\n\t\t}\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: Record<string, string>[] = rows.map(row => {\n\t\t\tconst cells: Record<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(chalkTable<string>({ columns: 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 => chalk.yellow(text))\n\t}\n\n\tpublic error(message: string): void {\n\t\tthis.writeDiagnostic(message, text => chalk.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/** A real Writable suitable for the `stdout` option of interactive prompt libraries. */\n\tpublic get promptOutput(): PromptOutputStream {\n\t\treturn this.promptStderr\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\nclass PromptWritable extends Writable {\n\tpublic readonly isTTY: boolean\n\n\tconstructor(private readonly stream: OutputStream) {\n\t\tsuper({ decodeStrings: false })\n\t\tthis.isTTY = stream.isTty\n\t}\n\n\tpublic get columns(): number {\n\t\treturn this.stream.columns ?? 80\n\t}\n\n\tpublic override _write(chunk: string | Uint8Array, encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n\t\ttry {\n\t\t\twriteStream(this.stream, typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString(encoding))\n\t\t\tcallback()\n\t\t} catch (error) {\n\t\t\tcallback(error instanceof Error ? error : new Error(String(error)))\n\t\t}\n\t}\n}\n\nconst createPromptStream = (stream: OutputStream): PromptOutputStream => new PromptWritable(stream)\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":[],"mappings":";;;;;;AASA,IAAI,sBAAsB,MAAM;AA0CzB,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,cAAA;AAGhB,SAAK,SAAS,QAAQ,UAAU,oBAAoB,QAAQ,MAAM;AAClE,SAAK,SAAS,QAAQ,UAAU,oBAAoB,QAAQ,MAAM;AAClE,SAAK,aAAa,QAAQ,eAAe,MAAM,QAAQ,MAAM,UAAU;AACvE,SAAK,eAAe,QAAQ,WAAW,SAAY,QAAQ,SAAS,mBAAmB,KAAK,MAAM;AAClG,SAAK,OAAO,UAAU,iBAAiB;AACvC,SAAK,OAAO,UAAU,iBAAiB;AAAA,EACxC;AAAA,EAEA,IAAW,OAAmB;AAC7B,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,IAAW,SAAkB;AAC5B,WAAO,KAAK,gBAAgB;AAAA,EAC7B;AAAA,EAEA,IAAW,UAAmB;AAC7B,WAAO,KAAK,gBAAgB;AAAA,EAC7B;AAAA;AAAA,EAGO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;AAC3E;AAEA,MAAM,iBAAiB,CAAC,UACvB,UAAU,QAAQ,UAAU,UAAa,CAAC,UAAU,UAAU,WAAW,QAAQ,EAAE,SAAS,OAAO,KAAK;"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const exitProcess = (code) => {
4
+ process.exitCode = code;
5
+ };
6
+ exports.exitProcess = exitProcess;
7
+ //# sourceMappingURL=exitProcess.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exitProcess.cjs","sources":["../../../../../packages/cli-common/src/application/exitProcess.ts"],"sourcesContent":["/**\n * Ends the process with the given exit code without losing buffered output.\n *\n * `process.exit()` terminates immediately and discards whatever `process.stdout` has not yet handed\n * to the OS. Writes to a pipe are asynchronous, so anything past the 64 KB pipe buffer was silently\n * dropped — `contember commands --json | jq` got a truncated document while the same command\n * redirected to a file was complete. Assigning `exitCode` instead lets the runtime exit on its own\n * once the streams have drained, which also covers output written directly through `console.log`.\n */\nexport const exitProcess = (code: number): void => {\n\tprocess.exitCode = code\n}\n"],"names":[],"mappings":";;AASO,MAAM,cAAc,CAAC,SAAuB;AAClD,UAAQ,WAAW;AACpB;;"}
@@ -0,0 +1,7 @@
1
+ const exitProcess = (code) => {
2
+ process.exitCode = code;
3
+ };
4
+ export {
5
+ exitProcess
6
+ };
7
+ //# sourceMappingURL=exitProcess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exitProcess.js","sources":["../../../../../packages/cli-common/src/application/exitProcess.ts"],"sourcesContent":["/**\n * Ends the process with the given exit code without losing buffered output.\n *\n * `process.exit()` terminates immediately and discards whatever `process.stdout` has not yet handed\n * to the OS. Writes to a pipe are asynchronous, so anything past the 64 KB pipe buffer was silently\n * dropped — `contember commands --json | jq` got a truncated document while the same command\n * redirected to a file was complete. Assigning `exitCode` instead lets the runtime exit on its own\n * once the streams have drained, which also covers output written directly through `console.log`.\n */\nexport const exitProcess = (code: number): void => {\n\tprocess.exitCode = code\n}\n"],"names":[],"mappings":"AASO,MAAM,cAAc,CAAC,SAAuB;AAClD,UAAQ,WAAW;AACpB;"}