zod-args-parser 1.2.8 → 2.0.0-beta.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 (510) hide show
  1. package/README.md +525 -588
  2. package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs +2 -0
  3. package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +1 -0
  4. package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs +2 -0
  5. package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +1 -0
  6. package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs +42 -0
  7. package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +1 -0
  8. package/lib/cjs/coerce/coerce-methods.cjs +2 -0
  9. package/lib/cjs/coerce/coerce-methods.cjs.map +1 -0
  10. package/lib/cjs/coerce/string-to-array.cjs +2 -0
  11. package/lib/cjs/coerce/string-to-array.cjs.map +1 -0
  12. package/lib/cjs/coerce/string-to-primitive.cjs +2 -0
  13. package/lib/cjs/coerce/string-to-primitive.cjs.map +1 -0
  14. package/lib/cjs/coerce/string-to-set.cjs +2 -0
  15. package/lib/cjs/coerce/string-to-set.cjs.map +1 -0
  16. package/lib/cjs/definitions/define-arguments.cjs +2 -0
  17. package/lib/cjs/definitions/define-arguments.cjs.map +1 -0
  18. package/lib/cjs/definitions/define-cli.cjs +2 -0
  19. package/lib/cjs/definitions/define-cli.cjs.map +1 -0
  20. package/lib/cjs/definitions/define-options.cjs +2 -0
  21. package/lib/cjs/definitions/define-options.cjs.map +1 -0
  22. package/lib/cjs/definitions/define-subcommand.cjs +2 -0
  23. package/lib/cjs/definitions/define-subcommand.cjs.map +1 -0
  24. package/lib/cjs/definitions/validate-cli-definition.cjs +2 -0
  25. package/lib/cjs/definitions/validate-cli-definition.cjs.map +1 -0
  26. package/lib/cjs/help-message/format-arguments.cjs +2 -0
  27. package/lib/cjs/help-message/format-arguments.cjs.map +1 -0
  28. package/lib/cjs/help-message/format-options.cjs +2 -0
  29. package/lib/cjs/help-message/format-options.cjs.map +1 -0
  30. package/lib/cjs/help-message/format-subcommands.cjs +2 -0
  31. package/lib/cjs/help-message/format-subcommands.cjs.map +1 -0
  32. package/lib/cjs/help-message/generate-for-cli.cjs +2 -0
  33. package/lib/cjs/help-message/generate-for-cli.cjs.map +1 -0
  34. package/lib/cjs/help-message/generate-for-subcommand.cjs +2 -0
  35. package/lib/cjs/help-message/generate-for-subcommand.cjs.map +1 -0
  36. package/lib/cjs/help-message/print-help.cjs +2 -0
  37. package/lib/cjs/help-message/print-help.cjs.map +1 -0
  38. package/lib/cjs/help-message/set-defaults.cjs +2 -0
  39. package/lib/cjs/help-message/set-defaults.cjs.map +1 -0
  40. package/lib/cjs/help-message/styles.cjs +2 -0
  41. package/lib/cjs/help-message/styles.cjs.map +1 -0
  42. package/lib/cjs/help-message/terminal-markdown.cjs +2 -0
  43. package/lib/cjs/help-message/terminal-markdown.cjs.map +1 -0
  44. package/lib/cjs/index.cjs +2 -0
  45. package/lib/cjs/index.cjs.map +1 -0
  46. package/lib/cjs/markdown/generate-markdown.cjs +2 -0
  47. package/lib/cjs/markdown/generate-markdown.cjs.map +1 -0
  48. package/lib/cjs/metadata/arguments-metadata.cjs +2 -0
  49. package/lib/cjs/metadata/arguments-metadata.cjs.map +1 -0
  50. package/lib/cjs/metadata/cli-metadata.cjs +2 -0
  51. package/lib/cjs/metadata/cli-metadata.cjs.map +1 -0
  52. package/lib/cjs/metadata/options-metadata.cjs +2 -0
  53. package/lib/cjs/metadata/options-metadata.cjs.map +1 -0
  54. package/lib/cjs/metadata/subcommands-metadata.cjs +2 -0
  55. package/lib/cjs/metadata/subcommands-metadata.cjs.map +1 -0
  56. package/lib/cjs/parse/context/cli-context-builder.cjs +2 -0
  57. package/lib/cjs/parse/context/cli-context-builder.cjs.map +1 -0
  58. package/lib/cjs/parse/context/object-context-builder.cjs +2 -0
  59. package/lib/cjs/parse/context/object-context-builder.cjs.map +1 -0
  60. package/lib/cjs/parse/parser-utilities.cjs +2 -0
  61. package/lib/cjs/parse/parser-utilities.cjs.map +1 -0
  62. package/lib/cjs/parse/safe-parse.cjs +2 -0
  63. package/lib/cjs/parse/safe-parse.cjs.map +1 -0
  64. package/lib/cjs/parse/validation/validate-context.cjs +2 -0
  65. package/lib/cjs/parse/validation/validate-context.cjs.map +1 -0
  66. package/lib/cjs/parse/validation/validators/arguments.cjs +2 -0
  67. package/lib/cjs/parse/validation/validators/arguments.cjs.map +1 -0
  68. package/lib/cjs/parse/validation/validators/conflict.cjs +2 -0
  69. package/lib/cjs/parse/validation/validators/conflict.cjs.map +1 -0
  70. package/lib/cjs/parse/validation/validators/exclusive.cjs +2 -0
  71. package/lib/cjs/parse/validation/validators/exclusive.cjs.map +1 -0
  72. package/lib/cjs/parse/validation/validators/explicitly-passed.cjs +2 -0
  73. package/lib/cjs/parse/validation/validators/explicitly-passed.cjs.map +1 -0
  74. package/lib/cjs/parse/validation/validators/options.cjs +2 -0
  75. package/lib/cjs/parse/validation/validators/options.cjs.map +1 -0
  76. package/lib/cjs/parse/validation/validators/requires.cjs +2 -0
  77. package/lib/cjs/parse/validation/validators/requires.cjs.map +1 -0
  78. package/lib/cjs/utilities.cjs +2 -0
  79. package/lib/cjs/utilities.cjs.map +1 -0
  80. package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js +2 -0
  81. package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js.map +1 -0
  82. package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js +2 -0
  83. package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js.map +1 -0
  84. package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js +42 -0
  85. package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js.map +1 -0
  86. package/lib/esm/coerce/coerce-methods.js +2 -0
  87. package/lib/esm/coerce/coerce-methods.js.map +1 -0
  88. package/lib/esm/coerce/string-to-array.js +2 -0
  89. package/lib/esm/coerce/string-to-array.js.map +1 -0
  90. package/lib/esm/coerce/string-to-primitive.js +2 -0
  91. package/lib/esm/coerce/string-to-primitive.js.map +1 -0
  92. package/lib/esm/coerce/string-to-set.js +2 -0
  93. package/lib/esm/coerce/string-to-set.js.map +1 -0
  94. package/lib/esm/definitions/define-arguments.js +2 -0
  95. package/lib/esm/definitions/define-arguments.js.map +1 -0
  96. package/lib/esm/definitions/define-cli.js +2 -0
  97. package/lib/esm/definitions/define-cli.js.map +1 -0
  98. package/lib/esm/definitions/define-options.js +2 -0
  99. package/lib/esm/definitions/define-options.js.map +1 -0
  100. package/lib/esm/definitions/define-subcommand.js +2 -0
  101. package/lib/esm/definitions/define-subcommand.js.map +1 -0
  102. package/lib/esm/definitions/validate-cli-definition.js +2 -0
  103. package/lib/esm/definitions/validate-cli-definition.js.map +1 -0
  104. package/lib/esm/help-message/format-arguments.js +2 -0
  105. package/lib/esm/help-message/format-arguments.js.map +1 -0
  106. package/lib/esm/help-message/format-options.js +2 -0
  107. package/lib/esm/help-message/format-options.js.map +1 -0
  108. package/lib/esm/help-message/format-subcommands.js +2 -0
  109. package/lib/esm/help-message/format-subcommands.js.map +1 -0
  110. package/lib/esm/help-message/generate-for-cli.js +2 -0
  111. package/lib/esm/help-message/generate-for-cli.js.map +1 -0
  112. package/lib/esm/help-message/generate-for-subcommand.js +2 -0
  113. package/lib/esm/help-message/generate-for-subcommand.js.map +1 -0
  114. package/lib/esm/help-message/print-help.js +2 -0
  115. package/lib/esm/help-message/print-help.js.map +1 -0
  116. package/lib/esm/help-message/set-defaults.js +2 -0
  117. package/lib/esm/help-message/set-defaults.js.map +1 -0
  118. package/lib/esm/help-message/styles.js +2 -0
  119. package/lib/esm/help-message/styles.js.map +1 -0
  120. package/lib/esm/help-message/terminal-markdown.js +2 -0
  121. package/lib/esm/help-message/terminal-markdown.js.map +1 -0
  122. package/lib/esm/index.js +2 -0
  123. package/lib/esm/index.js.map +1 -0
  124. package/lib/esm/markdown/generate-markdown.js +2 -0
  125. package/lib/esm/markdown/generate-markdown.js.map +1 -0
  126. package/lib/esm/metadata/arguments-metadata.js +2 -0
  127. package/lib/esm/metadata/arguments-metadata.js.map +1 -0
  128. package/lib/esm/metadata/cli-metadata.js +2 -0
  129. package/lib/esm/metadata/cli-metadata.js.map +1 -0
  130. package/lib/esm/metadata/options-metadata.js +2 -0
  131. package/lib/esm/metadata/options-metadata.js.map +1 -0
  132. package/lib/esm/metadata/subcommands-metadata.js +2 -0
  133. package/lib/esm/metadata/subcommands-metadata.js.map +1 -0
  134. package/lib/esm/parse/context/cli-context-builder.js +2 -0
  135. package/lib/esm/parse/context/cli-context-builder.js.map +1 -0
  136. package/lib/esm/parse/context/object-context-builder.js +2 -0
  137. package/lib/esm/parse/context/object-context-builder.js.map +1 -0
  138. package/lib/esm/parse/parser-utilities.js +2 -0
  139. package/lib/esm/parse/parser-utilities.js.map +1 -0
  140. package/lib/esm/parse/safe-parse.js +2 -0
  141. package/lib/esm/parse/safe-parse.js.map +1 -0
  142. package/lib/esm/parse/validation/validate-context.js +2 -0
  143. package/lib/esm/parse/validation/validate-context.js.map +1 -0
  144. package/lib/esm/parse/validation/validators/arguments.js +2 -0
  145. package/lib/esm/parse/validation/validators/arguments.js.map +1 -0
  146. package/lib/esm/parse/validation/validators/conflict.js +2 -0
  147. package/lib/esm/parse/validation/validators/conflict.js.map +1 -0
  148. package/lib/esm/parse/validation/validators/exclusive.js +2 -0
  149. package/lib/esm/parse/validation/validators/exclusive.js.map +1 -0
  150. package/lib/esm/parse/validation/validators/explicitly-passed.js +2 -0
  151. package/lib/esm/parse/validation/validators/explicitly-passed.js.map +1 -0
  152. package/lib/esm/parse/validation/validators/options.js +2 -0
  153. package/lib/esm/parse/validation/validators/options.js.map +1 -0
  154. package/lib/esm/parse/validation/validators/requires.js +2 -0
  155. package/lib/esm/parse/validation/validators/requires.js.map +1 -0
  156. package/lib/esm/utilities.js +2 -0
  157. package/lib/esm/utilities.js.map +1 -0
  158. package/lib/iife/index.js +2 -0
  159. package/lib/iife/index.js.map +1 -0
  160. package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs +2 -0
  161. package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs.map +1 -0
  162. package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs +2 -0
  163. package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs.map +1 -0
  164. package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs +42 -0
  165. package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs.map +1 -0
  166. package/lib/mjs/coerce/coerce-methods.mjs +2 -0
  167. package/lib/mjs/coerce/coerce-methods.mjs.map +1 -0
  168. package/lib/mjs/coerce/string-to-array.mjs +2 -0
  169. package/lib/mjs/coerce/string-to-array.mjs.map +1 -0
  170. package/lib/mjs/coerce/string-to-primitive.mjs +2 -0
  171. package/lib/mjs/coerce/string-to-primitive.mjs.map +1 -0
  172. package/lib/mjs/coerce/string-to-set.mjs +2 -0
  173. package/lib/mjs/coerce/string-to-set.mjs.map +1 -0
  174. package/lib/mjs/definitions/define-arguments.mjs +2 -0
  175. package/lib/mjs/definitions/define-arguments.mjs.map +1 -0
  176. package/lib/mjs/definitions/define-cli.mjs +2 -0
  177. package/lib/mjs/definitions/define-cli.mjs.map +1 -0
  178. package/lib/mjs/definitions/define-options.mjs +2 -0
  179. package/lib/mjs/definitions/define-options.mjs.map +1 -0
  180. package/lib/mjs/definitions/define-subcommand.mjs +2 -0
  181. package/lib/mjs/definitions/define-subcommand.mjs.map +1 -0
  182. package/lib/mjs/definitions/validate-cli-definition.mjs +2 -0
  183. package/lib/mjs/definitions/validate-cli-definition.mjs.map +1 -0
  184. package/lib/mjs/help-message/format-arguments.mjs +2 -0
  185. package/lib/mjs/help-message/format-arguments.mjs.map +1 -0
  186. package/lib/mjs/help-message/format-options.mjs +2 -0
  187. package/lib/mjs/help-message/format-options.mjs.map +1 -0
  188. package/lib/mjs/help-message/format-subcommands.mjs +2 -0
  189. package/lib/mjs/help-message/format-subcommands.mjs.map +1 -0
  190. package/lib/mjs/help-message/generate-for-cli.mjs +2 -0
  191. package/lib/mjs/help-message/generate-for-cli.mjs.map +1 -0
  192. package/lib/mjs/help-message/generate-for-subcommand.mjs +2 -0
  193. package/lib/mjs/help-message/generate-for-subcommand.mjs.map +1 -0
  194. package/lib/mjs/help-message/print-help.mjs +2 -0
  195. package/lib/mjs/help-message/print-help.mjs.map +1 -0
  196. package/lib/mjs/help-message/set-defaults.mjs +2 -0
  197. package/lib/mjs/help-message/set-defaults.mjs.map +1 -0
  198. package/lib/mjs/help-message/styles.mjs +2 -0
  199. package/lib/mjs/help-message/styles.mjs.map +1 -0
  200. package/lib/mjs/help-message/terminal-markdown.mjs +2 -0
  201. package/lib/mjs/help-message/terminal-markdown.mjs.map +1 -0
  202. package/lib/mjs/index.mjs +2 -0
  203. package/lib/mjs/index.mjs.map +1 -0
  204. package/lib/mjs/markdown/generate-markdown.mjs +2 -0
  205. package/lib/mjs/markdown/generate-markdown.mjs.map +1 -0
  206. package/lib/mjs/metadata/arguments-metadata.mjs +2 -0
  207. package/lib/mjs/metadata/arguments-metadata.mjs.map +1 -0
  208. package/lib/mjs/metadata/cli-metadata.mjs +2 -0
  209. package/lib/mjs/metadata/cli-metadata.mjs.map +1 -0
  210. package/lib/mjs/metadata/options-metadata.mjs +2 -0
  211. package/lib/mjs/metadata/options-metadata.mjs.map +1 -0
  212. package/lib/mjs/metadata/subcommands-metadata.mjs +2 -0
  213. package/lib/mjs/metadata/subcommands-metadata.mjs.map +1 -0
  214. package/lib/mjs/parse/context/cli-context-builder.mjs +2 -0
  215. package/lib/mjs/parse/context/cli-context-builder.mjs.map +1 -0
  216. package/lib/mjs/parse/context/object-context-builder.mjs +2 -0
  217. package/lib/mjs/parse/context/object-context-builder.mjs.map +1 -0
  218. package/lib/mjs/parse/parser-utilities.mjs +2 -0
  219. package/lib/mjs/parse/parser-utilities.mjs.map +1 -0
  220. package/lib/mjs/parse/safe-parse.mjs +2 -0
  221. package/lib/mjs/parse/safe-parse.mjs.map +1 -0
  222. package/lib/mjs/parse/validation/validate-context.mjs +2 -0
  223. package/lib/mjs/parse/validation/validate-context.mjs.map +1 -0
  224. package/lib/mjs/parse/validation/validators/arguments.mjs +2 -0
  225. package/lib/mjs/parse/validation/validators/arguments.mjs.map +1 -0
  226. package/lib/mjs/parse/validation/validators/conflict.mjs +2 -0
  227. package/lib/mjs/parse/validation/validators/conflict.mjs.map +1 -0
  228. package/lib/mjs/parse/validation/validators/exclusive.mjs +2 -0
  229. package/lib/mjs/parse/validation/validators/exclusive.mjs.map +1 -0
  230. package/lib/mjs/parse/validation/validators/explicitly-passed.mjs +2 -0
  231. package/lib/mjs/parse/validation/validators/explicitly-passed.mjs.map +1 -0
  232. package/lib/mjs/parse/validation/validators/options.mjs +2 -0
  233. package/lib/mjs/parse/validation/validators/options.mjs.map +1 -0
  234. package/lib/mjs/parse/validation/validators/requires.mjs +2 -0
  235. package/lib/mjs/parse/validation/validators/requires.mjs.map +1 -0
  236. package/lib/mjs/utilities.mjs +2 -0
  237. package/lib/mjs/utilities.mjs.map +1 -0
  238. package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts +2 -2
  239. package/lib/typescript/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
  240. package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +2 -2
  241. package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
  242. package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +2 -2
  243. package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
  244. package/lib/typescript/coerce/coerce-methods.d.ts +20 -0
  245. package/lib/typescript/coerce/coerce-methods.d.ts.map +1 -0
  246. package/lib/typescript/coerce/string-to-array.d.ts +6 -0
  247. package/lib/typescript/coerce/string-to-array.d.ts.map +1 -0
  248. package/lib/typescript/coerce/string-to-primitive.d.ts +5 -0
  249. package/lib/typescript/coerce/string-to-primitive.d.ts.map +1 -0
  250. package/lib/typescript/coerce/string-to-set.d.ts +6 -0
  251. package/lib/typescript/coerce/string-to-set.d.ts.map +1 -0
  252. package/lib/typescript/definitions/define-arguments.d.ts +7 -0
  253. package/lib/typescript/definitions/define-arguments.d.ts.map +1 -0
  254. package/lib/typescript/definitions/define-cli.d.ts +24 -0
  255. package/lib/typescript/definitions/define-cli.d.ts.map +1 -0
  256. package/lib/typescript/definitions/define-options.d.ts +7 -0
  257. package/lib/typescript/definitions/define-options.d.ts.map +1 -0
  258. package/lib/typescript/definitions/define-subcommand.d.ts +17 -0
  259. package/lib/typescript/definitions/define-subcommand.d.ts.map +1 -0
  260. package/lib/typescript/definitions/validate-cli-definition.d.ts +4 -0
  261. package/lib/typescript/definitions/validate-cli-definition.d.ts.map +1 -0
  262. package/lib/typescript/help-message/format-arguments.d.ts +3 -3
  263. package/lib/typescript/help-message/format-arguments.d.ts.map +1 -1
  264. package/lib/typescript/help-message/format-options.d.ts +3 -3
  265. package/lib/typescript/help-message/format-options.d.ts.map +1 -1
  266. package/lib/typescript/help-message/format-subcommands.d.ts +3 -3
  267. package/lib/typescript/help-message/format-subcommands.d.ts.map +1 -1
  268. package/lib/typescript/help-message/generate-for-cli.d.ts +8 -0
  269. package/lib/typescript/help-message/generate-for-cli.d.ts.map +1 -0
  270. package/lib/typescript/help-message/generate-for-subcommand.d.ts +4 -0
  271. package/lib/typescript/help-message/generate-for-subcommand.d.ts.map +1 -0
  272. package/lib/typescript/help-message/print-help.d.ts +5 -0
  273. package/lib/typescript/help-message/print-help.d.ts.map +1 -0
  274. package/lib/typescript/help-message/set-defaults.d.ts +4 -0
  275. package/lib/typescript/help-message/set-defaults.d.ts.map +1 -0
  276. package/lib/typescript/help-message/styles.d.ts +30 -106
  277. package/lib/typescript/help-message/styles.d.ts.map +1 -1
  278. package/lib/typescript/help-message/terminal-markdown.d.ts +3 -0
  279. package/lib/typescript/help-message/terminal-markdown.d.ts.map +1 -0
  280. package/lib/typescript/index.d.ts +23 -35
  281. package/lib/typescript/index.d.ts.map +1 -1
  282. package/lib/typescript/markdown/generate-markdown.d.ts +2 -2
  283. package/lib/typescript/markdown/generate-markdown.d.ts.map +1 -1
  284. package/lib/typescript/metadata/arguments-metadata.d.ts +4 -0
  285. package/lib/typescript/metadata/arguments-metadata.d.ts.map +1 -0
  286. package/lib/typescript/metadata/cli-metadata.d.ts +4 -0
  287. package/lib/typescript/metadata/cli-metadata.d.ts.map +1 -0
  288. package/lib/typescript/metadata/options-metadata.d.ts +4 -0
  289. package/lib/typescript/metadata/options-metadata.d.ts.map +1 -0
  290. package/lib/typescript/metadata/subcommands-metadata.d.ts +4 -0
  291. package/lib/typescript/metadata/subcommands-metadata.d.ts.map +1 -0
  292. package/lib/typescript/parse/context/cli-context-builder.d.ts +9 -0
  293. package/lib/typescript/parse/context/cli-context-builder.d.ts.map +1 -0
  294. package/lib/typescript/parse/context/object-context-builder.d.ts +6 -0
  295. package/lib/typescript/parse/context/object-context-builder.d.ts.map +1 -0
  296. package/lib/typescript/{parser/parse/parser-helpers.d.ts → parse/parser-utilities.d.ts} +18 -9
  297. package/lib/typescript/parse/parser-utilities.d.ts.map +1 -0
  298. package/lib/typescript/parse/safe-parse.d.ts +5 -0
  299. package/lib/typescript/parse/safe-parse.d.ts.map +1 -0
  300. package/lib/typescript/parse/validation/validate-context.d.ts +6 -0
  301. package/lib/typescript/parse/validation/validate-context.d.ts.map +1 -0
  302. package/lib/typescript/parse/validation/validators/arguments.d.ts +12 -0
  303. package/lib/typescript/parse/validation/validators/arguments.d.ts.map +1 -0
  304. package/lib/typescript/parse/validation/validators/conflict.d.ts +16 -0
  305. package/lib/typescript/parse/validation/validators/conflict.d.ts.map +1 -0
  306. package/lib/typescript/parse/validation/validators/exclusive.d.ts +16 -0
  307. package/lib/typescript/parse/validation/validators/exclusive.d.ts.map +1 -0
  308. package/lib/typescript/parse/validation/validators/explicitly-passed.d.ts +5 -0
  309. package/lib/typescript/parse/validation/validators/explicitly-passed.d.ts.map +1 -0
  310. package/lib/typescript/parse/validation/validators/options.d.ts +12 -0
  311. package/lib/typescript/parse/validation/validators/options.d.ts.map +1 -0
  312. package/lib/typescript/parse/validation/validators/requires.d.ts +18 -0
  313. package/lib/typescript/parse/validation/validators/requires.d.ts.map +1 -0
  314. package/lib/typescript/types/context-types.d.ts +135 -0
  315. package/lib/typescript/types/context-types.d.ts.map +1 -0
  316. package/lib/typescript/types/definitions-types.d.ts +294 -0
  317. package/lib/typescript/types/definitions-types.d.ts.map +1 -0
  318. package/lib/typescript/types/help-message-types.d.ts +134 -0
  319. package/lib/typescript/types/help-message-types.d.ts.map +1 -0
  320. package/lib/typescript/types/io-types.d.ts +96 -0
  321. package/lib/typescript/types/io-types.d.ts.map +1 -0
  322. package/lib/typescript/types/metadata-types.d.ts +75 -0
  323. package/lib/typescript/types/metadata-types.d.ts.map +1 -0
  324. package/lib/typescript/types/schema-types.d.ts +6 -0
  325. package/lib/typescript/types/schema-types.d.ts.map +1 -0
  326. package/lib/typescript/types/types.d.ts +61 -0
  327. package/lib/typescript/types/types.d.ts.map +1 -0
  328. package/lib/typescript/types/utilities-types.d.ts +17 -0
  329. package/lib/typescript/types/utilities-types.d.ts.map +1 -0
  330. package/lib/typescript/utilities.d.ts +24 -10
  331. package/lib/typescript/utilities.d.ts.map +1 -1
  332. package/package.json +29 -26
  333. package/src/autocomplete-scripts/bash-autocomplete-script.ts +13 -9
  334. package/src/autocomplete-scripts/powershell-autocomplete-script.ts +21 -13
  335. package/src/autocomplete-scripts/zsh-autocomplete-script.ts +27 -23
  336. package/src/coerce/coerce-methods.ts +75 -0
  337. package/src/coerce/string-to-array.ts +18 -0
  338. package/src/coerce/string-to-primitive.ts +31 -0
  339. package/src/coerce/string-to-set.ts +15 -0
  340. package/src/definitions/define-arguments.ts +10 -0
  341. package/src/definitions/define-cli.ts +105 -0
  342. package/src/definitions/define-options.ts +12 -0
  343. package/src/definitions/define-subcommand.ts +57 -0
  344. package/src/definitions/validate-cli-definition.ts +331 -0
  345. package/src/help-message/format-arguments.ts +57 -33
  346. package/src/help-message/format-options.ts +59 -34
  347. package/src/help-message/format-subcommands.ts +43 -21
  348. package/src/help-message/generate-for-cli.ts +114 -0
  349. package/src/help-message/generate-for-subcommand.ts +32 -0
  350. package/src/help-message/print-help.ts +13 -0
  351. package/src/help-message/set-defaults.ts +34 -0
  352. package/src/help-message/styles.ts +148 -103
  353. package/src/help-message/terminal-markdown.ts +147 -0
  354. package/src/index.ts +28 -97
  355. package/src/markdown/generate-markdown.ts +47 -58
  356. package/src/metadata/arguments-metadata.ts +28 -0
  357. package/src/metadata/cli-metadata.ts +26 -0
  358. package/src/metadata/options-metadata.ts +38 -0
  359. package/src/metadata/subcommands-metadata.ts +35 -0
  360. package/src/parse/context/cli-context-builder.ts +246 -0
  361. package/src/parse/context/object-context-builder.ts +63 -0
  362. package/src/{parser/parse/parser-helpers.ts → parse/parser-utilities.ts} +46 -25
  363. package/src/parse/safe-parse.ts +76 -0
  364. package/src/parse/validation/validate-context.ts +23 -0
  365. package/src/parse/validation/validators/arguments.ts +59 -0
  366. package/src/parse/validation/validators/conflict.ts +68 -0
  367. package/src/parse/validation/validators/exclusive.ts +70 -0
  368. package/src/parse/validation/validators/explicitly-passed.ts +15 -0
  369. package/src/parse/validation/validators/options.ts +59 -0
  370. package/src/parse/validation/validators/requires.ts +82 -0
  371. package/src/types/context-types.ts +171 -0
  372. package/src/types/definitions-types.ts +340 -0
  373. package/src/types/help-message-types.ts +153 -0
  374. package/src/types/io-types.ts +131 -0
  375. package/src/types/metadata-types.ts +104 -0
  376. package/src/types/schema-types.ts +9 -0
  377. package/src/types/types.ts +72 -0
  378. package/src/types/utilities-types.ts +26 -0
  379. package/src/utilities.ts +200 -23
  380. package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs +0 -42
  381. package/lib/commonjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +0 -1
  382. package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs +0 -31
  383. package/lib/commonjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +0 -1
  384. package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs +0 -41
  385. package/lib/commonjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +0 -1
  386. package/lib/commonjs/help-message/format-arguments.cjs +0 -1
  387. package/lib/commonjs/help-message/format-arguments.cjs.map +0 -1
  388. package/lib/commonjs/help-message/format-cli.cjs +0 -1
  389. package/lib/commonjs/help-message/format-cli.cjs.map +0 -1
  390. package/lib/commonjs/help-message/format-options.cjs +0 -1
  391. package/lib/commonjs/help-message/format-options.cjs.map +0 -1
  392. package/lib/commonjs/help-message/format-subcommands.cjs +0 -1
  393. package/lib/commonjs/help-message/format-subcommands.cjs.map +0 -1
  394. package/lib/commonjs/help-message/styles.cjs +0 -1
  395. package/lib/commonjs/help-message/styles.cjs.map +0 -1
  396. package/lib/commonjs/index.cjs +0 -1
  397. package/lib/commonjs/index.cjs.map +0 -1
  398. package/lib/commonjs/markdown/generate-markdown.cjs +0 -1
  399. package/lib/commonjs/markdown/generate-markdown.cjs.map +0 -1
  400. package/lib/commonjs/metadata/get-arguments-metadata.cjs +0 -1
  401. package/lib/commonjs/metadata/get-arguments-metadata.cjs.map +0 -1
  402. package/lib/commonjs/metadata/get-cli-metadata.cjs +0 -1
  403. package/lib/commonjs/metadata/get-cli-metadata.cjs.map +0 -1
  404. package/lib/commonjs/metadata/get-options-metadata.cjs +0 -1
  405. package/lib/commonjs/metadata/get-options-metadata.cjs.map +0 -1
  406. package/lib/commonjs/metadata/get-subcommands-metadata.cjs +0 -1
  407. package/lib/commonjs/metadata/get-subcommands-metadata.cjs.map +0 -1
  408. package/lib/commonjs/parser/parse/parse.cjs +0 -1
  409. package/lib/commonjs/parser/parse/parse.cjs.map +0 -1
  410. package/lib/commonjs/parser/parse/parser-helpers.cjs +0 -1
  411. package/lib/commonjs/parser/parse/parser-helpers.cjs.map +0 -1
  412. package/lib/commonjs/parser/safe-parse.cjs +0 -1
  413. package/lib/commonjs/parser/safe-parse.cjs.map +0 -1
  414. package/lib/commonjs/parser/unsafe-parse.cjs +0 -1
  415. package/lib/commonjs/parser/unsafe-parse.cjs.map +0 -1
  416. package/lib/commonjs/parser/validate/validate-type.cjs +0 -1
  417. package/lib/commonjs/parser/validate/validate-type.cjs.map +0 -1
  418. package/lib/commonjs/parser/validate/validate.cjs +0 -1
  419. package/lib/commonjs/parser/validate/validate.cjs.map +0 -1
  420. package/lib/commonjs/utilities.cjs +0 -1
  421. package/lib/commonjs/utilities.cjs.map +0 -1
  422. package/lib/commonjs/zod-utilities.cjs +0 -1
  423. package/lib/commonjs/zod-utilities.cjs.map +0 -1
  424. package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs +0 -42
  425. package/lib/module/autocomplete-scripts/bash-autocomplete-script.mjs.map +0 -1
  426. package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs +0 -31
  427. package/lib/module/autocomplete-scripts/powershell-autocomplete-script.mjs.map +0 -1
  428. package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs +0 -41
  429. package/lib/module/autocomplete-scripts/zsh-autocomplete-script.mjs.map +0 -1
  430. package/lib/module/help-message/format-arguments.mjs +0 -1
  431. package/lib/module/help-message/format-arguments.mjs.map +0 -1
  432. package/lib/module/help-message/format-cli.mjs +0 -1
  433. package/lib/module/help-message/format-cli.mjs.map +0 -1
  434. package/lib/module/help-message/format-options.mjs +0 -1
  435. package/lib/module/help-message/format-options.mjs.map +0 -1
  436. package/lib/module/help-message/format-subcommands.mjs +0 -1
  437. package/lib/module/help-message/format-subcommands.mjs.map +0 -1
  438. package/lib/module/help-message/styles.mjs +0 -1
  439. package/lib/module/help-message/styles.mjs.map +0 -1
  440. package/lib/module/index.mjs +0 -1
  441. package/lib/module/index.mjs.map +0 -1
  442. package/lib/module/markdown/generate-markdown.mjs +0 -1
  443. package/lib/module/markdown/generate-markdown.mjs.map +0 -1
  444. package/lib/module/metadata/get-arguments-metadata.mjs +0 -1
  445. package/lib/module/metadata/get-arguments-metadata.mjs.map +0 -1
  446. package/lib/module/metadata/get-cli-metadata.mjs +0 -1
  447. package/lib/module/metadata/get-cli-metadata.mjs.map +0 -1
  448. package/lib/module/metadata/get-options-metadata.mjs +0 -1
  449. package/lib/module/metadata/get-options-metadata.mjs.map +0 -1
  450. package/lib/module/metadata/get-subcommands-metadata.mjs +0 -1
  451. package/lib/module/metadata/get-subcommands-metadata.mjs.map +0 -1
  452. package/lib/module/parser/parse/parse.mjs +0 -1
  453. package/lib/module/parser/parse/parse.mjs.map +0 -1
  454. package/lib/module/parser/parse/parser-helpers.mjs +0 -1
  455. package/lib/module/parser/parse/parser-helpers.mjs.map +0 -1
  456. package/lib/module/parser/safe-parse.mjs +0 -1
  457. package/lib/module/parser/safe-parse.mjs.map +0 -1
  458. package/lib/module/parser/unsafe-parse.mjs +0 -1
  459. package/lib/module/parser/unsafe-parse.mjs.map +0 -1
  460. package/lib/module/parser/validate/validate-type.mjs +0 -1
  461. package/lib/module/parser/validate/validate-type.mjs.map +0 -1
  462. package/lib/module/parser/validate/validate.mjs +0 -1
  463. package/lib/module/parser/validate/validate.mjs.map +0 -1
  464. package/lib/module/utilities.mjs +0 -1
  465. package/lib/module/utilities.mjs.map +0 -1
  466. package/lib/module/zod-utilities.mjs +0 -1
  467. package/lib/module/zod-utilities.mjs.map +0 -1
  468. package/lib/typescript/help-message/format-cli.d.ts +0 -6
  469. package/lib/typescript/help-message/format-cli.d.ts.map +0 -1
  470. package/lib/typescript/metadata/get-arguments-metadata.d.ts +0 -4
  471. package/lib/typescript/metadata/get-arguments-metadata.d.ts.map +0 -1
  472. package/lib/typescript/metadata/get-cli-metadata.d.ts +0 -4
  473. package/lib/typescript/metadata/get-cli-metadata.d.ts.map +0 -1
  474. package/lib/typescript/metadata/get-options-metadata.d.ts +0 -4
  475. package/lib/typescript/metadata/get-options-metadata.d.ts.map +0 -1
  476. package/lib/typescript/metadata/get-subcommands-metadata.d.ts +0 -4
  477. package/lib/typescript/metadata/get-subcommands-metadata.d.ts.map +0 -1
  478. package/lib/typescript/metadata/metadata-types.d.ts +0 -80
  479. package/lib/typescript/metadata/metadata-types.d.ts.map +0 -1
  480. package/lib/typescript/parser/parse/parse-types.d.ts +0 -85
  481. package/lib/typescript/parser/parse/parse-types.d.ts.map +0 -1
  482. package/lib/typescript/parser/parse/parse.d.ts +0 -4
  483. package/lib/typescript/parser/parse/parse.d.ts.map +0 -1
  484. package/lib/typescript/parser/parse/parser-helpers.d.ts.map +0 -1
  485. package/lib/typescript/parser/safe-parse.d.ts +0 -4
  486. package/lib/typescript/parser/safe-parse.d.ts.map +0 -1
  487. package/lib/typescript/parser/unsafe-parse.d.ts +0 -4
  488. package/lib/typescript/parser/unsafe-parse.d.ts.map +0 -1
  489. package/lib/typescript/parser/validate/validate-type.d.ts +0 -22
  490. package/lib/typescript/parser/validate/validate-type.d.ts.map +0 -1
  491. package/lib/typescript/parser/validate/validate.d.ts +0 -11
  492. package/lib/typescript/parser/validate/validate.d.ts.map +0 -1
  493. package/lib/typescript/types.d.ts +0 -294
  494. package/lib/typescript/types.d.ts.map +0 -1
  495. package/lib/typescript/zod-utilities.d.ts +0 -28
  496. package/lib/typescript/zod-utilities.d.ts.map +0 -1
  497. package/src/help-message/format-cli.ts +0 -141
  498. package/src/metadata/get-arguments-metadata.ts +0 -25
  499. package/src/metadata/get-cli-metadata.ts +0 -23
  500. package/src/metadata/get-options-metadata.ts +0 -35
  501. package/src/metadata/get-subcommands-metadata.ts +0 -32
  502. package/src/metadata/metadata-types.ts +0 -114
  503. package/src/parser/parse/parse-types.ts +0 -89
  504. package/src/parser/parse/parse.ts +0 -230
  505. package/src/parser/safe-parse.ts +0 -103
  506. package/src/parser/unsafe-parse.ts +0 -98
  507. package/src/parser/validate/validate-type.ts +0 -21
  508. package/src/parser/validate/validate.ts +0 -66
  509. package/src/types.ts +0 -365
  510. package/src/zod-utilities.ts +0 -214
@@ -0,0 +1,131 @@
1
+ import type { Context, ContextWide } from "./context-types.ts";
2
+ import type { Argument, Cli, Option, Subcommand } from "./definitions-types.ts";
3
+ import type { InferSchemaInputType, InferSchemaOutputType } from "./schema-types.ts";
4
+ import type { Prettify, ToOptional, AllowUndefinedIfOptional as AddUndefinedIfAllOptional } from "./utilities-types.ts";
5
+
6
+ /** Output options type */
7
+ type OptionsOutputType<T extends Record<string, Option>> = Prettify<
8
+ ToOptional<{ [K in keyof T]: InferSchemaOutputType<T[K]["schema"]> }>
9
+ >;
10
+
11
+ /** Input options type */
12
+ type OptionsInputType<T extends Record<string, Option>> = Prettify<
13
+ ToOptional<{ [K in keyof T]: InferSchemaInputType<T[K]["schema"]> }>
14
+ >;
15
+
16
+ /** Output arguments type */
17
+ type ArgumentsOutputType<T extends Record<string, Argument>> = Prettify<
18
+ ToOptional<{ [K in keyof T]: InferSchemaOutputType<T[K]["schema"]> }>
19
+ >;
20
+
21
+ /** Input arguments type */
22
+ type ArgumentsInputType<T extends Record<string, Argument>> = Prettify<
23
+ ToOptional<{ [K in keyof T]: InferSchemaInputType<T[K]["schema"]> }>
24
+ >;
25
+
26
+ /**
27
+ * - Infer options output type.
28
+ *
29
+ * @example
30
+ * const myCommand = defineSubcommand({ name: "my-command", options: [...] });
31
+ * type MyCommandOptionsOutput = InferOptionsOutputType<typeof myCommand>;
32
+ */
33
+ export type InferOptionsOutputType<T extends Cli | Subcommand> =
34
+ T["options"] extends Record<string, Option> ? OptionsOutputType<T["options"]> : undefined;
35
+
36
+ /**
37
+ * - Infer arguments output type.
38
+ *
39
+ * @example
40
+ * const myCommand = defineSubcommand({ name: "my-command", arguments: [...] });
41
+ * type MyCommandArgumentsOutput = InferArgumentsOutputType<typeof myCommand>;
42
+ */
43
+ export type InferArgumentsOutputType<T extends Cli | Subcommand> =
44
+ T["arguments"] extends Record<string, Argument> ? ArgumentsOutputType<T["arguments"]> : undefined;
45
+
46
+ /**
47
+ * - Infer arguments input type.
48
+ *
49
+ * @example
50
+ * const myCommand = defineSubcommand({ name: "my-command", arguments: [...] });
51
+ * type MyCommandArgumentsInput = InferArgumentsInputType<typeof myCommand>;
52
+ */
53
+ export type InferArgumentsInputType<T extends Cli | Subcommand> =
54
+ T["arguments"] extends Record<string, Argument> ? ArgumentsInputType<T["arguments"]> : undefined;
55
+
56
+ /**
57
+ * - Infer options input type.
58
+ *
59
+ * @example
60
+ * const myCommand = defineSubcommand({ name: "my-command", options: [...] });
61
+ * type MyCommandOptionsInput = inferOptionsInputType<typeof myCommand>;
62
+ */
63
+ export type inferOptionsInputType<T extends Cli | Subcommand> =
64
+ T["options"] extends Record<string, Option> ? OptionsInputType<T["options"]> : undefined;
65
+
66
+ /**
67
+ * - Infer options, arguments, and positionals input types from the CLI/subcommand definition.
68
+ *
69
+ * @example
70
+ * const myCommand = defineSubcommand({ name: "my-command", ... });
71
+ * type MyCommandInput = InferInputType<typeof myCommand>;
72
+ */
73
+ export type InferInputType<T extends Cli | Subcommand> = Prettify<
74
+ // Add undefined if all properties are optional
75
+ AddUndefinedIfAllOptional<
76
+ // Make properties that can be undefined optional
77
+ ToOptional<{
78
+ positionals: T["allowPositionals"] extends true ? string[] : undefined;
79
+
80
+ options: T["options"] extends Record<string, Option>
81
+ ? // Add undefined if all properties are optional
82
+ AddUndefinedIfAllOptional<
83
+ // Options types as record
84
+ OptionsInputType<T["options"]>
85
+ >
86
+ : undefined;
87
+
88
+ arguments: T["arguments"] extends Record<string, Argument>
89
+ ? // Add undefined if all properties are optional
90
+ AddUndefinedIfAllOptional<
91
+ // Arguments types as record
92
+ ArgumentsInputType<T["arguments"]>
93
+ >
94
+ : undefined;
95
+ }>
96
+ >
97
+ >;
98
+
99
+ export interface InputTypeWide {
100
+ arguments?: Record<string, unknown>;
101
+ options?: Record<string, unknown>;
102
+ positionals?: string[];
103
+ }
104
+
105
+ /**
106
+ * - Infer schema output type.
107
+ *
108
+ * @example
109
+ * const myCommand = defineSubcommand({ name: "my-command", ... });
110
+ * type MyCommandOutput = InferOutputType<typeof myCommand>;
111
+ */
112
+ export type InferOutputType<T extends Cli | Subcommand> = Prettify<{
113
+ subcommand: "name" extends keyof T ? T["name"] : undefined;
114
+ options: T["options"] extends Record<string, Option> ? OptionsOutputType<T["options"]> : never;
115
+ arguments: T["arguments"] extends Record<string, Argument> ? ArgumentsOutputType<T["arguments"]> : never;
116
+ positionals: T["allowPositionals"] extends true ? string[] : never;
117
+ context: Context<[T]>;
118
+ }>;
119
+
120
+ /** Same as `InferOutputType` but for multiple subcommands/cli */
121
+ export type OutputType<S extends readonly (Cli | Subcommand)[]> = {
122
+ [K in keyof S]: InferOutputType<S[K]>;
123
+ }[number];
124
+
125
+ export interface OutputTypeWide {
126
+ subcommand: string | undefined;
127
+ positionals?: string[];
128
+ arguments?: Record<string, unknown>;
129
+ options?: Record<string, unknown>;
130
+ context: ContextWide;
131
+ }
@@ -0,0 +1,104 @@
1
+ import type { SchemaType } from "./schema-types.ts";
2
+
3
+ interface MetadataBase {
4
+ /** Empty string if not provided */
5
+ description: string;
6
+
7
+ /** Empty string if not provided */
8
+ descriptionMarkdown: string;
9
+
10
+ /** Empty string if not provided */
11
+ example: string;
12
+
13
+ /** Whether the metadata is hidden from the documentation. */
14
+ hidden: boolean;
15
+ }
16
+
17
+ export interface CliMetadata extends Omit<MetadataBase, "hidden"> {
18
+ /** The name of the cli program. */
19
+ name: string;
20
+
21
+ /** Empty string if not provided */
22
+ usage: string;
23
+
24
+ /** Whether the cli program allows positionals arguments. */
25
+ allowPositionals: boolean;
26
+
27
+ /** Empty array if not provided */
28
+ options: OptionMetadata[];
29
+
30
+ /** Empty array if not provided */
31
+ arguments: ArgumentMetadata[];
32
+
33
+ /** Empty array if not provided */
34
+ subcommands: SubcommandMetadata[];
35
+ }
36
+
37
+ export interface SubcommandMetadata extends MetadataBase {
38
+ /** The subcommand name. */
39
+ name: string;
40
+
41
+ /** Empty array if not provided */
42
+ aliases: string[];
43
+
44
+ /** Empty string if not provided */
45
+ placeholder: string;
46
+
47
+ /** Empty string if not provided */
48
+ usage: string;
49
+
50
+ /** Whether the subcommand allows positionals arguments. */
51
+ allowPositionals: boolean;
52
+
53
+ /** Empty array if not provided */
54
+ options: OptionMetadata[];
55
+
56
+ /** Empty array if not provided */
57
+ arguments: ArgumentMetadata[];
58
+ }
59
+
60
+ export interface OptionMetadata extends MetadataBase {
61
+ /** The option name. */
62
+ name: string;
63
+
64
+ /** The option name as argument. E.g. `--option-name` */
65
+ nameAsArg: string;
66
+
67
+ /** Empty array if not provided. */
68
+ aliases: string[];
69
+
70
+ /** Empty array if not provided. E.g. `[--alias-name, ...]` */
71
+ aliasesAsArgs: string[];
72
+
73
+ /** Empty string if not provided */
74
+ placeholder: string;
75
+
76
+ /** The default value of the option. */
77
+ defaultValue: unknown;
78
+
79
+ /** Empty string if not provided. */
80
+ defaultValueAsString: string;
81
+
82
+ /** Is optional. */
83
+ optional: boolean;
84
+
85
+ /** Standard Schema V1. */
86
+ schema: SchemaType;
87
+ }
88
+
89
+ export interface ArgumentMetadata extends MetadataBase {
90
+ /** The argument name. */
91
+ name: string;
92
+
93
+ /** The default value of the argument. */
94
+ defaultValue: unknown;
95
+
96
+ /** The default value of the argument as string. */
97
+ defaultValueAsString: string;
98
+
99
+ /** Is optional. */
100
+ optional: boolean;
101
+
102
+ /** Standard Schema V1. */
103
+ schema: SchemaType;
104
+ }
@@ -0,0 +1,9 @@
1
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
2
+
3
+ export type SchemaType<T = unknown> = StandardSchemaV1<T>;
4
+
5
+ export type InferSchemaInputType<T extends SchemaType> = StandardSchemaV1.InferInput<T>;
6
+
7
+ export type InferSchemaOutputType<T extends SchemaType> = StandardSchemaV1.InferOutput<T>;
8
+
9
+ export type SchemaResult<T = unknown> = StandardSchemaV1.Result<T>;
@@ -0,0 +1,72 @@
1
+ import type { Cli, Subcommand } from "./definitions-types.ts";
2
+ import type { PrintHelpOptions } from "./help-message-types.ts";
3
+ import type { InferInputType, InputTypeWide, OutputType, OutputTypeWide } from "./io-types.ts";
4
+
5
+ type PrimitiveTypeNames = "string" | "number" | "boolean" | "object" | "unknown";
6
+ export type CoerceTypes = PrimitiveTypeNames | `${PrimitiveTypeNames}[]` | `set<${PrimitiveTypeNames}>` | (string & {});
7
+
8
+ export interface CoerceMethod<Value> {
9
+ (terminalInput: string): Value;
10
+ type?: CoerceTypes;
11
+ }
12
+
13
+ type GetSubcommandsNames<T extends Partial<Subcommand>> = T extends Cli
14
+ ? T["subcommands"] extends infer S extends readonly [Subcommand, ...Subcommand[]]
15
+ ? { [Index in keyof S]: S[Index] extends { name: string } ? S[Index]["name"] : never }[number]
16
+ : never
17
+ : never;
18
+
19
+ type Unsubscribe = () => void;
20
+
21
+ export interface AttachedMethods<T extends Cli | Subcommand> {
22
+ /**
23
+ * Add a handler to be called when the subcommand/cli is executed.
24
+ *
25
+ * @example
26
+ * const unsubscribe = cli.onExecute(result => console.log(result));
27
+ */
28
+ onExecute: (handler: (data: OutputType<[T]>) => void) => Unsubscribe;
29
+
30
+ // Make the argument optional if it has undefined type
31
+ execute: InferInputType<T> extends infer InputType
32
+ ? undefined extends InputType
33
+ ? (input?: InputType) => void
34
+ : (input: InputType) => void
35
+ : never;
36
+
37
+ /** **WARNING**: This will only be available after the CLI schema has been created */
38
+ generateCliHelpMessage?: (options?: PrintHelpOptions) => string;
39
+
40
+ /**
41
+ * **WARNING**: This will only be available after the CLI schema has been created
42
+ *
43
+ * @throws {Error} - When the subcommand is not found
44
+ */
45
+ generateSubcommandHelpMessage?: (
46
+ subcommandName: GetSubcommandsNames<T> | (string & {}),
47
+ options?: PrintHelpOptions,
48
+ ) => string;
49
+ }
50
+
51
+ export interface AttachedMethodsWide {
52
+ onExecute: (handler: (data: OutputTypeWide) => void) => Unsubscribe;
53
+ execute: (input?: InputTypeWide) => void;
54
+ generateCliHelpMessage?: (options?: PrintHelpOptions) => void;
55
+ /** @throws {Error} - When the subcommand is not found */
56
+ generateSubcommandHelpMessage?: (subcommandName: string, options?: PrintHelpOptions) => void;
57
+ }
58
+
59
+ export type CliOutputType<S extends Cli> =
60
+ | OutputType<[S]>
61
+ | (S["subcommands"] extends readonly [Subcommand, ...Subcommand[]] ? OutputType<S["subcommands"]> : never);
62
+
63
+ export type CliParseResult<S extends Cli> =
64
+ | { value: CliOutputType<S>; error?: undefined }
65
+ | { value?: never; error: Error };
66
+
67
+ export type CliParseResultWide = { value: OutputTypeWide; error?: undefined } | { value?: never; error: Error };
68
+
69
+ export interface ValidateMethods<S extends Cli> {
70
+ run(input: string | string[]): CliParseResult<S>;
71
+ runAsync(input: string | string[]): Promise<CliParseResult<S>>;
72
+ }
@@ -0,0 +1,26 @@
1
+ /** `{ some props } & { other props }` => `{ some props, other props }` */
2
+ export type Prettify<T> = { [K in keyof T]: T[K] } & {};
3
+
4
+ /** Extract the undefined properties from an object */
5
+ export type UndefinedProperties<T> = { [P in keyof T]-?: undefined extends T[P] ? P : never }[keyof T];
6
+
7
+ /** Make undefined properties optional? */
8
+ export type ToOptional<T> = Partial<Pick<T, UndefinedProperties<T>>> &
9
+ Pick<T, Exclude<keyof T, UndefinedProperties<T>>>;
10
+
11
+ /** If every property in a record is optional, widen the type to `T | undefined`. */
12
+ export type AllowUndefinedIfOptional<T> = {
13
+ [K in keyof T]-?: object extends Pick<T, K> ? never : K;
14
+ }[keyof T] extends never
15
+ ? T | undefined
16
+ : T;
17
+
18
+ /** Widen literal and tuples */
19
+ // prettier-ignore
20
+ export type Widen<T> =
21
+ T extends string ? string :
22
+ T extends number ? number :
23
+ T extends boolean ? boolean :
24
+ T extends readonly (infer U)[] ? Widen<U>[] :
25
+ T extends Set<infer U> ? Set<Widen<U>> :
26
+ T;
package/src/utilities.ts CHANGED
@@ -1,21 +1,56 @@
1
- import { SubcommandMetadata } from "./metadata/metadata-types.js";
1
+ import type { Argument, Option, PreparedType } from "./types/definitions-types.ts";
2
+ import type { SubcommandMetadata } from "./types/metadata-types.ts";
3
+ import type { SchemaResult, SchemaType } from "./types/schema-types.ts";
4
+ import type { CoerceMethod } from "./types/types.ts";
2
5
 
3
- /**
4
- * Converts a string to its corresponding boolean value if the string is "true" or "false" (case-insensitive).
5
- *
6
- * @param string - The input string to convert.
7
- * @returns `true` if the input is "true", `false` if the input is "false", or the original string otherwise.
8
- */
9
- export function stringToBoolean(string: string): boolean | string {
10
- if (string.toLowerCase() === "true") {
11
- return true;
6
+ /** @throws */
7
+ export function validateSync(schema: SchemaType, value?: unknown): SchemaResult {
8
+ const results = schema["~standard"].validate(value);
9
+ if (results instanceof Promise) {
10
+ throw new TypeError("async schema validation not supported");
12
11
  }
13
12
 
14
- if (string.toLowerCase() === "false") {
15
- return false;
13
+ return results;
14
+ }
15
+
16
+ export function defaultValueAndIsOptional(schema: SchemaType): { defaultValue: unknown; optional: boolean } {
17
+ const results = validateSync(schema);
18
+
19
+ if (results.issues) {
20
+ return { defaultValue: undefined, optional: false };
21
+ }
22
+
23
+ return { defaultValue: results.value, optional: true };
24
+ }
25
+
26
+ export function PrepareType(schema: SchemaType, coerceHandler: CoerceMethod<unknown>): PreparedType {
27
+ const { optional, defaultValue } = defaultValueAndIsOptional(schema);
28
+
29
+ return {
30
+ schema,
31
+ optional,
32
+ defaultValue,
33
+ coerceTo: coerceHandler.type,
34
+ validate: (value?: string) => validateSync(schema, value && coerceHandler(value)),
35
+ };
36
+ }
37
+
38
+ export function prepareDefinitionTypes(definition: Record<string, Argument> | Record<string, Option> | undefined) {
39
+ if (!definition) return;
40
+
41
+ for (const object of Object.values<Argument | Option>(definition)) {
42
+ if (!object.coerce) {
43
+ object.coerce = (value: string) => value;
44
+ }
45
+
46
+ if (!object._preparedType) {
47
+ object._preparedType = PrepareType(object.schema, object.coerce);
48
+ }
16
49
  }
50
+ }
17
51
 
18
- return string;
52
+ export function toKebabCase(input: string): string {
53
+ return input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
19
54
  }
20
55
 
21
56
  /**
@@ -68,10 +103,9 @@ export function indent(count: number) {
68
103
  return " ".repeat(count);
69
104
  }
70
105
 
71
- /** Concat strings */
72
- export function concat(...messages: string[]) {
73
- // messages = messages.filter(Boolean);
74
- return messages.join(" ");
106
+ /** Indents every line in the given text by the provided number of spaces. Empty lines are preserved. */
107
+ export function indentLines(text: string, spaces: number): string {
108
+ return text.replace(/\n/g, "\n" + indent(spaces));
75
109
  }
76
110
 
77
111
  export function stringifyValue(value: unknown): string {
@@ -93,7 +127,7 @@ export function stringifyValue(value: unknown): string {
93
127
  /** Insert text at the end of the first line */
94
128
  export function insertAtEndOfFirstLine(string: string, insert: string) {
95
129
  const lines = string.split("\n");
96
- lines[0] += " " + insert;
130
+ lines[0] += (lines[0] ? " " : "") + insert;
97
131
  return lines.join("\n");
98
132
  }
99
133
 
@@ -101,15 +135,19 @@ export function insertAtEndOfFirstLine(string: string, insert: string) {
101
135
  export function subcommandPlaceholder(metadata: SubcommandMetadata): string {
102
136
  let placeholder = metadata.placeholder;
103
137
 
104
- if (!placeholder && metadata.options.length > 0) {
105
- placeholder = "[options]";
138
+ if (placeholder) {
139
+ return placeholder;
106
140
  }
107
141
 
108
- if (!placeholder && metadata.arguments.length > 0) {
109
- placeholder = "<arguments>";
142
+ if (metadata.options.length > 0) {
143
+ placeholder += (placeholder ? " " : "") + "[options]";
110
144
  }
111
145
 
112
- if (metadata.allowPositional) {
146
+ if (metadata.arguments.length > 0) {
147
+ placeholder += (placeholder ? " " : "") + "<arguments>";
148
+ }
149
+
150
+ if (metadata.allowPositionals) {
113
151
  placeholder += (placeholder ? " " : "") + "<positionals>";
114
152
  }
115
153
 
@@ -119,3 +157,142 @@ export function subcommandPlaceholder(metadata: SubcommandMetadata): string {
119
157
 
120
158
  return placeholder;
121
159
  }
160
+
161
+ /** Parse a string into an argv (array of arguments) */
162
+ export function parseArgv(input: string): string[] {
163
+ const argv = [];
164
+
165
+ let currentQuote: string | undefined = undefined;
166
+ let currentArgument: string | undefined = undefined;
167
+
168
+ for (let index = 0; index < input.length; index++) {
169
+ const char = input[index];
170
+ const previousChar = input[index - 1];
171
+ const nextChar = input[index + 1];
172
+ const end = index === input.length - 1;
173
+
174
+ // entering/leaving quote
175
+ if ((char === '"' || char === "'") && previousChar !== "\\") {
176
+ // leaving quote
177
+ if (currentQuote === char) {
178
+ currentQuote = undefined;
179
+ continue;
180
+ }
181
+
182
+ // entering quote
183
+ if (currentQuote === undefined) {
184
+ currentQuote = char;
185
+ continue;
186
+ }
187
+
188
+ // quote inside quote
189
+ if (currentQuote !== undefined && char !== currentQuote) {
190
+ currentArgument += char;
191
+ continue;
192
+ }
193
+ continue;
194
+ }
195
+
196
+ // new line
197
+ if (char === "\\" && nextChar === "\n") {
198
+ index++;
199
+ continue;
200
+ }
201
+
202
+ // Add to argv
203
+ if (currentArgument !== undefined && currentQuote === undefined) {
204
+ if (char === " ") {
205
+ argv.push(currentArgument);
206
+ currentArgument = undefined;
207
+ continue;
208
+ }
209
+
210
+ if (end) {
211
+ currentArgument += char;
212
+ argv.push(currentArgument);
213
+ currentArgument = undefined;
214
+ continue;
215
+ }
216
+ }
217
+
218
+ // Ignore spaces outside of quotes
219
+ if (char === " " && currentQuote === undefined) {
220
+ continue;
221
+ }
222
+
223
+ // Ignore escaped characters
224
+ if (char === "\\" && (nextChar === "'" || nextChar === '"')) {
225
+ continue;
226
+ }
227
+
228
+ currentArgument ??= "";
229
+ currentArgument += char;
230
+ }
231
+
232
+ // Add last argument
233
+ if (currentArgument !== undefined) {
234
+ argv.push(currentArgument);
235
+ }
236
+
237
+ return argv;
238
+ }
239
+
240
+ /**
241
+ * Escape HTML characters inside HTML tags in a Markdown string, but leave code blocks, inline code, and HTML comments
242
+ * unchanged.
243
+ */
244
+ export function escapeHtmlTags(markdown: string): string {
245
+ const escapeMap: Record<string, string> = { "&": "&amp;", "<": "&lt;", ">": "&gt;" };
246
+
247
+ // Captures:
248
+ // 1) fenced code blocks or inline code
249
+ // 2) HTML comments <!-- ... -->
250
+ // 3) other HTML tags like <b>, <div attr="x">, etc.
251
+ const re = /(```[\s\S]*?```|`[^`]*`)|(<!--[\s\S]*?-->)|(<[^>]+>)/g;
252
+
253
+ return markdown.replace(re, (fullMatch: string, code?: string, comment?: string, tag?: string) => {
254
+ if (code) return code;
255
+ if (comment) return comment;
256
+ if (!tag) return fullMatch;
257
+
258
+ return tag.replace(/[&<>]/g, ch => escapeMap[ch]);
259
+ });
260
+ }
261
+
262
+ /** Credits: https://github.com/chalk/ansi-regex */
263
+ function ansiRegex({ onlyFirst = false } = {}) {
264
+ // Valid string terminator sequences are BEL, ESC\, and 0x9c
265
+ const ST = String.raw`(?:\u0007|\u001B\u005C|\u009C)`;
266
+
267
+ // OSC sequences only: ESC ] ... ST (non-greedy until the first ST)
268
+ const osc = String.raw`(?:\u001B\][\s\S]*?${ST})`;
269
+
270
+ // CSI and related: ESC/C1, optional intermediates, optional params (supports ; and :) then final byte
271
+ const csi = String.raw`[\u001B\u009B][[\]()#;?]*(?:\d{1,4}(?:[;:]\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]`;
272
+
273
+ const pattern = `${osc}|${csi}`;
274
+
275
+ return new RegExp(pattern, onlyFirst ? undefined : "g");
276
+ }
277
+
278
+ const regex = ansiRegex();
279
+
280
+ export function stripAnsi(string: string): string {
281
+ return string.replace(regex, "");
282
+ }
283
+
284
+ export function findDuplicateStrings(values: readonly string[]): string[] {
285
+ const seen = new Set<string>();
286
+ const duplicates = new Set<string>();
287
+
288
+ for (const value of values) {
289
+ if (seen.has(value)) {
290
+ duplicates.add(value);
291
+ continue;
292
+ }
293
+
294
+ seen.add(value);
295
+ }
296
+
297
+ return Array.from(duplicates);
298
+ }
@@ -1,42 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.generateBashAutocompleteScript=generateBashAutocompleteScript;var _parserHelpers=require("../parser/parse/parser-helpers.cjs");function generateBashAutocompleteScript(...parameters){const[cli,...subcommands]=parameters;const mappedCommands={};for(const subcommand of subcommands){mappedCommands[subcommand.name]={options:subcommand.options?.map(option=>(0,_parserHelpers.transformOptionToArgument)(option.name))??[],aliases:subcommand.aliases??[]}}let switchCase="";for(const[key,{options,aliases}]of Object.entries(mappedCommands)){switchCase+=` ${key}${aliases.length>0?"|":""}${aliases.join("|")})\n`;switchCase+=` opts="${options.join(" ")}"\n`;switchCase+=" ;;\n"}if(cli.options?.length){switchCase+=` "-"*)\n`;switchCase+=` opts="${cli.options.map(option=>(0,_parserHelpers.transformOptionToArgument)(option.name)).join(" ")}"\n`;switchCase+=" ;;\n"}return`# Auto-generated by zod-args-parser
2
-
3
- _${cli.cliName}_autocomplete() {
4
- local cur prev commands opts subcommand used_opts filtered_opts
5
-
6
- cur="\${COMP_WORDS[COMP_CWORD]}"
7
- prev="\${COMP_WORDS[COMP_CWORD-1]}"
8
- subcommand="\${COMP_WORDS[1]}"
9
-
10
- commands="${Object.keys(mappedCommands).join(" ")}"
11
-
12
- case "$subcommand" in
13
- ${switchCase}
14
- esac
15
-
16
- used_opts=""
17
- if [[ " \${commands[@]} " =~ " $subcommand " ]]; then
18
- for word in "\${COMP_WORDS[@]:2}"; do
19
- if [[ "$word" =~ ^- ]]; then
20
- used_opts+=" $word"
21
- fi
22
- done
23
- fi
24
-
25
- if [[ -n "$opts" ]]; then
26
- filtered_opts=""
27
- for opt in $opts; do
28
- if [[ ! " $used_opts " =~ " $opt " ]]; then
29
- filtered_opts+="$opt "
30
- fi
31
- done
32
- COMPREPLY=( $(compgen -W "$filtered_opts" -- "$cur") )
33
- return
34
- fi
35
-
36
- if [[ "\${COMP_CWORD}" -eq 1 ]]; then
37
- COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
38
- fi
39
- }
40
-
41
- complete -F _${cli.cliName}_autocomplete ${cli.cliName}
42
- `}
@@ -1 +0,0 @@
1
- {"version":3,"names":["_parserHelpers","require","generateBashAutocompleteScript","parameters","cli","subcommands","mappedCommands","subcommand","name","options","map","option","transformOptionToArgument","aliases","switchCase","key","Object","entries","length","join","cliName","keys"],"sourceRoot":"../../../src/autocomplete-scripts","sources":["bash-autocomplete-script.ts"],"sourcesContent":["import { transformOptionToArgument } from \"../parser/parse/parser-helpers.js\";\n\nimport type { Cli, Subcommand } from \"../types.js\";\n\n/**\n * - Generate bash autocomplete script for your CLI\n * - The generated script should be added to your `.bash_profile` or `.bashrc` file:\n *\n * - Run: `nano $HOME/.bash_profile` or `nano $HOME/.bashrc`\n * - Add the following line: `source <generated script path>`\n * - Save and reopen bash to take effect\n */\nexport function generateBashAutocompleteScript(...parameters: [Cli, ...Subcommand[]]): string {\n const [cli, ...subcommands] = parameters;\n\n type MappedCommands = Record<string, { options: string[]; aliases: string[] }>;\n\n const mappedCommands: MappedCommands = {};\n for (const subcommand of subcommands) {\n mappedCommands[subcommand.name] = {\n options: subcommand.options?.map(option => transformOptionToArgument(option.name)) ?? [],\n aliases: subcommand.aliases ?? [],\n };\n }\n\n let switchCase = \"\";\n for (const [key, { options, aliases }] of Object.entries(mappedCommands)) {\n switchCase += ` ${key}${aliases.length > 0 ? \"|\" : \"\"}${aliases.join(\"|\")})\\n`;\n switchCase += ` opts=\"${options.join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n if (cli.options?.length) {\n switchCase += ` \"-\"*)\\n`;\n switchCase += ` opts=\"${cli.options.map(option => transformOptionToArgument(option.name)).join(\" \")}\"\\n`;\n switchCase += \" ;;\\n\";\n }\n\n return `# Auto-generated by zod-args-parser\n\n_${cli.cliName}_autocomplete() {\n local cur prev commands opts subcommand used_opts filtered_opts\n\n cur=\"\\${COMP_WORDS[COMP_CWORD]}\"\n prev=\"\\${COMP_WORDS[COMP_CWORD-1]}\"\n subcommand=\"\\${COMP_WORDS[1]}\"\n\n commands=\"${Object.keys(mappedCommands).join(\" \")}\"\n\n case \"$subcommand\" in\n${switchCase}\n esac\n\n used_opts=\"\"\n if [[ \" \\${commands[@]} \" =~ \" $subcommand \" ]]; then\n for word in \"\\${COMP_WORDS[@]:2}\"; do\n if [[ \"$word\" =~ ^- ]]; then\n used_opts+=\" $word\"\n fi\n done\n fi\n\n if [[ -n \"$opts\" ]]; then\n filtered_opts=\"\"\n for opt in $opts; do\n if [[ ! \" $used_opts \" =~ \" $opt \" ]]; then\n filtered_opts+=\"$opt \"\n fi\n done\n COMPREPLY=( $(compgen -W \"$filtered_opts\" -- \"$cur\") )\n return\n fi\n\n if [[ \"\\${COMP_CWORD}\" -eq 1 ]]; then\n COMPREPLY=( $(compgen -W \"$commands\" -- \"$cur\") )\n fi\n}\n\ncomplete -F _${cli.cliName}_autocomplete ${cli.cliName}\n`;\n}\n"],"mappings":"4IAAA,IAAAA,cAAA,CAAAC,OAAA,uCAYO,QAAS,CAAAC,8BAA8BA,CAAC,GAAGC,UAAkC,CAAU,CAC5F,KAAM,CAACC,GAAG,CAAE,GAAGC,WAAW,CAAC,CAAGF,UAAU,CAIxC,KAAM,CAAAG,cAA8B,CAAG,CAAC,CAAC,CACzC,IAAK,KAAM,CAAAC,UAAU,GAAI,CAAAF,WAAW,CAAE,CACpCC,cAAc,CAACC,UAAU,CAACC,IAAI,CAAC,CAAG,CAChCC,OAAO,CAAEF,UAAU,CAACE,OAAO,EAAEC,GAAG,CAACC,MAAM,EAAI,GAAAC,wCAAyB,EAACD,MAAM,CAACH,IAAI,CAAC,CAAC,EAAI,EAAE,CACxFK,OAAO,CAAEN,UAAU,CAACM,OAAO,EAAI,EACjC,CACF,CAEA,GAAI,CAAAC,UAAU,CAAG,EAAE,CACnB,IAAK,KAAM,CAACC,GAAG,CAAE,CAAEN,OAAO,CAAEI,OAAQ,CAAC,CAAC,EAAI,CAAAG,MAAM,CAACC,OAAO,CAACX,cAAc,CAAC,CAAE,CACxEQ,UAAU,EAAI,OAAOC,GAAG,GAAGF,OAAO,CAACK,MAAM,CAAG,CAAC,CAAG,GAAG,CAAG,EAAE,GAAGL,OAAO,CAACM,IAAI,CAAC,GAAG,CAAC,KAAK,CACjFL,UAAU,EAAI,eAAeL,OAAO,CAACU,IAAI,CAAC,GAAG,CAAC,KAAK,CACnDL,UAAU,EAAI,YAChB,CAEA,GAAIV,GAAG,CAACK,OAAO,EAAES,MAAM,CAAE,CACvBJ,UAAU,EAAI,aAAa,CAC3BA,UAAU,EAAI,eAAeV,GAAG,CAACK,OAAO,CAACC,GAAG,CAACC,MAAM,EAAI,GAAAC,wCAAyB,EAACD,MAAM,CAACH,IAAI,CAAC,CAAC,CAACW,IAAI,CAAC,GAAG,CAAC,KAAK,CAC7GL,UAAU,EAAI,YAChB,CAEA,MAAO;AACT;AACA,GAAGV,GAAG,CAACgB,OAAO;AACd;AACA;AACA;AACA;AACA;AACA;AACA,cAAcJ,MAAM,CAACK,IAAI,CAACf,cAAc,CAAC,CAACa,IAAI,CAAC,GAAG,CAAC;AACnD;AACA;AACA,EAAEL,UAAU;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeV,GAAG,CAACgB,OAAO,iBAAiBhB,GAAG,CAACgB,OAAO;AACtD,CACA","ignoreList":[]}