padrone 1.8.2 → 2.0.0

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 (333) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/README.md +2 -2
  3. package/dist/codegen/code-builder.d.mts +10 -0
  4. package/dist/codegen/code-builder.d.mts.map +1 -0
  5. package/dist/codegen/code-builder.mjs +185 -0
  6. package/dist/codegen/code-builder.mjs.map +1 -0
  7. package/dist/codegen/discovery.d.mts +44 -0
  8. package/dist/codegen/discovery.d.mts.map +1 -0
  9. package/dist/codegen/discovery.mjs +179 -0
  10. package/dist/codegen/discovery.mjs.map +1 -0
  11. package/dist/codegen/file-emitter.d.mts +10 -0
  12. package/dist/codegen/file-emitter.d.mts.map +1 -0
  13. package/dist/codegen/file-emitter.mjs +58 -0
  14. package/dist/codegen/file-emitter.mjs.map +1 -0
  15. package/dist/codegen/generators/barrel-file.d.mts +10 -0
  16. package/dist/codegen/generators/barrel-file.d.mts.map +1 -0
  17. package/dist/codegen/generators/barrel-file.mjs +16 -0
  18. package/dist/codegen/generators/barrel-file.mjs.map +1 -0
  19. package/dist/codegen/generators/command-file.d.mts +25 -0
  20. package/dist/codegen/generators/command-file.d.mts.map +1 -0
  21. package/dist/codegen/generators/command-file.mjs +130 -0
  22. package/dist/codegen/generators/command-file.mjs.map +1 -0
  23. package/dist/codegen/generators/command-tree.d.mts +17 -0
  24. package/dist/codegen/generators/command-tree.d.mts.map +1 -0
  25. package/dist/codegen/generators/command-tree.mjs +72 -0
  26. package/dist/codegen/generators/command-tree.mjs.map +1 -0
  27. package/dist/codegen/index.d.mts +15 -330
  28. package/dist/codegen/index.mjs +13 -1507
  29. package/dist/codegen/parsers/bash.d.mts +19 -0
  30. package/dist/codegen/parsers/bash.d.mts.map +1 -0
  31. package/dist/codegen/parsers/bash.mjs +112 -0
  32. package/dist/codegen/parsers/bash.mjs.map +1 -0
  33. package/dist/codegen/parsers/fish.d.mts +13 -0
  34. package/dist/codegen/parsers/fish.d.mts.map +1 -0
  35. package/dist/codegen/parsers/fish.mjs +108 -0
  36. package/dist/codegen/parsers/fish.mjs.map +1 -0
  37. package/dist/codegen/parsers/help.d.mts +15 -0
  38. package/dist/codegen/parsers/help.d.mts.map +1 -0
  39. package/dist/codegen/parsers/help.mjs +271 -0
  40. package/dist/codegen/parsers/help.mjs.map +1 -0
  41. package/dist/codegen/parsers/merge.d.mts +14 -0
  42. package/dist/codegen/parsers/merge.d.mts.map +1 -0
  43. package/dist/codegen/parsers/merge.mjs +76 -0
  44. package/dist/codegen/parsers/merge.mjs.map +1 -0
  45. package/dist/codegen/parsers/zsh.d.mts +16 -0
  46. package/dist/codegen/parsers/zsh.d.mts.map +1 -0
  47. package/dist/codegen/parsers/zsh.mjs +161 -0
  48. package/dist/codegen/parsers/zsh.mjs.map +1 -0
  49. package/dist/codegen/schema-to-code.d.mts +24 -0
  50. package/dist/codegen/schema-to-code.d.mts.map +1 -0
  51. package/dist/codegen/schema-to-code.mjs +147 -0
  52. package/dist/codegen/schema-to-code.mjs.map +1 -0
  53. package/dist/codegen/template.d.mts +18 -0
  54. package/dist/codegen/template.d.mts.map +1 -0
  55. package/dist/codegen/template.mjs +37 -0
  56. package/dist/codegen/template.mjs.map +1 -0
  57. package/dist/codegen/types.d.mts +144 -0
  58. package/dist/codegen/types.d.mts.map +1 -0
  59. package/dist/completion.d.mts +2 -0
  60. package/dist/completion.mjs +2 -0
  61. package/dist/core/args.d.mts +3 -0
  62. package/dist/{args-DrCXxXeP.mjs → core/args.mjs} +49 -113
  63. package/dist/core/args.mjs.map +1 -0
  64. package/dist/core/commands.d.mts +13 -0
  65. package/dist/core/commands.d.mts.map +1 -0
  66. package/dist/{commands-DLR0rFgq.mjs → core/commands.mjs} +4 -232
  67. package/dist/core/commands.mjs.map +1 -0
  68. package/dist/core/create.d.mts +63 -0
  69. package/dist/core/create.d.mts.map +1 -0
  70. package/dist/core/create.mjs +230 -0
  71. package/dist/core/create.mjs.map +1 -0
  72. package/dist/core/default-runtime.mjs +198 -0
  73. package/dist/core/default-runtime.mjs.map +1 -0
  74. package/dist/core/errors.d.mts +107 -0
  75. package/dist/core/errors.d.mts.map +1 -0
  76. package/dist/{errors-DA4KzK1M.mjs → core/errors.mjs} +2 -2
  77. package/dist/core/errors.mjs.map +1 -0
  78. package/dist/core/exec.mjs +191 -0
  79. package/dist/core/exec.mjs.map +1 -0
  80. package/dist/core/interceptors.d.mts +33 -0
  81. package/dist/core/interceptors.d.mts.map +1 -0
  82. package/dist/core/interceptors.mjs +253 -0
  83. package/dist/core/interceptors.mjs.map +1 -0
  84. package/dist/core/parse.mjs +181 -0
  85. package/dist/core/parse.mjs.map +1 -0
  86. package/dist/core/program-methods.mjs +256 -0
  87. package/dist/core/program-methods.mjs.map +1 -0
  88. package/dist/core/results.d.mts +13 -0
  89. package/dist/core/results.d.mts.map +1 -0
  90. package/dist/core/results.mjs +150 -0
  91. package/dist/core/results.mjs.map +1 -0
  92. package/dist/core/runtime.d.mts +213 -0
  93. package/dist/core/runtime.d.mts.map +1 -0
  94. package/dist/core/runtime.mjs +10 -0
  95. package/dist/core/runtime.mjs.map +1 -0
  96. package/dist/core/validate.mjs +220 -0
  97. package/dist/core/validate.mjs.map +1 -0
  98. package/dist/docs/index.d.mts +1 -1
  99. package/dist/docs/index.d.mts.map +1 -1
  100. package/dist/docs/index.mjs +2 -2
  101. package/dist/docs/index.mjs.map +1 -1
  102. package/dist/extension/auto-output.d.mts +53 -0
  103. package/dist/extension/auto-output.d.mts.map +1 -0
  104. package/dist/extension/auto-output.mjs +116 -0
  105. package/dist/extension/auto-output.mjs.map +1 -0
  106. package/dist/extension/color.d.mts +19 -0
  107. package/dist/extension/color.d.mts.map +1 -0
  108. package/dist/extension/color.mjs +37 -0
  109. package/dist/extension/color.mjs.map +1 -0
  110. package/dist/extension/completion.d.mts +25 -0
  111. package/dist/extension/completion.d.mts.map +1 -0
  112. package/dist/extension/completion.mjs +40 -0
  113. package/dist/extension/completion.mjs.map +1 -0
  114. package/dist/extension/config.d.mts +55 -0
  115. package/dist/extension/config.d.mts.map +1 -0
  116. package/dist/extension/config.mjs +162 -0
  117. package/dist/extension/config.mjs.map +1 -0
  118. package/dist/extension/env.d.mts +42 -0
  119. package/dist/extension/env.d.mts.map +1 -0
  120. package/dist/extension/env.mjs +44 -0
  121. package/dist/extension/env.mjs.map +1 -0
  122. package/dist/extension/help.d.mts +29 -0
  123. package/dist/extension/help.d.mts.map +1 -0
  124. package/dist/extension/help.mjs +161 -0
  125. package/dist/extension/help.mjs.map +1 -0
  126. package/dist/extension/index.d.mts +18 -0
  127. package/dist/extension/ink.d.mts +31 -0
  128. package/dist/extension/ink.d.mts.map +1 -0
  129. package/dist/extension/ink.mjs +69 -0
  130. package/dist/extension/ink.mjs.map +1 -0
  131. package/dist/extension/interactive.d.mts +16 -0
  132. package/dist/extension/interactive.d.mts.map +1 -0
  133. package/dist/extension/interactive.mjs +89 -0
  134. package/dist/extension/interactive.mjs.map +1 -0
  135. package/dist/extension/logger.d.mts +67 -0
  136. package/dist/extension/logger.d.mts.map +1 -0
  137. package/dist/extension/logger.mjs +188 -0
  138. package/dist/extension/logger.mjs.map +1 -0
  139. package/dist/extension/man.d.mts +25 -0
  140. package/dist/extension/man.d.mts.map +1 -0
  141. package/dist/extension/man.mjs +41 -0
  142. package/dist/extension/man.mjs.map +1 -0
  143. package/dist/extension/mcp.d.mts +28 -0
  144. package/dist/extension/mcp.d.mts.map +1 -0
  145. package/dist/extension/mcp.mjs +44 -0
  146. package/dist/extension/mcp.mjs.map +1 -0
  147. package/dist/extension/progress-renderer.d.mts +13 -0
  148. package/dist/extension/progress-renderer.d.mts.map +1 -0
  149. package/dist/extension/progress-renderer.mjs +351 -0
  150. package/dist/extension/progress-renderer.mjs.map +1 -0
  151. package/dist/extension/progress.d.mts +76 -0
  152. package/dist/extension/progress.d.mts.map +1 -0
  153. package/dist/extension/progress.mjs +225 -0
  154. package/dist/extension/progress.mjs.map +1 -0
  155. package/dist/extension/repl.d.mts +26 -0
  156. package/dist/extension/repl.d.mts.map +1 -0
  157. package/dist/extension/repl.mjs +67 -0
  158. package/dist/extension/repl.mjs.map +1 -0
  159. package/dist/extension/serve.d.mts +27 -0
  160. package/dist/extension/serve.d.mts.map +1 -0
  161. package/dist/extension/serve.mjs +41 -0
  162. package/dist/extension/serve.mjs.map +1 -0
  163. package/dist/extension/signal.d.mts +19 -0
  164. package/dist/extension/signal.d.mts.map +1 -0
  165. package/dist/extension/signal.mjs +81 -0
  166. package/dist/extension/signal.mjs.map +1 -0
  167. package/dist/extension/stdin.d.mts +19 -0
  168. package/dist/extension/stdin.d.mts.map +1 -0
  169. package/dist/extension/stdin.mjs +52 -0
  170. package/dist/extension/stdin.mjs.map +1 -0
  171. package/dist/extension/suggestions.d.mts +6 -0
  172. package/dist/extension/suggestions.d.mts.map +1 -0
  173. package/dist/extension/suggestions.mjs +113 -0
  174. package/dist/extension/suggestions.mjs.map +1 -0
  175. package/dist/extension/timing.d.mts +27 -0
  176. package/dist/extension/timing.d.mts.map +1 -0
  177. package/dist/extension/timing.mjs +71 -0
  178. package/dist/extension/timing.mjs.map +1 -0
  179. package/dist/extension/tracing.d.mts +85 -0
  180. package/dist/extension/tracing.d.mts.map +1 -0
  181. package/dist/extension/tracing.mjs +107 -0
  182. package/dist/extension/tracing.mjs.map +1 -0
  183. package/dist/extension/update-check.d.mts +20 -0
  184. package/dist/extension/update-check.d.mts.map +1 -0
  185. package/dist/extension/update-check.mjs +62 -0
  186. package/dist/extension/update-check.mjs.map +1 -0
  187. package/dist/extension/utils.mjs +43 -0
  188. package/dist/extension/utils.mjs.map +1 -0
  189. package/dist/extension/version.d.mts +20 -0
  190. package/dist/extension/version.d.mts.map +1 -0
  191. package/dist/extension/version.mjs +51 -0
  192. package/dist/extension/version.mjs.map +1 -0
  193. package/dist/{completion-UnBKfGuk.mjs → feature/completion.mjs} +4 -3
  194. package/dist/feature/completion.mjs.map +1 -0
  195. package/dist/feature/interactive.mjs +145 -0
  196. package/dist/feature/interactive.mjs.map +1 -0
  197. package/dist/feature/mcp.d.mts +18 -0
  198. package/dist/feature/mcp.d.mts.map +1 -0
  199. package/dist/{mcp-D6PdtjIs.mjs → feature/mcp.mjs} +6 -6
  200. package/dist/feature/mcp.mjs.map +1 -0
  201. package/dist/feature/repl-loop.mjs +217 -0
  202. package/dist/feature/repl-loop.mjs.map +1 -0
  203. package/dist/feature/serve.d.mts +18 -0
  204. package/dist/feature/serve.d.mts.map +1 -0
  205. package/dist/{serve-PaCLsNoD.mjs → feature/serve.mjs} +7 -7
  206. package/dist/feature/serve.mjs.map +1 -0
  207. package/dist/feature/test.d.mts +109 -0
  208. package/dist/feature/test.d.mts.map +1 -0
  209. package/dist/feature/test.mjs +116 -0
  210. package/dist/feature/test.mjs.map +1 -0
  211. package/dist/feature/update-check.d.mts +35 -0
  212. package/dist/feature/update-check.d.mts.map +1 -0
  213. package/dist/{update-check-CZ2VqjnV.mjs → feature/update-check.mjs} +2 -2
  214. package/dist/feature/update-check.mjs.map +1 -0
  215. package/dist/feature/wrap.d.mts +58 -0
  216. package/dist/feature/wrap.d.mts.map +1 -0
  217. package/dist/feature/wrap.mjs +77 -0
  218. package/dist/feature/wrap.mjs.map +1 -0
  219. package/dist/index.d.mts +38 -901
  220. package/dist/index.mjs +25 -4337
  221. package/dist/ink.d.mts +2 -0
  222. package/dist/ink.mjs +2 -0
  223. package/dist/man.d.mts +2 -0
  224. package/dist/man.mjs +2 -0
  225. package/dist/mcp.d.mts +3 -0
  226. package/dist/mcp.mjs +2 -0
  227. package/dist/output/colorizer.d.mts +28 -0
  228. package/dist/output/colorizer.d.mts.map +1 -0
  229. package/dist/output/colorizer.mjs +94 -0
  230. package/dist/output/colorizer.mjs.map +1 -0
  231. package/dist/{formatter-CY3KrOEd.d.mts → output/formatter.d.mts} +2 -28
  232. package/dist/output/formatter.d.mts.map +1 -0
  233. package/dist/output/formatter.mjs +360 -0
  234. package/dist/output/formatter.mjs.map +1 -0
  235. package/dist/output/help.d.mts +18 -0
  236. package/dist/output/help.d.mts.map +1 -0
  237. package/dist/output/help.mjs +267 -0
  238. package/dist/output/help.mjs.map +1 -0
  239. package/dist/output/output-indicator.d.mts +27 -0
  240. package/dist/output/output-indicator.d.mts.map +1 -0
  241. package/dist/output/output-indicator.mjs +54 -0
  242. package/dist/output/output-indicator.mjs.map +1 -0
  243. package/dist/output/primitives.d.mts +33 -0
  244. package/dist/output/primitives.d.mts.map +1 -0
  245. package/dist/output/primitives.mjs +206 -0
  246. package/dist/output/primitives.mjs.map +1 -0
  247. package/dist/output/styling.d.mts +38 -0
  248. package/dist/output/styling.d.mts.map +1 -0
  249. package/dist/output/styling.mjs +146 -0
  250. package/dist/output/styling.mjs.map +1 -0
  251. package/dist/schema/zod.d.mts +6 -0
  252. package/dist/schema/zod.d.mts.map +1 -0
  253. package/dist/schema/zod.mjs +50 -0
  254. package/dist/schema/zod.mjs.map +1 -0
  255. package/dist/serve.d.mts +2 -0
  256. package/dist/serve.mjs +2 -0
  257. package/dist/test.d.mts +2 -109
  258. package/dist/test.mjs +1 -115
  259. package/dist/tracing.d.mts +2 -0
  260. package/dist/tracing.mjs +2 -0
  261. package/dist/types/args-meta.d.mts +129 -0
  262. package/dist/types/args-meta.d.mts.map +1 -0
  263. package/dist/types/builder.d.mts +212 -0
  264. package/dist/types/builder.d.mts.map +1 -0
  265. package/dist/types/command.d.mts +112 -0
  266. package/dist/types/command.d.mts.map +1 -0
  267. package/dist/types/index.d.mts +8 -0
  268. package/dist/types/interceptor.d.mts +232 -0
  269. package/dist/types/interceptor.d.mts.map +1 -0
  270. package/dist/types/preferences.d.mts +79 -0
  271. package/dist/types/preferences.d.mts.map +1 -0
  272. package/dist/types/result.d.mts +61 -0
  273. package/dist/types/result.d.mts.map +1 -0
  274. package/dist/types/schema.d.mts +24 -0
  275. package/dist/types/schema.d.mts.map +1 -0
  276. package/dist/util/dotenv.mjs +174 -0
  277. package/dist/util/dotenv.mjs.map +1 -0
  278. package/dist/util/shell-utils.mjs +80 -0
  279. package/dist/util/shell-utils.mjs.map +1 -0
  280. package/dist/util/stream.d.mts +33 -0
  281. package/dist/util/stream.d.mts.map +1 -0
  282. package/dist/{stream-DC4H8YTx.mjs → util/stream.mjs} +2 -2
  283. package/dist/util/stream.mjs.map +1 -0
  284. package/dist/util/type-helpers.d.mts +74 -0
  285. package/dist/util/type-helpers.d.mts.map +1 -0
  286. package/dist/util/type-utils.d.mts +186 -0
  287. package/dist/util/type-utils.d.mts.map +1 -0
  288. package/dist/util/utils.mjs +43 -0
  289. package/dist/util/utils.mjs.map +1 -0
  290. package/dist/zod.d.mts +1 -32
  291. package/dist/zod.mjs +1 -49
  292. package/package.json +65 -17
  293. package/src/completion.ts +2 -0
  294. package/src/core/args.ts +63 -37
  295. package/src/core/runtime.ts +11 -2
  296. package/src/extension/completion.ts +3 -0
  297. package/src/extension/index.ts +0 -12
  298. package/src/extension/ink.ts +2 -1
  299. package/src/extension/man.ts +3 -0
  300. package/src/extension/mcp.ts +3 -0
  301. package/src/extension/progress-renderer.ts +32 -8
  302. package/src/extension/progress.ts +19 -9
  303. package/src/extension/serve.ts +3 -0
  304. package/src/extension/tracing.ts +2 -0
  305. package/src/index.ts +1 -20
  306. package/src/ink.ts +2 -0
  307. package/src/man.ts +2 -0
  308. package/src/mcp.ts +3 -0
  309. package/src/serve.ts +2 -0
  310. package/src/tracing.ts +9 -0
  311. package/src/types/builder.ts +2 -2
  312. package/src/zod.ts +1 -1
  313. package/dist/args-DrCXxXeP.mjs.map +0 -1
  314. package/dist/codegen/index.d.mts.map +0 -1
  315. package/dist/codegen/index.mjs.map +0 -1
  316. package/dist/commands-DLR0rFgq.mjs.map +0 -1
  317. package/dist/completion-UnBKfGuk.mjs.map +0 -1
  318. package/dist/errors-DA4KzK1M.mjs.map +0 -1
  319. package/dist/formatter-CY3KrOEd.d.mts.map +0 -1
  320. package/dist/help-B-ZMYyn-.mjs +0 -892
  321. package/dist/help-B-ZMYyn-.mjs.map +0 -1
  322. package/dist/index-D-Dpz7l_.d.mts +0 -1427
  323. package/dist/index-D-Dpz7l_.d.mts.map +0 -1
  324. package/dist/index.d.mts.map +0 -1
  325. package/dist/index.mjs.map +0 -1
  326. package/dist/mcp-D6PdtjIs.mjs.map +0 -1
  327. package/dist/serve-PaCLsNoD.mjs.map +0 -1
  328. package/dist/stream-DC4H8YTx.mjs.map +0 -1
  329. package/dist/test.d.mts.map +0 -1
  330. package/dist/test.mjs.map +0 -1
  331. package/dist/update-check-CZ2VqjnV.mjs.map +0 -1
  332. package/dist/zod.d.mts.map +0 -1
  333. package/dist/zod.mjs.map +0 -1
@@ -1,892 +0,0 @@
1
- import { o as findCommandByName } from "./commands-DLR0rFgq.mjs";
2
- import { a as getJsonSchema, c as parsePositionalConfig, i as extractSchemaMetadata, u as camelToKebab } from "./args-DrCXxXeP.mjs";
3
- //#region src/output/colorizer.ts
4
- const ansiCodes = {
5
- reset: "\x1B[0m",
6
- bold: "\x1B[1m",
7
- dim: "\x1B[2m",
8
- italic: "\x1B[3m",
9
- underline: "\x1B[4m",
10
- strikethrough: "\x1B[9m",
11
- red: "\x1B[31m",
12
- green: "\x1B[32m",
13
- yellow: "\x1B[33m",
14
- blue: "\x1B[34m",
15
- magenta: "\x1B[35m",
16
- cyan: "\x1B[36m",
17
- white: "\x1B[37m",
18
- gray: "\x1B[90m"
19
- };
20
- const defaultTheme = {
21
- command: ["cyan", "bold"],
22
- arg: ["green"],
23
- type: ["yellow"],
24
- description: ["dim"],
25
- label: ["bold"],
26
- meta: ["gray"],
27
- example: ["underline"],
28
- exampleValue: ["italic"],
29
- deprecated: ["strikethrough", "gray"]
30
- };
31
- const colorThemes = {
32
- default: defaultTheme,
33
- ocean: {
34
- command: ["blue", "bold"],
35
- arg: ["cyan"],
36
- type: ["green"],
37
- description: ["dim"],
38
- label: ["bold"],
39
- meta: ["gray"],
40
- example: ["underline", "cyan"],
41
- exampleValue: ["italic"],
42
- deprecated: ["strikethrough", "gray"]
43
- },
44
- warm: {
45
- command: ["yellow", "bold"],
46
- arg: ["red"],
47
- type: ["magenta"],
48
- description: ["dim"],
49
- label: ["bold"],
50
- meta: ["gray"],
51
- example: ["underline", "yellow"],
52
- exampleValue: ["italic"],
53
- deprecated: ["strikethrough", "gray"]
54
- },
55
- monochrome: {
56
- command: ["bold"],
57
- arg: ["underline"],
58
- type: ["dim"],
59
- description: ["dim"],
60
- label: ["bold"],
61
- meta: ["dim"],
62
- example: ["underline"],
63
- exampleValue: ["italic"],
64
- deprecated: ["strikethrough", "dim"]
65
- }
66
- };
67
- function makeStyleFn(styles) {
68
- const prefix = styles.map((s) => ansiCodes[s]).join("");
69
- return (text) => `${prefix}${text}${ansiCodes.reset}`;
70
- }
71
- function resolveConfig(config) {
72
- if (!config) return defaultTheme;
73
- if (typeof config === "string") return colorThemes[config] ?? defaultTheme;
74
- return {
75
- ...defaultTheme,
76
- ...config
77
- };
78
- }
79
- function createColorizer(config) {
80
- const resolved = resolveConfig(config);
81
- return {
82
- command: makeStyleFn(resolved.command),
83
- arg: makeStyleFn(resolved.arg),
84
- type: makeStyleFn(resolved.type),
85
- description: makeStyleFn(resolved.description),
86
- label: makeStyleFn(resolved.label),
87
- meta: makeStyleFn(resolved.meta),
88
- example: makeStyleFn(resolved.example),
89
- exampleValue: makeStyleFn(resolved.exampleValue),
90
- deprecated: makeStyleFn(resolved.deprecated)
91
- };
92
- }
93
- function wrapText(text, maxWidth) {
94
- if (maxWidth <= 0 || text.length <= maxWidth) return [text];
95
- const words = text.split(" ");
96
- const lines = [];
97
- let current = "";
98
- for (const word of words) if (current && current.length + 1 + word.length > maxWidth) {
99
- lines.push(current);
100
- current = word;
101
- } else current = current ? `${current} ${word}` : word;
102
- if (current) lines.push(current);
103
- return lines.length > 0 ? lines : [text];
104
- }
105
- function escapeHtml(text) {
106
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
107
- }
108
- function createTextStyler() {
109
- return {
110
- command: (text) => text,
111
- arg: (text) => text,
112
- type: (text) => text,
113
- description: (text) => text,
114
- label: (text) => text,
115
- section: (text) => text,
116
- meta: (text) => text,
117
- example: (text) => text,
118
- exampleValue: (text) => text,
119
- deprecated: (text) => text
120
- };
121
- }
122
- function createAnsiStyler(theme) {
123
- const colorizer = createColorizer(theme);
124
- return {
125
- command: colorizer.command,
126
- arg: colorizer.arg,
127
- type: colorizer.type,
128
- description: colorizer.description,
129
- label: colorizer.label,
130
- section: colorizer.label,
131
- meta: colorizer.meta,
132
- example: colorizer.example,
133
- exampleValue: colorizer.exampleValue,
134
- deprecated: colorizer.deprecated
135
- };
136
- }
137
- function createConsoleStyler(theme) {
138
- return createAnsiStyler(theme);
139
- }
140
- function createMarkdownStyler() {
141
- return {
142
- command: (text) => `**${text}**`,
143
- arg: (text) => `\`${text}\``,
144
- type: (text) => `\`${text}\``,
145
- description: (text) => text,
146
- label: (text) => `**${text}**`,
147
- section: (text) => `### ${text}`,
148
- meta: (text) => `*${text}*`,
149
- example: (text) => `**${text}**`,
150
- exampleValue: (text) => `\`${text}\``,
151
- deprecated: (text) => `~~${text}~~`
152
- };
153
- }
154
- function createHtmlStyler() {
155
- return {
156
- command: (text) => `<strong style="color: #00bcd4;">${escapeHtml(text)}</strong>`,
157
- arg: (text) => `<code style="color: #4caf50;">${escapeHtml(text)}</code>`,
158
- type: (text) => `<code style="color: #ff9800;">${escapeHtml(text)}</code>`,
159
- description: (text) => `<span style="color: #666;">${escapeHtml(text)}</span>`,
160
- label: (text) => `<strong>${escapeHtml(text)}</strong>`,
161
- section: (text) => `<h3>${escapeHtml(text)}</h3>`,
162
- meta: (text) => `<span style="color: #999;">${escapeHtml(text)}</span>`,
163
- example: (text) => `<strong style="text-decoration: underline;">${escapeHtml(text)}</strong>`,
164
- exampleValue: (text) => `<em>${escapeHtml(text)}</em>`,
165
- deprecated: (text) => `<del style="color: #999;">${escapeHtml(text)}</del>`
166
- };
167
- }
168
- function createTextLayout() {
169
- return {
170
- newline: "\n",
171
- indent: (level) => " ".repeat(level),
172
- join: (parts) => parts.filter(Boolean).join(" ")
173
- };
174
- }
175
- function createMarkdownLayout() {
176
- return {
177
- newline: "\n\n",
178
- indent: (level) => {
179
- if (level === 0) return "";
180
- if (level === 1) return " ";
181
- return " ";
182
- },
183
- join: (parts) => parts.filter(Boolean).join(" ")
184
- };
185
- }
186
- function createHtmlLayout() {
187
- return {
188
- newline: "<br>",
189
- indent: (level) => "&nbsp;&nbsp;".repeat(level),
190
- join: (parts) => parts.filter(Boolean).join(" "),
191
- wrapDocument: (content) => `<div style="font-family: monospace; line-height: 1.6;">${content}</div>`
192
- };
193
- }
194
- function shouldUseAnsi(env, isTTY) {
195
- if (env?.NO_COLOR) return false;
196
- if (env?.CI) return false;
197
- if (typeof isTTY === "boolean") return isTTY;
198
- return false;
199
- }
200
- /** Resolve the output format from the runtime and caller context. */
201
- function resolveOutputFormat(runtime, caller) {
202
- let format;
203
- if (caller === "serve" || caller === "mcp" || caller === "tool") format = "json";
204
- else if (runtime.format && runtime.format !== "auto" && runtime.format !== "console") format = runtime.format;
205
- else format = shouldUseAnsi(runtime.env(), runtime.terminal?.isTTY) ? "ansi" : "text";
206
- const terminalWidth = format === "markdown" || format === "html" ? void 0 : runtime.terminal?.columns ?? 80;
207
- let styler;
208
- let layout;
209
- switch (format) {
210
- case "ansi":
211
- styler = createAnsiStyler(runtime.theme);
212
- layout = createTextLayout();
213
- break;
214
- case "markdown":
215
- styler = createMarkdownStyler();
216
- layout = createMarkdownLayout();
217
- break;
218
- case "html":
219
- styler = createHtmlStyler();
220
- layout = createHtmlLayout();
221
- break;
222
- default:
223
- styler = createTextStyler();
224
- layout = createTextLayout();
225
- break;
226
- }
227
- return {
228
- format,
229
- styler,
230
- layout,
231
- terminalWidth
232
- };
233
- }
234
- //#endregion
235
- //#region src/util/utils.ts
236
- function getRootCommand(cmd) {
237
- let current = cmd;
238
- while (current.parent) current = current.parent;
239
- return current;
240
- }
241
- async function readVersionFromPackageJson() {
242
- try {
243
- const fs = await import("node:fs");
244
- const path = await import("node:path");
245
- let dir = process.cwd();
246
- for (let i = 0; i < 10; i++) {
247
- const pkgPath = path.join(dir, "package.json");
248
- if (fs.existsSync(pkgPath)) {
249
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
250
- if (pkg.version) return pkg.version;
251
- }
252
- const parentDir = path.dirname(dir);
253
- if (parentDir === dir) break;
254
- dir = parentDir;
255
- }
256
- } catch {}
257
- return "0.0.0";
258
- }
259
- /**
260
- * Attempts to get the version from various sources:
261
- * 1. Explicit version set on the command
262
- * 2. npm_package_version environment variable (set by npm/yarn/pnpm when running scripts)
263
- * 3. package.json in current or parent directories
264
- *
265
- * Returns synchronously when an explicit version or env var is available.
266
- * Falls back to async package.json discovery otherwise.
267
- */
268
- function getVersion(explicitVersion) {
269
- if (explicitVersion) return explicitVersion;
270
- if (typeof process !== "undefined" && process.env?.npm_package_version) return process.env.npm_package_version;
271
- if (typeof process !== "undefined") return readVersionFromPackageJson();
272
- return "0.0.0";
273
- }
274
- //#endregion
275
- //#region src/output/formatter.ts
276
- /**
277
- * Creates a formatter that uses the given styler and layout configuration.
278
- */
279
- function createGenericFormatter(styler, layout, showAllBuiltins, terminalWidth) {
280
- const { newline, indent, join, wrapDocument } = layout;
281
- function formatUsageSection(info) {
282
- const usageParts = [styler.command(info.usage.command), info.usage.hasSubcommands ? styler.meta("[command]") : ""];
283
- if (info.positionals && info.positionals.length > 0) for (const arg of info.positionals) {
284
- const name = arg.name.startsWith("...") ? `${arg.name}` : arg.name;
285
- usageParts.push(styler.meta(arg.optional ? `[${name}]` : `<${name}>`));
286
- }
287
- if (info.usage.hasArguments) usageParts.push(styler.meta("[options]"));
288
- return [`${styler.label("Usage:")} ${join(usageParts)}`];
289
- }
290
- function formatSubcommandsSection(info) {
291
- const lines = [];
292
- const subcommands = info.subcommands;
293
- const subcommandSuffix = (c) => c.hasSubcommands ? " <subcommand>" : "";
294
- const formatAliasParts = (c) => {
295
- if (!c.aliases?.length) return {
296
- plain: "",
297
- styled: ""
298
- };
299
- const realAliases = c.aliases.filter((a) => a !== "[default]");
300
- const hasDefault = c.aliases.some((a) => a === "[default]");
301
- const parts = [];
302
- const styledParts = [];
303
- if (realAliases.length) {
304
- parts.push(`(${realAliases.join(", ")})`);
305
- styledParts.push(`(${realAliases.join(", ")})`);
306
- }
307
- if (hasDefault) {
308
- parts.push("[default]");
309
- styledParts.push(styler.meta("[default]"));
310
- }
311
- return {
312
- plain: parts.length ? ` ${parts.join(" ")}` : "",
313
- styled: styledParts.length ? ` ${styledParts.join(" ")}` : ""
314
- };
315
- };
316
- const maxNameLength = Math.max(...subcommands.map((c) => {
317
- return (c.name + subcommandSuffix(c) + formatAliasParts(c).plain).length;
318
- }));
319
- const grouped = Object.groupBy(subcommands, (c) => c.group ?? "");
320
- const renderSubcommands = (cmds) => {
321
- for (const subCmd of cmds) {
322
- const aliasParts = formatAliasParts(subCmd);
323
- const suffix = subcommandSuffix(subCmd);
324
- const commandDisplay = subCmd.name + suffix + aliasParts.plain;
325
- const padding = " ".repeat(Math.max(0, maxNameLength - commandDisplay.length + 2));
326
- const isDeprecated = !!subCmd.deprecated;
327
- const isDefaultEntry = subCmd.name === "[default]";
328
- const lineParts = [isDeprecated ? styler.deprecated(commandDisplay) : (isDefaultEntry ? styler.meta(subCmd.name) : styler.command(subCmd.name)) + (suffix ? styler.meta(suffix) : "") + aliasParts.styled, padding];
329
- const displayText = subCmd.title ?? subCmd.description;
330
- if (displayText) lineParts.push(isDeprecated ? styler.deprecated(displayText) : styler.description(displayText));
331
- if (isDeprecated) {
332
- const deprecatedMeta = typeof subCmd.deprecated === "string" ? styler.meta(` (deprecated: ${subCmd.deprecated})`) : styler.meta(" (deprecated)");
333
- lineParts.push(deprecatedMeta);
334
- }
335
- lines.push(indent(1) + lineParts.join(""));
336
- }
337
- };
338
- for (const [key, items] of Object.entries(grouped)) {
339
- if (lines.length > 0) lines.push("");
340
- lines.push(styler.section(key ? `${key}:` : "Commands:"));
341
- renderSubcommands(items);
342
- }
343
- if (!info.builtins?.length) {
344
- lines.push("");
345
- lines.push(styler.meta(`Run "${info.name} [command] --help" for more information on a command.`));
346
- }
347
- return lines;
348
- }
349
- function formatPositionalsSection(info) {
350
- const lines = [];
351
- const args = info.positionals;
352
- lines.push(styler.section("Arguments:"));
353
- const maxNameLength = Math.min(32, Math.max(...args.map((a) => a.name.length)));
354
- const descCol = 2 + maxNameLength + 2;
355
- const posAvailWidth = terminalWidth ? terminalWidth - descCol : void 0;
356
- const descColPad = " ".repeat(descCol);
357
- for (const arg of args) {
358
- const padding = " ".repeat(Math.max(2, maxNameLength - arg.name.length + 2));
359
- const prefix = indent(1) + styler.arg(arg.name) + padding;
360
- const descPlain = arg.description ?? "";
361
- const styledDesc = descPlain ? styler.description(descPlain) : "";
362
- const metaParts = [];
363
- const styledMetaParts = [];
364
- if (info.usage.stdinField === arg.name) {
365
- metaParts.push("(stdin)");
366
- styledMetaParts.push(styler.meta("(stdin)"));
367
- }
368
- if (arg.enum) {
369
- const text = `(choices: ${arg.enum.join(", ")})`;
370
- metaParts.push(text);
371
- styledMetaParts.push(styler.meta(text));
372
- }
373
- if (arg.default !== void 0) {
374
- const text = `(default: ${String(arg.default)})`;
375
- metaParts.push(text);
376
- styledMetaParts.push(styler.meta(text));
377
- }
378
- const metaStyled = join(styledMetaParts);
379
- if (posAvailWidth && posAvailWidth > 0) if ([descPlain, metaParts.join(" ")].filter(Boolean).join(" ").length <= posAvailWidth) lines.push(prefix + [styledDesc, metaStyled].filter(Boolean).join(" "));
380
- else if (!descPlain || descPlain.length <= posAvailWidth) {
381
- lines.push(prefix + styledDesc);
382
- if (metaStyled) lines.push(descColPad + metaStyled);
383
- } else {
384
- const wrapped = wrapText(descPlain, posAvailWidth);
385
- lines.push(prefix + styler.description(wrapped[0]));
386
- for (const wline of wrapped.slice(1)) lines.push(descColPad + styler.description(wline));
387
- if (metaStyled) lines.push(descColPad + metaStyled);
388
- }
389
- else lines.push(prefix + join([styledDesc, metaStyled]));
390
- }
391
- return lines;
392
- }
393
- function formatArgumentsSection(info) {
394
- const lines = [];
395
- const argList = info.arguments || [];
396
- const hasDefault = (value) => {
397
- if (value === void 0) return false;
398
- if (value === "") return false;
399
- if (Array.isArray(value) && value.length === 0) return false;
400
- return true;
401
- };
402
- const argColumns = argList.map((arg) => {
403
- const kebab = camelToKebab(arg.name);
404
- const primaryName = kebab && arg.aliases?.includes(kebab) ? kebab : arg.name;
405
- const remainingAliases = arg.aliases?.filter((a) => a !== primaryName);
406
- const flagsPlain = arg.flags?.length ? arg.flags.map((f) => `-${f}`).join(", ") : "";
407
- const negPlain = arg.negative?.length ? arg.negative.map((n) => `--${n}`).join(", ") : "";
408
- return {
409
- flagsPlain,
410
- namesPlain: [
411
- `--${primaryName}`,
412
- ...remainingAliases?.map((a) => `--${a}`) || [],
413
- ...negPlain ? [negPlain] : []
414
- ].join(", "),
415
- typePlain: arg.type && arg.type !== "boolean" ? arg.optional ? `[${arg.type}]` : `<${arg.type}>` : "",
416
- isDeprecated: !!arg.deprecated,
417
- arg
418
- };
419
- });
420
- const maxFlagsWidth = Math.min(12, Math.max(0, ...argColumns.map((c) => c.flagsPlain.length)));
421
- const maxNamesWidth = Math.min(32, Math.max(0, ...argColumns.map((c) => c.namesPlain.length)));
422
- const maxTypeWidth = Math.min(16, Math.max(0, ...argColumns.map((c) => c.typePlain.length)));
423
- const hasAnyFlags = maxFlagsWidth > 0;
424
- const descCol = 2 + (hasAnyFlags ? maxFlagsWidth + 2 : 0) + maxNamesWidth + 2 + (maxTypeWidth > 0 ? maxTypeWidth + 2 : 0);
425
- const argAvailWidth = terminalWidth ? terminalWidth - descCol : void 0;
426
- const descColPad = " ".repeat(descCol);
427
- const grouped = Object.groupBy(argColumns, (c) => c.arg.group ?? "");
428
- const renderArgColumns = (columns) => {
429
- for (const { flagsPlain, namesPlain, typePlain, isDeprecated, arg } of columns) {
430
- const parts = [];
431
- if (hasAnyFlags) {
432
- const styledFlags = isDeprecated ? flagsPlain ? styler.deprecated(flagsPlain) : "" : flagsPlain ? styler.arg(flagsPlain) : "";
433
- const flagsPadding = " ".repeat(Math.max(0, maxFlagsWidth - flagsPlain.length));
434
- const separator = flagsPlain ? ", " : " ";
435
- parts.push(styledFlags + flagsPadding + separator);
436
- }
437
- const styledNames = isDeprecated ? styler.deprecated(namesPlain) : styler.arg(namesPlain);
438
- const namesPadding = " ".repeat(Math.max(2, maxNamesWidth - namesPlain.length + 2));
439
- parts.push(styledNames + namesPadding);
440
- if (maxTypeWidth > 0) {
441
- const styledType = typePlain ? styler.type(typePlain) : "";
442
- const typePadding = " ".repeat(Math.max(2, maxTypeWidth - typePlain.length + 2));
443
- parts.push(styledType + typePadding);
444
- }
445
- const prefix = indent(1) + parts.join("");
446
- const contPad = argAvailWidth ? descColPad : indent(3);
447
- const inlineMeta = [];
448
- const styledInlineMeta = [];
449
- if (isDeprecated && typeof arg.deprecated !== "string") {
450
- inlineMeta.push("(deprecated)");
451
- styledInlineMeta.push(styler.meta("(deprecated)"));
452
- }
453
- if (hasDefault(arg.default)) {
454
- const text = `(default: ${String(arg.default)})`;
455
- inlineMeta.push(text);
456
- styledInlineMeta.push(styler.meta(text));
457
- }
458
- if (arg.enum) {
459
- const text = `(choices: ${arg.enum.join(", ")})`;
460
- inlineMeta.push(text);
461
- styledInlineMeta.push(styler.meta(text));
462
- }
463
- const descPlain = arg.description ?? "";
464
- const styledDesc = descPlain ? isDeprecated ? styler.deprecated(descPlain) : styler.description(descPlain) : "";
465
- const metaStyled = join(styledInlineMeta);
466
- if (argAvailWidth && argAvailWidth > 0) if ([descPlain, inlineMeta.join(" ")].filter(Boolean).join(" ").length <= argAvailWidth) lines.push(prefix + [styledDesc, metaStyled].filter(Boolean).join(" "));
467
- else if (!descPlain || descPlain.length <= argAvailWidth) {
468
- lines.push(prefix + styledDesc);
469
- if (metaStyled) lines.push(descColPad + metaStyled);
470
- } else {
471
- const wrapped = wrapText(descPlain, argAvailWidth);
472
- const styleFn = isDeprecated ? styler.deprecated : styler.description;
473
- lines.push(prefix + styleFn(wrapped[0]));
474
- for (const wline of wrapped.slice(1)) lines.push(descColPad + styleFn(wline));
475
- if (metaStyled) lines.push(descColPad + metaStyled);
476
- }
477
- else {
478
- const descParts = [];
479
- if (styledDesc) descParts.push(styledDesc);
480
- lines.push(prefix + join(descParts));
481
- if (styledInlineMeta.length > 0) lines.push(indent(3) + metaStyled);
482
- }
483
- const line3Parts = [];
484
- if (isDeprecated && typeof arg.deprecated === "string") line3Parts.push(styler.meta(`(deprecated: ${arg.deprecated})`));
485
- if (arg.examples && arg.examples.length > 0) {
486
- const exampleValues = arg.examples.map((example) => typeof example === "string" ? example : JSON.stringify(example)).join(", ");
487
- line3Parts.push(styler.example("Example:"), styler.exampleValue(exampleValues));
488
- }
489
- if (line3Parts.length > 0) lines.push(contPad + join(line3Parts));
490
- const line4Parts = [];
491
- if (info.usage.stdinField === arg.name) line4Parts.push(styler.meta("(stdin)"));
492
- if (arg.env) {
493
- const envVars = typeof arg.env === "string" ? [arg.env] : arg.env;
494
- line4Parts.push(styler.example("Env:"), styler.exampleValue(envVars.join(", ")));
495
- }
496
- if (arg.configKey) line4Parts.push(styler.example("Config:"), styler.exampleValue(arg.configKey));
497
- if (line4Parts.length > 0) lines.push(contPad + join(line4Parts));
498
- }
499
- };
500
- for (const [key, items] of Object.entries(grouped)) {
501
- if (lines.length > 0) lines.push("");
502
- lines.push(styler.section(key ? `${key}:` : "Options:"));
503
- renderArgColumns(items);
504
- }
505
- return lines;
506
- }
507
- function formatBuiltinsSection(info) {
508
- const lines = [];
509
- const builtins = info.builtins;
510
- if (!showAllBuiltins) {
511
- lines.push(`${styler.label("Global:")} ${styler.meta([
512
- "help [command]",
513
- "version",
514
- "[command] --repl"
515
- ].join(", "))}`);
516
- const hint = info.usage.hasSubcommands ? `Run "${info.name} [command] --help" for more information. Use "--all" for all global commands.` : `Use "${info.name} help --all" for more information on global commands.`;
517
- lines.push(styler.meta(hint));
518
- return lines;
519
- }
520
- lines.push(styler.section("Global:"));
521
- const allLengths = [];
522
- for (const entry of builtins) {
523
- allLengths.push(entry.name.length);
524
- if (entry.sub) for (const sub of entry.sub) allLengths.push(sub.name.length + 2);
525
- }
526
- const maxLen = Math.max(...allLengths);
527
- for (const entry of builtins) {
528
- const padding = " ".repeat(Math.max(2, maxLen - entry.name.length + 2));
529
- const parts = [styler.command(entry.name)];
530
- if (entry.description) parts.push(padding + styler.description(entry.description));
531
- lines.push(indent(1) + parts.join(""));
532
- if (entry.sub) for (const sub of entry.sub) {
533
- const subPadding = " ".repeat(Math.max(2, maxLen - sub.name.length));
534
- const subParts = [styler.arg(sub.name)];
535
- if (sub.description) subParts.push(subPadding + styler.description(sub.description));
536
- lines.push(indent(2) + subParts.join(""));
537
- }
538
- }
539
- return lines;
540
- }
541
- return { format(info) {
542
- const lines = [];
543
- if (info.deprecated) {
544
- const deprecationMessage = typeof info.deprecated === "string" ? `⚠️ This command is deprecated: ${info.deprecated}` : "⚠️ This command is deprecated";
545
- lines.push(styler.deprecated(deprecationMessage));
546
- lines.push("");
547
- }
548
- lines.push(...formatUsageSection(info));
549
- lines.push("");
550
- if (info.title) {
551
- lines.push(styler.label(info.title));
552
- lines.push("");
553
- }
554
- if (info.aliases && info.aliases.length > 0) {
555
- lines.push(styler.meta(`Aliases: ${info.aliases.join(", ")}`));
556
- lines.push("");
557
- }
558
- if (info.description) {
559
- lines.push(styler.description(info.description));
560
- lines.push("");
561
- }
562
- if (info.examples && info.examples.length > 0) {
563
- lines.push(styler.section("Examples:"));
564
- for (const ex of info.examples) lines.push(indent(1) + styler.meta("$ ") + styler.exampleValue(ex));
565
- lines.push("");
566
- }
567
- if (info.subcommands && info.subcommands.length > 0) {
568
- lines.push(...formatSubcommandsSection(info));
569
- lines.push("");
570
- }
571
- if (info.positionals && info.positionals.length > 0) {
572
- lines.push(...formatPositionalsSection(info));
573
- lines.push("");
574
- }
575
- if (info.arguments && info.arguments.length > 0) {
576
- lines.push(...formatArgumentsSection(info));
577
- lines.push("");
578
- }
579
- if (info.builtins && info.builtins.length > 0) {
580
- lines.push(...formatBuiltinsSection(info));
581
- lines.push("");
582
- }
583
- if (info.arguments?.some((arg) => arg.negatable && arg.default === true)) {
584
- lines.push(styler.meta("Boolean options can be negated with --no-<option>."));
585
- lines.push("");
586
- }
587
- if (info.nestedCommands?.length) {
588
- lines.push(styler.section("Subcommand Details:"));
589
- lines.push("");
590
- for (const nestedCmd of info.nestedCommands) {
591
- lines.push(styler.meta("─".repeat(60)));
592
- lines.push(this.format(nestedCmd));
593
- }
594
- }
595
- const result = lines.join(newline);
596
- return wrapDocument ? wrapDocument(result) : result;
597
- } };
598
- }
599
- function createJsonFormatter() {
600
- return { format(info) {
601
- return JSON.stringify(info, null, 2);
602
- } };
603
- }
604
- /**
605
- * Creates a minimal formatter that outputs just a single-line usage string.
606
- */
607
- function createMinimalFormatter() {
608
- return { format(info) {
609
- const parts = [info.usage.command];
610
- if (info.usage.hasSubcommands) parts.push("[command]");
611
- if (info.positionals && info.positionals.length > 0) for (const arg of info.positionals) {
612
- const name = arg.name.startsWith("...") ? `${arg.name}` : arg.name;
613
- parts.push(arg.optional ? `[${name}]` : `<${name}>`);
614
- }
615
- if (info.usage.hasArguments) parts.push("[options]");
616
- return parts.join(" ");
617
- } };
618
- }
619
- function createFormatter(format, detail = "standard", theme, all, width, terminal, env) {
620
- if (detail === "minimal") return createMinimalFormatter();
621
- if (format === "json") return createJsonFormatter();
622
- const tw = format === "markdown" || format === "html" ? void 0 : width ?? terminal?.columns ?? 80;
623
- if (format === "ansi" || format === "auto" && shouldUseAnsi(env, terminal?.isTTY)) return createGenericFormatter(createAnsiStyler(theme), createTextLayout(), all, tw);
624
- if (format === "console") return createGenericFormatter(createConsoleStyler(theme), createTextLayout(), all, tw);
625
- if (format === "markdown") return createGenericFormatter(createMarkdownStyler(), createMarkdownLayout(), all);
626
- if (format === "html") return createGenericFormatter(createHtmlStyler(), createHtmlLayout(), all);
627
- return createGenericFormatter(createTextStyler(), createTextLayout(), all, tw);
628
- }
629
- //#endregion
630
- //#region src/output/help.ts
631
- /**
632
- * Extract positional arguments info from schema based on meta.positional config.
633
- */
634
- function extractPositionalArgsInfo(schema, meta) {
635
- const args = [];
636
- const positionalNames = /* @__PURE__ */ new Set();
637
- if (!schema || !meta?.positional || meta.positional.length === 0) return {
638
- args,
639
- positionalNames
640
- };
641
- const positionalConfig = parsePositionalConfig(meta.positional);
642
- try {
643
- const jsonSchema = getJsonSchema(schema);
644
- if (jsonSchema.type === "object" && jsonSchema.properties) {
645
- const properties = jsonSchema.properties;
646
- const required = jsonSchema.required || [];
647
- for (const { name, variadic } of positionalConfig) {
648
- const prop = properties[name];
649
- if (!prop) continue;
650
- positionalNames.add(name);
651
- const optMeta = meta.fields?.[name];
652
- args.push({
653
- name: variadic ? `...${name}` : name,
654
- description: optMeta?.description ?? prop.description,
655
- optional: !required.includes(name),
656
- default: prop.default,
657
- type: variadic ? `array<${prop.items?.type || "string"}>` : prop.type,
658
- enum: prop.enum ?? prop.items?.enum
659
- });
660
- }
661
- }
662
- } catch {}
663
- return {
664
- args,
665
- positionalNames
666
- };
667
- }
668
- function extractArgsInfo(schema, meta, positionalNames) {
669
- const result = [];
670
- if (!schema) return result;
671
- if (!schema["~standard"].vendor.includes("zod")) return result;
672
- const argsMeta = meta?.fields;
673
- try {
674
- const jsonSchema = getJsonSchema(schema);
675
- if (jsonSchema.type === "object" && jsonSchema.properties) {
676
- const properties = jsonSchema.properties;
677
- const required = jsonSchema.required || [];
678
- const propertyNames = new Set(Object.keys(properties));
679
- const hasExplicitNegation = (key) => {
680
- const camelNegated = `no${key.charAt(0).toUpperCase()}${key.slice(1)}`;
681
- if (propertyNames.has(camelNegated)) return true;
682
- const kebabNegated = `no-${key}`;
683
- if (propertyNames.has(kebabNegated)) return true;
684
- return false;
685
- };
686
- const isNegationOf = (key) => {
687
- if (key.startsWith("no") && key.length > 2 && key[2] === key[2]?.toUpperCase()) {
688
- const positiveKey = key.charAt(2).toLowerCase() + key.slice(3);
689
- if (propertyNames.has(positiveKey)) return true;
690
- }
691
- if (key.startsWith("no-")) {
692
- const positiveKey = key.slice(3);
693
- if (propertyNames.has(positiveKey)) return true;
694
- }
695
- return false;
696
- };
697
- for (const [key, prop] of Object.entries(properties)) {
698
- if (positionalNames?.has(key)) continue;
699
- const isOptional = !required.includes(key);
700
- const enumValues = prop.enum ?? prop.items?.enum;
701
- const optMeta = argsMeta?.[key];
702
- const propType = prop.type;
703
- const rawNegative = optMeta?.negative ?? prop?.negative;
704
- const hasCustomNegative = rawNegative !== void 0;
705
- const negativeList = hasCustomNegative ? typeof rawNegative === "string" ? rawNegative ? [rawNegative] : [] : Array.from(rawNegative).filter(Boolean) : void 0;
706
- const isNegatable = propType === "boolean" && !hasCustomNegative && !hasExplicitNegation(key) && !isNegationOf(key);
707
- result.push({
708
- name: key,
709
- description: optMeta?.description ?? prop.description,
710
- optional: isOptional,
711
- default: prop.default,
712
- type: propType === "array" ? `${prop.items?.type || "string"}[]` : propType,
713
- enum: enumValues,
714
- deprecated: optMeta?.deprecated ?? prop?.deprecated,
715
- hidden: optMeta?.hidden ?? prop?.hidden,
716
- examples: optMeta?.examples ?? prop?.examples,
717
- variadic: propType === "array",
718
- negatable: isNegatable,
719
- negative: negativeList?.length ? negativeList : void 0,
720
- group: optMeta?.group
721
- });
722
- }
723
- }
724
- } catch {}
725
- return result;
726
- }
727
- /**
728
- * Builds a comprehensive HelpInfo structure from a command.
729
- * This is the single source of truth that all formatters use.
730
- * @param cmd - The command to build help info for
731
- * @param detail - The level of detail ('minimal', 'standard', or 'full')
732
- */
733
- function getHelpInfo(cmd, detail = "standard", all) {
734
- const rootCmd = getRootCommand(cmd);
735
- const isDefaultCommand = cmd.parent && (!cmd.name || cmd.aliases?.includes(""));
736
- const nonEmptyAliases = cmd.aliases?.filter(Boolean);
737
- const commandName = cmd.path || cmd.name || nonEmptyAliases?.[0] || (cmd.parent ? "[default]" : "program");
738
- const remainingAliases = !cmd.name && nonEmptyAliases?.length ? nonEmptyAliases.slice(1) : nonEmptyAliases ?? [];
739
- const displayAliases = isDefaultCommand ? [...remainingAliases, "[default]"] : nonEmptyAliases;
740
- const { args: positionalArgs, positionalNames } = cmd.argsSchema ? extractPositionalArgsInfo(cmd.argsSchema, cmd.meta) : {
741
- args: [],
742
- positionalNames: /* @__PURE__ */ new Set()
743
- };
744
- const hasPositionals = positionalArgs.length > 0;
745
- const helpInfo = {
746
- name: commandName,
747
- title: cmd.title,
748
- description: cmd.description,
749
- examples: cmd.examples,
750
- aliases: displayAliases,
751
- deprecated: cmd.deprecated,
752
- hidden: cmd.hidden,
753
- usage: {
754
- command: rootCmd === cmd ? commandName : `${rootCmd.name} ${commandName}`,
755
- hasSubcommands: !!(cmd.commands && cmd.commands.length > 0),
756
- hasPositionals,
757
- hasArguments: false,
758
- stdinField: cmd.meta?.stdin
759
- }
760
- };
761
- if (cmd.commands && cmd.commands.length > 0) {
762
- const visibleCommands = detail === "full" ? cmd.commands : cmd.commands.filter((c) => !c.hidden);
763
- helpInfo.subcommands = [...cmd.action ? [{
764
- name: "[default]",
765
- title: cmd.title,
766
- description: cmd.description
767
- }] : [], ...visibleCommands.flatMap((c) => {
768
- const isDefault = !c.name || c.aliases?.includes("");
769
- const nonEmptyAliases = c.aliases?.filter(Boolean);
770
- const displayName = c.name || nonEmptyAliases?.[0] || "[default]";
771
- const remainingAliases = !c.name && nonEmptyAliases?.length ? nonEmptyAliases.slice(1) : nonEmptyAliases ?? [];
772
- const displayAliases = isDefault && displayName !== "[default]" ? [...remainingAliases, "[default]"] : isDefault ? remainingAliases : nonEmptyAliases;
773
- const hasSubcommands = !!(c.commands && c.commands.length > 0);
774
- const hasDefaultHandler = c.action || c.commands?.some((sub) => !sub.name || sub.aliases?.includes(""));
775
- if (hasSubcommands && hasDefaultHandler) {
776
- const defaultSub = !c.action ? c.commands?.find((sub) => !sub.name || sub.aliases?.includes("")) : void 0;
777
- const hasDefaultSubInfo = defaultSub && (defaultSub.title || defaultSub.description);
778
- return [{
779
- name: displayName,
780
- title: hasDefaultSubInfo ? defaultSub.title : c.title,
781
- description: hasDefaultSubInfo ? defaultSub.description : c.description,
782
- aliases: displayAliases?.length ? displayAliases : void 0,
783
- deprecated: c.deprecated,
784
- hidden: c.hidden,
785
- group: c.group
786
- }, {
787
- name: displayName,
788
- title: c.title,
789
- description: c.description,
790
- deprecated: c.deprecated,
791
- hidden: c.hidden,
792
- hasSubcommands: true,
793
- group: c.group
794
- }];
795
- }
796
- return [{
797
- name: displayName,
798
- title: c.title,
799
- description: c.description,
800
- aliases: displayAliases?.length ? displayAliases : void 0,
801
- deprecated: c.deprecated,
802
- hidden: c.hidden,
803
- hasSubcommands,
804
- group: c.group
805
- }];
806
- })];
807
- if (detail === "full") helpInfo.nestedCommands = visibleCommands.map((c) => getHelpInfo(c, "full"));
808
- }
809
- if (hasPositionals) helpInfo.positionals = positionalArgs;
810
- if (cmd.argsSchema) {
811
- const argsInfo = extractArgsInfo(cmd.argsSchema, cmd.meta, positionalNames);
812
- const argMap = Object.fromEntries(argsInfo.map((arg) => [arg.name, arg]));
813
- const { flags, aliases } = extractSchemaMetadata(cmd.argsSchema, cmd.meta?.fields, cmd.meta?.autoAlias);
814
- for (const [flag, name] of Object.entries(flags)) {
815
- const arg = argMap[name];
816
- if (!arg) continue;
817
- arg.flags = [...arg.flags || [], flag];
818
- }
819
- for (const [alias, name] of Object.entries(aliases)) {
820
- const arg = argMap[name];
821
- if (!arg) continue;
822
- arg.aliases = [...arg.aliases || [], alias];
823
- }
824
- const visibleArgs = argsInfo.filter((arg) => !arg.hidden);
825
- if (visibleArgs.length > 0) {
826
- helpInfo.arguments = visibleArgs;
827
- helpInfo.usage.hasArguments = true;
828
- }
829
- }
830
- if (!cmd.parent || all) {
831
- const builtins = [];
832
- if (!findCommandByName("help", rootCmd.commands)) builtins.push({
833
- name: "help [command], -h, --help",
834
- description: "Show help for a command",
835
- sub: [
836
- {
837
- name: "--all",
838
- description: "Show all global commands and flags"
839
- },
840
- {
841
- name: "--detail <level>",
842
- description: "Detail level (minimal, standard, full)"
843
- },
844
- {
845
- name: "--format <format>",
846
- description: "Output format (text, ansi, json, markdown, html)"
847
- }
848
- ]
849
- });
850
- if (!findCommandByName("version", rootCmd.commands)) builtins.push({
851
- name: "version, -v, --version",
852
- description: "Show version information"
853
- });
854
- if (!findCommandByName("completion", rootCmd.commands)) builtins.push({
855
- name: "completion [shell]",
856
- description: "Generate shell completions (bash, zsh, fish, powershell)"
857
- });
858
- if (!findCommandByName("man", rootCmd.commands)) builtins.push({
859
- name: "man",
860
- description: "Show or install man pages (--setup to install, --remove to uninstall) (experimental)"
861
- });
862
- builtins.push({
863
- name: "[command] --repl",
864
- description: "Start interactive REPL scoped to a command"
865
- });
866
- if (!findCommandByName("mcp", rootCmd.commands)) builtins.push({
867
- name: "mcp [http|stdio]",
868
- description: "Start a Model Context Protocol server to expose commands as AI tools (experimental)",
869
- sub: [{
870
- name: "--port <port>",
871
- description: "HTTP port (default: 3000)"
872
- }, {
873
- name: "--host <host>",
874
- description: "HTTP host (default: 127.0.0.1)"
875
- }]
876
- });
877
- builtins.push({
878
- name: "--color [theme], --no-color",
879
- description: "Set color theme (default, ocean, warm, monochrome) or disable colors"
880
- });
881
- if (builtins.length > 0) helpInfo.builtins = builtins;
882
- }
883
- return helpInfo;
884
- }
885
- function generateHelp(rootCommand, commandObj = rootCommand, prefs) {
886
- const helpInfo = getHelpInfo(commandObj, prefs?.detail, prefs?.all);
887
- return createFormatter(prefs?.format ?? "auto", prefs?.detail, prefs?.theme, prefs?.all, prefs?.width, prefs?.terminal, prefs?.env).format(helpInfo);
888
- }
889
- //#endregion
890
- export { escapeHtml as a, getVersion as i, getHelpInfo as n, resolveOutputFormat as o, getRootCommand as r, colorThemes as s, generateHelp as t };
891
-
892
- //# sourceMappingURL=help-B-ZMYyn-.mjs.map