zod-args-parser 2.0.0-beta.1 → 2.0.0-beta.3

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 (474) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +244 -282
  3. package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js +74 -2
  4. package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js.map +7 -1
  5. package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js +90 -2
  6. package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js.map +7 -1
  7. package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js +39 -13
  8. package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js.map +7 -1
  9. package/lib/esm/cli-error/cli-error.js +38 -0
  10. package/lib/esm/cli-error/cli-error.js.map +7 -0
  11. package/lib/esm/cli-error/error-cause.js +12 -0
  12. package/lib/esm/cli-error/error-cause.js.map +7 -0
  13. package/lib/esm/cli-error/error-code/definition-error-code.js +23 -0
  14. package/lib/esm/cli-error/error-code/definition-error-code.js.map +7 -0
  15. package/lib/esm/cli-error/error-code/internal-error-code.js +10 -0
  16. package/lib/esm/cli-error/error-code/internal-error-code.js.map +7 -0
  17. package/lib/esm/cli-error/error-code/parse-error-code.js +18 -0
  18. package/lib/esm/cli-error/error-code/parse-error-code.js.map +7 -0
  19. package/lib/esm/cli-error/error-code/validation-error-code.js +17 -0
  20. package/lib/esm/cli-error/error-code/validation-error-code.js.map +7 -0
  21. package/lib/esm/cli-error/error-message/definition-error-message.js +70 -0
  22. package/lib/esm/cli-error/error-message/definition-error-message.js.map +7 -0
  23. package/lib/esm/cli-error/error-message/internal-error-message.js +16 -0
  24. package/lib/esm/cli-error/error-message/internal-error-message.js.map +7 -0
  25. package/lib/esm/cli-error/error-message/parse-error-message.js +40 -0
  26. package/lib/esm/cli-error/error-message/parse-error-message.js.map +7 -0
  27. package/lib/esm/cli-error/error-message/validation-error-message.js +60 -0
  28. package/lib/esm/cli-error/error-message/validation-error-message.js.map +7 -0
  29. package/lib/esm/coerce/coerce-methods.js +197 -2
  30. package/lib/esm/coerce/coerce-methods.js.map +7 -1
  31. package/lib/esm/coerce/string-to-array.js +17 -2
  32. package/lib/esm/coerce/string-to-array.js.map +7 -1
  33. package/lib/esm/coerce/string-to-primitive.js +73 -2
  34. package/lib/esm/coerce/string-to-primitive.js.map +7 -1
  35. package/lib/esm/coerce/string-to-set.js +17 -2
  36. package/lib/esm/coerce/string-to-set.js.map +7 -1
  37. package/lib/esm/definitions/define-arguments.js +10 -2
  38. package/lib/esm/definitions/define-arguments.js.map +7 -1
  39. package/lib/esm/definitions/define-cli.js +89 -2
  40. package/lib/esm/definitions/define-cli.js.map +7 -1
  41. package/lib/esm/definitions/define-options.js +10 -2
  42. package/lib/esm/definitions/define-options.js.map +7 -1
  43. package/lib/esm/definitions/define-subcommand.js +56 -2
  44. package/lib/esm/definitions/define-subcommand.js.map +7 -1
  45. package/lib/esm/definitions/validate-cli-definition.js +360 -2
  46. package/lib/esm/definitions/validate-cli-definition.js.map +7 -1
  47. package/lib/esm/help-message/format-arguments.js +48 -2
  48. package/lib/esm/help-message/format-arguments.js.map +7 -1
  49. package/lib/esm/help-message/format-options.js +50 -2
  50. package/lib/esm/help-message/format-options.js.map +7 -1
  51. package/lib/esm/help-message/format-subcommands.js +37 -2
  52. package/lib/esm/help-message/format-subcommands.js.map +7 -1
  53. package/lib/esm/help-message/generate-for-cli.js +71 -2
  54. package/lib/esm/help-message/generate-for-cli.js.map +7 -1
  55. package/lib/esm/help-message/generate-for-subcommand.js +23 -2
  56. package/lib/esm/help-message/generate-for-subcommand.js.map +7 -1
  57. package/lib/esm/help-message/print-help.js +14 -2
  58. package/lib/esm/help-message/print-help.js.map +7 -1
  59. package/lib/esm/help-message/set-defaults.js +29 -2
  60. package/lib/esm/help-message/set-defaults.js.map +7 -1
  61. package/lib/esm/help-message/styles.js +154 -2
  62. package/lib/esm/help-message/styles.js.map +7 -1
  63. package/lib/esm/help-message/terminal-markdown.js +121 -2
  64. package/lib/esm/help-message/terminal-markdown.js.map +7 -1
  65. package/lib/esm/index.js +52 -2
  66. package/lib/esm/index.js.map +7 -1
  67. package/lib/esm/markdown/generate-markdown.js +153 -2
  68. package/lib/esm/markdown/generate-markdown.js.map +7 -1
  69. package/lib/esm/metadata/arguments-metadata.js +26 -2
  70. package/lib/esm/metadata/arguments-metadata.js.map +7 -1
  71. package/lib/esm/metadata/cli-metadata.js +24 -2
  72. package/lib/esm/metadata/cli-metadata.js.map +7 -1
  73. package/lib/esm/metadata/options-metadata.js +35 -2
  74. package/lib/esm/metadata/options-metadata.js.map +7 -1
  75. package/lib/esm/metadata/subcommands-metadata.js +32 -2
  76. package/lib/esm/metadata/subcommands-metadata.js.map +7 -1
  77. package/lib/esm/parse/context/cli-context-builder.js +283 -2
  78. package/lib/esm/parse/context/cli-context-builder.js.map +7 -1
  79. package/lib/esm/parse/context/object-context-builder.js +62 -2
  80. package/lib/esm/parse/context/object-context-builder.js.map +7 -1
  81. package/lib/esm/parse/parser-utilities.js +108 -2
  82. package/lib/esm/parse/parser-utilities.js.map +7 -1
  83. package/lib/esm/parse/safe-parse.js +57 -2
  84. package/lib/esm/parse/safe-parse.js.map +7 -1
  85. package/lib/esm/parse/validation/validate-context.js +17 -2
  86. package/lib/esm/parse/validation/validate-context.js.map +7 -1
  87. package/lib/esm/parse/validation/validators/arguments.js +67 -2
  88. package/lib/esm/parse/validation/validators/arguments.js.map +7 -1
  89. package/lib/esm/parse/validation/validators/conflict.js +38 -2
  90. package/lib/esm/parse/validation/validators/conflict.js.map +7 -1
  91. package/lib/esm/parse/validation/validators/exclusive.js +39 -2
  92. package/lib/esm/parse/validation/validators/exclusive.js.map +7 -1
  93. package/lib/esm/parse/validation/validators/explicitly-passed.js +18 -2
  94. package/lib/esm/parse/validation/validators/explicitly-passed.js.map +7 -1
  95. package/lib/esm/parse/validation/validators/options.js +67 -2
  96. package/lib/esm/parse/validation/validators/options.js.map +7 -1
  97. package/lib/esm/parse/validation/validators/requires.js +43 -2
  98. package/lib/esm/parse/validation/validators/requires.js.map +7 -1
  99. package/lib/esm/utilities/parse-argv.js +61 -0
  100. package/lib/esm/utilities/parse-argv.js.map +7 -0
  101. package/lib/esm/utilities/schema-utilities.js +57 -0
  102. package/lib/esm/utilities/schema-utilities.js.map +7 -0
  103. package/lib/esm/utilities/utilities.js +122 -0
  104. package/lib/esm/utilities/utilities.js.map +7 -0
  105. package/lib/iife/index.js +41 -1
  106. package/lib/iife/index.js.map +1 -1
  107. package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs +74 -2
  108. package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs.map +7 -1
  109. package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs +90 -2
  110. package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs.map +7 -1
  111. package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs +39 -13
  112. package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs.map +7 -1
  113. package/lib/mjs/cli-error/cli-error.mjs +38 -0
  114. package/lib/mjs/cli-error/cli-error.mjs.map +7 -0
  115. package/lib/mjs/cli-error/error-cause.mjs +12 -0
  116. package/lib/mjs/cli-error/error-cause.mjs.map +7 -0
  117. package/lib/mjs/cli-error/error-code/definition-error-code.mjs +23 -0
  118. package/lib/mjs/cli-error/error-code/definition-error-code.mjs.map +7 -0
  119. package/lib/mjs/cli-error/error-code/internal-error-code.mjs +10 -0
  120. package/lib/mjs/cli-error/error-code/internal-error-code.mjs.map +7 -0
  121. package/lib/mjs/cli-error/error-code/parse-error-code.mjs +18 -0
  122. package/lib/mjs/cli-error/error-code/parse-error-code.mjs.map +7 -0
  123. package/lib/mjs/cli-error/error-code/validation-error-code.mjs +17 -0
  124. package/lib/mjs/cli-error/error-code/validation-error-code.mjs.map +7 -0
  125. package/lib/mjs/cli-error/error-message/definition-error-message.mjs +70 -0
  126. package/lib/mjs/cli-error/error-message/definition-error-message.mjs.map +7 -0
  127. package/lib/mjs/cli-error/error-message/internal-error-message.mjs +16 -0
  128. package/lib/mjs/cli-error/error-message/internal-error-message.mjs.map +7 -0
  129. package/lib/mjs/cli-error/error-message/parse-error-message.mjs +40 -0
  130. package/lib/mjs/cli-error/error-message/parse-error-message.mjs.map +7 -0
  131. package/lib/mjs/cli-error/error-message/validation-error-message.mjs +60 -0
  132. package/lib/mjs/cli-error/error-message/validation-error-message.mjs.map +7 -0
  133. package/lib/mjs/coerce/coerce-methods.mjs +197 -2
  134. package/lib/mjs/coerce/coerce-methods.mjs.map +7 -1
  135. package/lib/mjs/coerce/string-to-array.mjs +17 -2
  136. package/lib/mjs/coerce/string-to-array.mjs.map +7 -1
  137. package/lib/mjs/coerce/string-to-primitive.mjs +73 -2
  138. package/lib/mjs/coerce/string-to-primitive.mjs.map +7 -1
  139. package/lib/mjs/coerce/string-to-set.mjs +17 -2
  140. package/lib/mjs/coerce/string-to-set.mjs.map +7 -1
  141. package/lib/mjs/definitions/define-arguments.mjs +10 -2
  142. package/lib/mjs/definitions/define-arguments.mjs.map +7 -1
  143. package/lib/mjs/definitions/define-cli.mjs +89 -2
  144. package/lib/mjs/definitions/define-cli.mjs.map +7 -1
  145. package/lib/mjs/definitions/define-options.mjs +10 -2
  146. package/lib/mjs/definitions/define-options.mjs.map +7 -1
  147. package/lib/mjs/definitions/define-subcommand.mjs +56 -2
  148. package/lib/mjs/definitions/define-subcommand.mjs.map +7 -1
  149. package/lib/mjs/definitions/validate-cli-definition.mjs +360 -2
  150. package/lib/mjs/definitions/validate-cli-definition.mjs.map +7 -1
  151. package/lib/mjs/help-message/format-arguments.mjs +48 -2
  152. package/lib/mjs/help-message/format-arguments.mjs.map +7 -1
  153. package/lib/mjs/help-message/format-options.mjs +50 -2
  154. package/lib/mjs/help-message/format-options.mjs.map +7 -1
  155. package/lib/mjs/help-message/format-subcommands.mjs +37 -2
  156. package/lib/mjs/help-message/format-subcommands.mjs.map +7 -1
  157. package/lib/mjs/help-message/generate-for-cli.mjs +71 -2
  158. package/lib/mjs/help-message/generate-for-cli.mjs.map +7 -1
  159. package/lib/mjs/help-message/generate-for-subcommand.mjs +23 -2
  160. package/lib/mjs/help-message/generate-for-subcommand.mjs.map +7 -1
  161. package/lib/mjs/help-message/print-help.mjs +14 -2
  162. package/lib/mjs/help-message/print-help.mjs.map +7 -1
  163. package/lib/mjs/help-message/set-defaults.mjs +29 -2
  164. package/lib/mjs/help-message/set-defaults.mjs.map +7 -1
  165. package/lib/mjs/help-message/styles.mjs +154 -2
  166. package/lib/mjs/help-message/styles.mjs.map +7 -1
  167. package/lib/mjs/help-message/terminal-markdown.mjs +121 -2
  168. package/lib/mjs/help-message/terminal-markdown.mjs.map +7 -1
  169. package/lib/mjs/index.mjs +52 -2
  170. package/lib/mjs/index.mjs.map +7 -1
  171. package/lib/mjs/markdown/generate-markdown.mjs +153 -2
  172. package/lib/mjs/markdown/generate-markdown.mjs.map +7 -1
  173. package/lib/mjs/metadata/arguments-metadata.mjs +26 -2
  174. package/lib/mjs/metadata/arguments-metadata.mjs.map +7 -1
  175. package/lib/mjs/metadata/cli-metadata.mjs +24 -2
  176. package/lib/mjs/metadata/cli-metadata.mjs.map +7 -1
  177. package/lib/mjs/metadata/options-metadata.mjs +35 -2
  178. package/lib/mjs/metadata/options-metadata.mjs.map +7 -1
  179. package/lib/mjs/metadata/subcommands-metadata.mjs +32 -2
  180. package/lib/mjs/metadata/subcommands-metadata.mjs.map +7 -1
  181. package/lib/mjs/parse/context/cli-context-builder.mjs +283 -2
  182. package/lib/mjs/parse/context/cli-context-builder.mjs.map +7 -1
  183. package/lib/mjs/parse/context/object-context-builder.mjs +62 -2
  184. package/lib/mjs/parse/context/object-context-builder.mjs.map +7 -1
  185. package/lib/mjs/parse/parser-utilities.mjs +108 -2
  186. package/lib/mjs/parse/parser-utilities.mjs.map +7 -1
  187. package/lib/mjs/parse/safe-parse.mjs +57 -2
  188. package/lib/mjs/parse/safe-parse.mjs.map +7 -1
  189. package/lib/mjs/parse/validation/validate-context.mjs +17 -2
  190. package/lib/mjs/parse/validation/validate-context.mjs.map +7 -1
  191. package/lib/mjs/parse/validation/validators/arguments.mjs +67 -2
  192. package/lib/mjs/parse/validation/validators/arguments.mjs.map +7 -1
  193. package/lib/mjs/parse/validation/validators/conflict.mjs +38 -2
  194. package/lib/mjs/parse/validation/validators/conflict.mjs.map +7 -1
  195. package/lib/mjs/parse/validation/validators/exclusive.mjs +39 -2
  196. package/lib/mjs/parse/validation/validators/exclusive.mjs.map +7 -1
  197. package/lib/mjs/parse/validation/validators/explicitly-passed.mjs +18 -2
  198. package/lib/mjs/parse/validation/validators/explicitly-passed.mjs.map +7 -1
  199. package/lib/mjs/parse/validation/validators/options.mjs +67 -2
  200. package/lib/mjs/parse/validation/validators/options.mjs.map +7 -1
  201. package/lib/mjs/parse/validation/validators/requires.mjs +43 -2
  202. package/lib/mjs/parse/validation/validators/requires.mjs.map +7 -1
  203. package/lib/mjs/utilities/parse-argv.mjs +61 -0
  204. package/lib/mjs/utilities/parse-argv.mjs.map +7 -0
  205. package/lib/mjs/utilities/schema-utilities.mjs +57 -0
  206. package/lib/mjs/utilities/schema-utilities.mjs.map +7 -0
  207. package/lib/mjs/utilities/utilities.mjs +122 -0
  208. package/lib/mjs/utilities/utilities.mjs.map +7 -0
  209. package/lib/{typescript → types}/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
  210. package/lib/types/autocomplete-scripts/powershell-autocomplete-script.d.ts +15 -0
  211. package/lib/{typescript → types}/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
  212. package/lib/types/autocomplete-scripts/zsh-autocomplete-script.d.ts +4 -0
  213. package/lib/{typescript → types}/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
  214. package/lib/types/cli-error/cli-error.d.ts +152 -0
  215. package/lib/types/cli-error/cli-error.d.ts.map +1 -0
  216. package/lib/types/cli-error/error-cause.d.ts +5 -0
  217. package/lib/types/cli-error/error-cause.d.ts.map +1 -0
  218. package/lib/types/cli-error/error-code/definition-error-code.d.ts +5 -0
  219. package/lib/types/cli-error/error-code/definition-error-code.d.ts.map +1 -0
  220. package/lib/types/cli-error/error-code/internal-error-code.d.ts +5 -0
  221. package/lib/types/cli-error/error-code/internal-error-code.d.ts.map +1 -0
  222. package/lib/types/cli-error/error-code/parse-error-code.d.ts +5 -0
  223. package/lib/types/cli-error/error-code/parse-error-code.d.ts.map +1 -0
  224. package/lib/types/cli-error/error-code/validation-error-code.d.ts +5 -0
  225. package/lib/types/cli-error/error-code/validation-error-code.d.ts.map +1 -0
  226. package/lib/types/cli-error/error-message/definition-error-message.d.ts +3 -0
  227. package/lib/types/cli-error/error-message/definition-error-message.d.ts.map +1 -0
  228. package/lib/types/cli-error/error-message/internal-error-message.d.ts +3 -0
  229. package/lib/types/cli-error/error-message/internal-error-message.d.ts.map +1 -0
  230. package/lib/types/cli-error/error-message/parse-error-message.d.ts +3 -0
  231. package/lib/types/cli-error/error-message/parse-error-message.d.ts.map +1 -0
  232. package/lib/types/cli-error/error-message/validation-error-message.d.ts +3 -0
  233. package/lib/types/cli-error/error-message/validation-error-message.d.ts.map +1 -0
  234. package/lib/types/coerce/coerce-methods.d.ts +122 -0
  235. package/lib/types/coerce/coerce-methods.d.ts.map +1 -0
  236. package/lib/{typescript → types}/coerce/string-to-array.d.ts +2 -2
  237. package/lib/types/coerce/string-to-array.d.ts.map +1 -0
  238. package/lib/types/coerce/string-to-primitive.d.ts +21 -0
  239. package/lib/types/coerce/string-to-primitive.d.ts.map +1 -0
  240. package/lib/{typescript → types}/coerce/string-to-set.d.ts +2 -2
  241. package/lib/{typescript → types}/coerce/string-to-set.d.ts.map +1 -1
  242. package/lib/{typescript → types}/definitions/define-cli.d.ts +2 -6
  243. package/lib/types/definitions/define-cli.d.ts.map +1 -0
  244. package/lib/{typescript → types}/definitions/define-subcommand.d.ts +2 -4
  245. package/lib/types/definitions/define-subcommand.d.ts.map +1 -0
  246. package/lib/{typescript → types}/definitions/validate-cli-definition.d.ts +1 -1
  247. package/lib/types/definitions/validate-cli-definition.d.ts.map +1 -0
  248. package/lib/{typescript → types}/help-message/terminal-markdown.d.ts.map +1 -1
  249. package/lib/{typescript → types}/index.d.ts +7 -0
  250. package/lib/{typescript → types}/index.d.ts.map +1 -1
  251. package/lib/{typescript → types}/metadata/arguments-metadata.d.ts.map +1 -1
  252. package/lib/{typescript → types}/metadata/options-metadata.d.ts.map +1 -1
  253. package/lib/{typescript → types}/parse/context/cli-context-builder.d.ts +1 -1
  254. package/lib/{typescript → types}/parse/context/cli-context-builder.d.ts.map +1 -1
  255. package/lib/{typescript → types}/parse/context/object-context-builder.d.ts +1 -1
  256. package/lib/types/parse/context/object-context-builder.d.ts.map +1 -0
  257. package/lib/{typescript → types}/parse/parser-utilities.d.ts +9 -0
  258. package/lib/{typescript → types}/parse/parser-utilities.d.ts.map +1 -1
  259. package/lib/{typescript → types}/parse/safe-parse.d.ts.map +1 -1
  260. package/lib/{typescript → types}/parse/validation/validate-context.d.ts +1 -1
  261. package/lib/{typescript → types}/parse/validation/validate-context.d.ts.map +1 -1
  262. package/lib/{typescript → types}/parse/validation/validators/arguments.d.ts +1 -1
  263. package/lib/{typescript → types}/parse/validation/validators/arguments.d.ts.map +1 -1
  264. package/lib/{typescript → types}/parse/validation/validators/conflict.d.ts +3 -3
  265. package/lib/{typescript → types}/parse/validation/validators/conflict.d.ts.map +1 -1
  266. package/lib/{typescript → types}/parse/validation/validators/exclusive.d.ts +3 -3
  267. package/lib/{typescript → types}/parse/validation/validators/exclusive.d.ts.map +1 -1
  268. package/lib/{typescript → types}/parse/validation/validators/options.d.ts +1 -1
  269. package/lib/{typescript → types}/parse/validation/validators/options.d.ts.map +1 -1
  270. package/lib/{typescript → types}/parse/validation/validators/requires.d.ts +3 -3
  271. package/lib/{typescript → types}/parse/validation/validators/requires.d.ts.map +1 -1
  272. package/lib/{typescript → types}/types/definitions-types.d.ts +35 -4
  273. package/lib/types/types/definitions-types.d.ts.map +1 -0
  274. package/lib/types/types/error-types.d.ts +275 -0
  275. package/lib/types/types/error-types.d.ts.map +1 -0
  276. package/lib/types/types/types.d.ts +146 -0
  277. package/lib/types/types/types.d.ts.map +1 -0
  278. package/lib/{typescript → types}/types/utilities-types.d.ts +0 -2
  279. package/lib/{typescript → types}/types/utilities-types.d.ts.map +1 -1
  280. package/lib/types/utilities/parse-argv.d.ts +3 -0
  281. package/lib/types/utilities/parse-argv.d.ts.map +1 -0
  282. package/lib/types/utilities/schema-utilities.d.ts +15 -0
  283. package/lib/types/utilities/schema-utilities.d.ts.map +1 -0
  284. package/lib/{typescript → types/utilities}/utilities.d.ts +12 -15
  285. package/lib/types/utilities/utilities.d.ts.map +1 -0
  286. package/package.json +10 -9
  287. package/src/autocomplete-scripts/bash-autocomplete-script.ts +14 -12
  288. package/src/autocomplete-scripts/powershell-autocomplete-script.ts +67 -33
  289. package/src/autocomplete-scripts/zsh-autocomplete-script.ts +39 -31
  290. package/src/cli-error/cli-error.ts +44 -0
  291. package/src/cli-error/error-cause.ts +10 -0
  292. package/src/cli-error/error-code/definition-error-code.ts +21 -0
  293. package/src/cli-error/error-code/internal-error-code.ts +8 -0
  294. package/src/cli-error/error-code/parse-error-code.ts +16 -0
  295. package/src/cli-error/error-code/validation-error-code.ts +15 -0
  296. package/src/cli-error/error-message/definition-error-message.ts +144 -0
  297. package/src/cli-error/error-message/internal-error-message.ts +19 -0
  298. package/src/cli-error/error-message/parse-error-message.ts +76 -0
  299. package/src/cli-error/error-message/validation-error-message.ts +104 -0
  300. package/src/coerce/coerce-methods.ts +194 -39
  301. package/src/coerce/string-to-array.ts +2 -2
  302. package/src/coerce/string-to-primitive.ts +72 -13
  303. package/src/coerce/string-to-set.ts +2 -2
  304. package/src/definitions/define-arguments.ts +1 -1
  305. package/src/definitions/define-cli.ts +65 -30
  306. package/src/definitions/define-options.ts +1 -1
  307. package/src/definitions/define-subcommand.ts +47 -17
  308. package/src/definitions/validate-cli-definition.ts +287 -172
  309. package/src/help-message/format-arguments.ts +1 -1
  310. package/src/help-message/format-options.ts +1 -1
  311. package/src/help-message/format-subcommands.ts +1 -1
  312. package/src/help-message/generate-for-cli.ts +1 -1
  313. package/src/help-message/terminal-markdown.ts +3 -4
  314. package/src/index.ts +16 -0
  315. package/src/markdown/generate-markdown.ts +5 -4
  316. package/src/metadata/arguments-metadata.ts +2 -1
  317. package/src/metadata/options-metadata.ts +2 -1
  318. package/src/parse/context/cli-context-builder.ts +166 -39
  319. package/src/parse/context/object-context-builder.ts +37 -11
  320. package/src/parse/parser-utilities.ts +24 -10
  321. package/src/parse/safe-parse.ts +3 -6
  322. package/src/parse/validation/validate-context.ts +1 -1
  323. package/src/parse/validation/validators/arguments.ts +42 -14
  324. package/src/parse/validation/validators/conflict.ts +11 -20
  325. package/src/parse/validation/validators/exclusive.ts +16 -25
  326. package/src/parse/validation/validators/options.ts +40 -12
  327. package/src/parse/validation/validators/requires.ts +11 -20
  328. package/src/types/definitions-types.ts +36 -8
  329. package/src/types/error-types.ts +326 -0
  330. package/src/types/types.ts +100 -7
  331. package/src/types/utilities-types.ts +0 -10
  332. package/src/utilities/parse-argv.ts +79 -0
  333. package/src/utilities/schema-utilities.ts +72 -0
  334. package/src/{utilities.ts → utilities/utilities.ts} +25 -138
  335. package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs +0 -2
  336. package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +0 -1
  337. package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs +0 -2
  338. package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +0 -1
  339. package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs +0 -42
  340. package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +0 -1
  341. package/lib/cjs/coerce/coerce-methods.cjs +0 -2
  342. package/lib/cjs/coerce/coerce-methods.cjs.map +0 -1
  343. package/lib/cjs/coerce/string-to-array.cjs +0 -2
  344. package/lib/cjs/coerce/string-to-array.cjs.map +0 -1
  345. package/lib/cjs/coerce/string-to-primitive.cjs +0 -2
  346. package/lib/cjs/coerce/string-to-primitive.cjs.map +0 -1
  347. package/lib/cjs/coerce/string-to-set.cjs +0 -2
  348. package/lib/cjs/coerce/string-to-set.cjs.map +0 -1
  349. package/lib/cjs/definitions/define-arguments.cjs +0 -2
  350. package/lib/cjs/definitions/define-arguments.cjs.map +0 -1
  351. package/lib/cjs/definitions/define-cli.cjs +0 -2
  352. package/lib/cjs/definitions/define-cli.cjs.map +0 -1
  353. package/lib/cjs/definitions/define-options.cjs +0 -2
  354. package/lib/cjs/definitions/define-options.cjs.map +0 -1
  355. package/lib/cjs/definitions/define-subcommand.cjs +0 -2
  356. package/lib/cjs/definitions/define-subcommand.cjs.map +0 -1
  357. package/lib/cjs/definitions/validate-cli-definition.cjs +0 -2
  358. package/lib/cjs/definitions/validate-cli-definition.cjs.map +0 -1
  359. package/lib/cjs/help-message/format-arguments.cjs +0 -2
  360. package/lib/cjs/help-message/format-arguments.cjs.map +0 -1
  361. package/lib/cjs/help-message/format-options.cjs +0 -2
  362. package/lib/cjs/help-message/format-options.cjs.map +0 -1
  363. package/lib/cjs/help-message/format-subcommands.cjs +0 -2
  364. package/lib/cjs/help-message/format-subcommands.cjs.map +0 -1
  365. package/lib/cjs/help-message/generate-for-cli.cjs +0 -2
  366. package/lib/cjs/help-message/generate-for-cli.cjs.map +0 -1
  367. package/lib/cjs/help-message/generate-for-subcommand.cjs +0 -2
  368. package/lib/cjs/help-message/generate-for-subcommand.cjs.map +0 -1
  369. package/lib/cjs/help-message/print-help.cjs +0 -2
  370. package/lib/cjs/help-message/print-help.cjs.map +0 -1
  371. package/lib/cjs/help-message/set-defaults.cjs +0 -2
  372. package/lib/cjs/help-message/set-defaults.cjs.map +0 -1
  373. package/lib/cjs/help-message/styles.cjs +0 -2
  374. package/lib/cjs/help-message/styles.cjs.map +0 -1
  375. package/lib/cjs/help-message/terminal-markdown.cjs +0 -2
  376. package/lib/cjs/help-message/terminal-markdown.cjs.map +0 -1
  377. package/lib/cjs/index.cjs +0 -2
  378. package/lib/cjs/index.cjs.map +0 -1
  379. package/lib/cjs/markdown/generate-markdown.cjs +0 -2
  380. package/lib/cjs/markdown/generate-markdown.cjs.map +0 -1
  381. package/lib/cjs/metadata/arguments-metadata.cjs +0 -2
  382. package/lib/cjs/metadata/arguments-metadata.cjs.map +0 -1
  383. package/lib/cjs/metadata/cli-metadata.cjs +0 -2
  384. package/lib/cjs/metadata/cli-metadata.cjs.map +0 -1
  385. package/lib/cjs/metadata/options-metadata.cjs +0 -2
  386. package/lib/cjs/metadata/options-metadata.cjs.map +0 -1
  387. package/lib/cjs/metadata/subcommands-metadata.cjs +0 -2
  388. package/lib/cjs/metadata/subcommands-metadata.cjs.map +0 -1
  389. package/lib/cjs/parse/context/cli-context-builder.cjs +0 -2
  390. package/lib/cjs/parse/context/cli-context-builder.cjs.map +0 -1
  391. package/lib/cjs/parse/context/object-context-builder.cjs +0 -2
  392. package/lib/cjs/parse/context/object-context-builder.cjs.map +0 -1
  393. package/lib/cjs/parse/parser-utilities.cjs +0 -2
  394. package/lib/cjs/parse/parser-utilities.cjs.map +0 -1
  395. package/lib/cjs/parse/safe-parse.cjs +0 -2
  396. package/lib/cjs/parse/safe-parse.cjs.map +0 -1
  397. package/lib/cjs/parse/validation/validate-context.cjs +0 -2
  398. package/lib/cjs/parse/validation/validate-context.cjs.map +0 -1
  399. package/lib/cjs/parse/validation/validators/arguments.cjs +0 -2
  400. package/lib/cjs/parse/validation/validators/arguments.cjs.map +0 -1
  401. package/lib/cjs/parse/validation/validators/conflict.cjs +0 -2
  402. package/lib/cjs/parse/validation/validators/conflict.cjs.map +0 -1
  403. package/lib/cjs/parse/validation/validators/exclusive.cjs +0 -2
  404. package/lib/cjs/parse/validation/validators/exclusive.cjs.map +0 -1
  405. package/lib/cjs/parse/validation/validators/explicitly-passed.cjs +0 -2
  406. package/lib/cjs/parse/validation/validators/explicitly-passed.cjs.map +0 -1
  407. package/lib/cjs/parse/validation/validators/options.cjs +0 -2
  408. package/lib/cjs/parse/validation/validators/options.cjs.map +0 -1
  409. package/lib/cjs/parse/validation/validators/requires.cjs +0 -2
  410. package/lib/cjs/parse/validation/validators/requires.cjs.map +0 -1
  411. package/lib/cjs/utilities.cjs +0 -2
  412. package/lib/cjs/utilities.cjs.map +0 -1
  413. package/lib/esm/utilities.js +0 -2
  414. package/lib/esm/utilities.js.map +0 -1
  415. package/lib/mjs/utilities.mjs +0 -2
  416. package/lib/mjs/utilities.mjs.map +0 -1
  417. package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +0 -14
  418. package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +0 -11
  419. package/lib/typescript/coerce/coerce-methods.d.ts +0 -20
  420. package/lib/typescript/coerce/coerce-methods.d.ts.map +0 -1
  421. package/lib/typescript/coerce/string-to-array.d.ts.map +0 -1
  422. package/lib/typescript/coerce/string-to-primitive.d.ts +0 -5
  423. package/lib/typescript/coerce/string-to-primitive.d.ts.map +0 -1
  424. package/lib/typescript/definitions/define-cli.d.ts.map +0 -1
  425. package/lib/typescript/definitions/define-subcommand.d.ts.map +0 -1
  426. package/lib/typescript/definitions/validate-cli-definition.d.ts.map +0 -1
  427. package/lib/typescript/parse/context/object-context-builder.d.ts.map +0 -1
  428. package/lib/typescript/types/definitions-types.d.ts.map +0 -1
  429. package/lib/typescript/types/types.d.ts +0 -61
  430. package/lib/typescript/types/types.d.ts.map +0 -1
  431. package/lib/typescript/utilities.d.ts.map +0 -1
  432. /package/lib/{typescript → types}/autocomplete-scripts/bash-autocomplete-script.d.ts +0 -0
  433. /package/lib/{typescript → types}/definitions/define-arguments.d.ts +0 -0
  434. /package/lib/{typescript → types}/definitions/define-arguments.d.ts.map +0 -0
  435. /package/lib/{typescript → types}/definitions/define-options.d.ts +0 -0
  436. /package/lib/{typescript → types}/definitions/define-options.d.ts.map +0 -0
  437. /package/lib/{typescript → types}/help-message/format-arguments.d.ts +0 -0
  438. /package/lib/{typescript → types}/help-message/format-arguments.d.ts.map +0 -0
  439. /package/lib/{typescript → types}/help-message/format-options.d.ts +0 -0
  440. /package/lib/{typescript → types}/help-message/format-options.d.ts.map +0 -0
  441. /package/lib/{typescript → types}/help-message/format-subcommands.d.ts +0 -0
  442. /package/lib/{typescript → types}/help-message/format-subcommands.d.ts.map +0 -0
  443. /package/lib/{typescript → types}/help-message/generate-for-cli.d.ts +0 -0
  444. /package/lib/{typescript → types}/help-message/generate-for-cli.d.ts.map +0 -0
  445. /package/lib/{typescript → types}/help-message/generate-for-subcommand.d.ts +0 -0
  446. /package/lib/{typescript → types}/help-message/generate-for-subcommand.d.ts.map +0 -0
  447. /package/lib/{typescript → types}/help-message/print-help.d.ts +0 -0
  448. /package/lib/{typescript → types}/help-message/print-help.d.ts.map +0 -0
  449. /package/lib/{typescript → types}/help-message/set-defaults.d.ts +0 -0
  450. /package/lib/{typescript → types}/help-message/set-defaults.d.ts.map +0 -0
  451. /package/lib/{typescript → types}/help-message/styles.d.ts +0 -0
  452. /package/lib/{typescript → types}/help-message/styles.d.ts.map +0 -0
  453. /package/lib/{typescript → types}/help-message/terminal-markdown.d.ts +0 -0
  454. /package/lib/{typescript → types}/markdown/generate-markdown.d.ts +0 -0
  455. /package/lib/{typescript → types}/markdown/generate-markdown.d.ts.map +0 -0
  456. /package/lib/{typescript → types}/metadata/arguments-metadata.d.ts +0 -0
  457. /package/lib/{typescript → types}/metadata/cli-metadata.d.ts +0 -0
  458. /package/lib/{typescript → types}/metadata/cli-metadata.d.ts.map +0 -0
  459. /package/lib/{typescript → types}/metadata/options-metadata.d.ts +0 -0
  460. /package/lib/{typescript → types}/metadata/subcommands-metadata.d.ts +0 -0
  461. /package/lib/{typescript → types}/metadata/subcommands-metadata.d.ts.map +0 -0
  462. /package/lib/{typescript → types}/parse/safe-parse.d.ts +0 -0
  463. /package/lib/{typescript → types}/parse/validation/validators/explicitly-passed.d.ts +0 -0
  464. /package/lib/{typescript → types}/parse/validation/validators/explicitly-passed.d.ts.map +0 -0
  465. /package/lib/{typescript → types}/types/context-types.d.ts +0 -0
  466. /package/lib/{typescript → types}/types/context-types.d.ts.map +0 -0
  467. /package/lib/{typescript → types}/types/help-message-types.d.ts +0 -0
  468. /package/lib/{typescript → types}/types/help-message-types.d.ts.map +0 -0
  469. /package/lib/{typescript → types}/types/io-types.d.ts +0 -0
  470. /package/lib/{typescript → types}/types/io-types.d.ts.map +0 -0
  471. /package/lib/{typescript → types}/types/metadata-types.d.ts +0 -0
  472. /package/lib/{typescript → types}/types/metadata-types.d.ts.map +0 -0
  473. /package/lib/{typescript → types}/types/schema-types.d.ts +0 -0
  474. /package/lib/{typescript → types}/types/schema-types.d.ts.map +0 -0
package/LICENSE CHANGED
@@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
+
package/README.md CHANGED
@@ -16,25 +16,31 @@ A strictly typed command-line arguments parser powered by schema validation.
16
16
  - [Creating a subcommand](#creating-a-subcommand)
17
17
  - [Creating options](#creating-options)
18
18
  - [Creating typed arguments](#creating-typed-arguments)
19
+ - [Sharing options and typed arguments](#sharing-options-and-typed-arguments)
19
20
  - [Using Schemas](#using-schemas)
20
21
  - [Default Values and Optional Inputs](#default-values-and-optional-inputs)
21
22
  - [Positionals vs Typed Arguments](#positionals-vs-typed-arguments)
22
23
  - [Option and Argument Constraints](#option-and-argument-constraints)
23
24
  - [Negating a boolean option](#negating-a-boolean-option)
25
+ - [Structured Object Options](#structured-object-options)
26
+ - [Execute commands programmatically](#execute-commands-programmatically)
24
27
  - [Creating a Custom Help Message Style](#creating-a-custom-help-message-style)
25
28
  - [Help Message as HTML](#help-message-as-html)
29
+ - [Handling and Inspecting Errors](#handling-and-inspecting-errors)
30
+ - [Loading from a CDN](#loading-from-a-cdn)
26
31
  - [API Reference](#api-reference)
27
- - [Type Utilities](#type-utilities)
28
- - [Coerce Helpers](#coerce-helpers)
29
- - [Markdown Generation](#markdown-generation)
30
- - [Autocompletion Script Generation](#autocompletion-script-generation)
31
- - [Help Message](#help-message)
32
- - [PrintHelpOptions](#printhelpoptions)
33
- - [Cli](#cli)
34
- - [Subcommand](#subcommand)
35
- - [Option](#option)
36
- - [Argument](#argument)
37
- - [Context Type](#context-type)
32
+ - [Type Utilities](docs/api-reference.md#type-utilities)
33
+ - [Coerce Helpers](docs/api-reference.md#coerce-helpers)
34
+ - [Markdown Generation](docs/api-reference.md#markdown-generation)
35
+ - [Autocompletion Script Generation](docs/api-reference.md#autocompletion-script-generation)
36
+ - [Help Message](docs/api-reference.md#help-message)
37
+ - [PrintHelpOptions](docs/api-reference.md#printhelpoptions)
38
+ - [Cli](docs/api-reference.md#cli)
39
+ - [Subcommand](docs/api-reference.md#subcommand)
40
+ - [Option](docs/api-reference.md#option)
41
+ - [Argument](docs/api-reference.md#argument)
42
+ - [Context Type](docs/api-reference.md#context-type)
43
+ - [Error Types](docs/api-reference.md#error-types)
38
44
  - [License](#license)
39
45
 
40
46
  ## Features
@@ -65,46 +71,24 @@ The following example uses `zod` as the validation library, but you can use any
65
71
  import * as z from "zod";
66
72
  import { defineCLI, coerce } from "zod-args-parser";
67
73
 
68
- // Define the CLI program (main command)
69
- const listyCLI = defineCLI({
70
- cliName: "listy",
71
-
72
- subcommands: [
73
- // ...
74
- ],
75
-
74
+ const cli = defineCLI({
75
+ cliName: "hello",
76
76
  options: {
77
- help: {
78
- schema: z.boolean().optional(),
79
- coerce: coerce.boolean,
77
+ /** `--name` or `-n` */
78
+ name: {
79
+ aliases: ["n"],
80
+ schema: z.string().default("world"),
80
81
  },
81
82
  },
82
-
83
- arguments: {
84
- // ...
85
- },
86
83
  });
87
84
 
88
- // When the CLI (main command) is executed
89
- listyCLI.onExecute(results => {
90
- const { help } = results.options;
91
-
92
- // print help for the CLI
93
- if (help && listyCLI.generateCliHelpMessage) {
94
- console.log(listyCLI.generateCliHelpMessage());
95
- return;
96
- }
97
-
98
- console.error("Please try `listy --help`");
85
+ cli.onExecute(({ options }) => {
86
+ console.log(`Hello, ${options.name}!`);
99
87
  });
100
88
 
101
- // Run the CLI and pass in the command line arguments
102
- const results = listyCLI.run(process.argv.slice(2));
103
-
104
- // Inspect parsed results
105
- if (results.error) {
106
- console.error(results.error.message);
107
- console.log("\n`listy --help` for more information");
89
+ const result = cli.run(process.argv.slice(2));
90
+ if (result.error) {
91
+ console.error(result.error.message);
108
92
  }
109
93
  ```
110
94
 
@@ -220,6 +204,7 @@ Option names can use any common case style:
220
204
  - LIST_NAME `=>` --list-name
221
205
 
222
206
  ```ts
207
+ import * as z from "zod";
223
208
  import { defineSubcommand, coerce } from "zod-args-parser";
224
209
 
225
210
  const createListCommand = defineSubcommand({
@@ -329,6 +314,52 @@ const createListCommand = defineSubcommand({
329
314
  });
330
315
  ```
331
316
 
317
+ ### Sharing options and typed arguments
318
+
319
+ Options and typed arguments can be shared between subcommands/main CLI.
320
+
321
+ ```ts
322
+ // shared.ts
323
+ import * as z from "zod";
324
+ import { defineArguments, defineOptions, coerce } from "zod-args-parser";
325
+
326
+ export const sharedOptions = defineOptions({
327
+ verbose: {
328
+ schema: z.boolean().optional(),
329
+ coerce: coerce.boolean,
330
+ meta: {
331
+ description: "Enable verbose mode.",
332
+ },
333
+ },
334
+ });
335
+
336
+ export const sharedArguments = defineArguments({
337
+ // ...
338
+ });
339
+ ```
340
+
341
+ ```ts
342
+ // add-command.ts
343
+ import * as z from "zod";
344
+ import { defineSubcommand, coerce } from "zod-args-parser";
345
+
346
+ import { sharedOptions, sharedArguments } from "./shared.ts";
347
+
348
+ export const addCommand = defineSubcommand({
349
+ //...
350
+
351
+ options: {
352
+ // ...
353
+ ...sharedOptions,
354
+ },
355
+
356
+ arguments: {
357
+ // ...
358
+ ...sharedArguments,
359
+ },
360
+ });
361
+ ```
362
+
332
363
  ### Using schemas
333
364
 
334
365
  Other validation libraries can be used as long as they support [`StandardSchemaV1`](https://github.com/standard-schema/standard-schema) and allow primitive types to be optional or have default values.
@@ -392,17 +423,130 @@ Both options and typed arguments support rules to control valid combinations:
392
423
 
393
424
  ### Negating a boolean option
394
425
 
395
- Boolean options can be negated by prefixing them with `no-` or by using the equals sign `=`.
426
+ Boolean flags are `true` when they appear on the command line.
427
+ Prefixing a flag with `--no-` inverts its final value.
428
+
429
+ When a value is explicitly assigned (`=true` or `=false`), the assignment is applied first, then the `--no-` prefix flips the result.
430
+
431
+ Examples:
432
+
433
+ ```sh
434
+ --bool true
435
+ --no-bool false
436
+ ```
437
+
438
+ ```sh
439
+ --bool=true true
440
+ --bool=false false
441
+ ```
442
+
443
+ ```sh
444
+ --no-bool=true false # assigned true → inverted
445
+ --no-bool=false true # assigned false → inverted
446
+ ```
447
+
448
+ Short-form flags follow the same logic, but do **not** accept `=value` syntax:
449
+
450
+ ```sh
451
+ -v true
452
+ --no-v false
453
+ ```
454
+
455
+ ```sh
456
+ -v=true ERROR
457
+ -v=false ERROR
458
+ ```
459
+
460
+ ```sh
461
+ --no-v=true false
462
+ --no-v=false true
463
+ ```
464
+
465
+ ### Structured Object Options
466
+
467
+ Options using `coerce.object` receive **stringified JSON** and are parsed with `JSON.parse`.
468
+ They also support **dotted flags** to assign nested fields without writing full JSON.
469
+
470
+ See [Coerce Helpers](./docs/api-reference.md#coerce-helpers).
471
+
472
+ ```ts
473
+ import * as z from "zod";
474
+ import { defineCLI, coerce } from "zod-args-parser";
475
+
476
+ const cli = defineCLI({
477
+ cliName: "listy",
478
+ options: {
479
+ db: {
480
+ schema: z
481
+ .object({
482
+ host: z.string().default("localhost"),
483
+ port: z.number().default(5432),
484
+ https: z.boolean().default(false),
485
+ credentials: z.object({
486
+ user: z.string(),
487
+ pass: z.string(),
488
+ }),
489
+ })
490
+ .optional(),
491
+
492
+ // Accepts either a full JSON string or individual "dotted" flags,
493
+ // parsed with JSON.parse.
494
+ coerce: coerce.object({ coerceBoolean: true, coerceNumber: ["port"] }),
495
+
496
+ meta: {
497
+ placeholder: "<.host,.port,.credentials.user,.credentials.pass>",
498
+ description: "Database configuration object. Parsed as JSON; supports dotted flags.",
499
+ example: "--db.host=prod-db --db.credentials.user=alice --db.credentials.pass=secret",
500
+ },
501
+ },
502
+ },
503
+ });
504
+
505
+ cli.onExecute(({ options }) => {
506
+ console.log(options.db);
507
+ });
508
+ ```
509
+
510
+ #### Usage Examples
396
511
 
397
512
  ```sh
398
- --bool true
399
- --no-bool false
513
+ # Dotted flags for nested values using `=`
514
+ listy --db.https=true --db.host=db.local --db.port=3306 --db.credentials.user=root --db.credentials.pass=toor
515
+
516
+ # Dotted flags for nested values without `=`
517
+ listy --db.https true --db.host db.local --db.port 3306 --db.credentials.user root --db.credentials.pass toor
518
+
519
+ # Full JSON input (stringified)
520
+ listy --db '{"host":"db.local","https":true,"credentials":{"user":"root","pass":"toor"}}'
521
+ ```
522
+
523
+ ### Execute commands programmatically
524
+
525
+ You can execute the main CLI or a specific subcommand directly from code.
526
+ The input is provided as an object (`{ options, arguments, positionals }`) and is validated using the defined schemas.
527
+ Invalid input throws an error. Use `.executeAsync()` if your `onExecute` handler is asynchronous.
528
+
529
+ > [!NOTE]
530
+ > `run()` is like calling the CLI from the terminal.
531
+ > `execute()` is like calling a function directly.
400
532
 
401
- --bool=true true
402
- --bool=false false
533
+ ```ts
534
+ import { InferOptionsInputType } from "zod-args-parser";
535
+
536
+ import { listyCLI } from "./cli.ts";
537
+
538
+ // In this example, Listy only defines options — no typed arguments or positionals.
539
+ // To keep the function simple, we accept only the options as input.
540
+
541
+ /** @throws {CliError} */
542
+ export function executeListy(options: InferOptionsInputType<typeof listyCLI>) {
543
+ listyCLI.execute({ options });
544
+ }
403
545
 
404
- -v true
405
- --no-v false
546
+ /** @throws {CliError} */
547
+ export async function executeListyAsync(options: InferOptionsInputType<typeof listyCLI>) {
548
+ await listyCLI.executeAsync({ options });
549
+ }
406
550
  ```
407
551
 
408
552
  ### Creating a Custom Help Message Style
@@ -452,257 +596,75 @@ span._markdown * {
452
596
  }
453
597
  ```
454
598
 
455
- ## API Reference
456
-
457
- ### Type Utilities
458
-
459
- #### `InferInputType<T extends Cli | Subcommand>`
599
+ ### Handling and Inspecting Errors
460
600
 
461
- Infer options, arguments, and positionals input types from the CLI/subcommand definition.
601
+ The library processes input in four stages. Errors can occur at any step:
462
602
 
463
- #### `InferOutputType<T extends Cli | Subcommand>`
603
+ 1. **Definition Validation** Ensures the CLI and subcommand definitions are valid.
604
+ 2. **Argument Parsing** — Reads terminal input and builds the initial parse result.
605
+ 3. **Context Validation** — Applies schema validation and dependency rules.
606
+ 4. **Execution** — Runs the command or subcommand once all checks succeed.
464
607
 
465
- Infer options, arguments, and positionals output types from the CLI/subcommand definition.
608
+ After running your CLI, the returned result may contain an error. You can narrow down the error by its **cause** or **code** to handle it specifically.
466
609
 
467
- #### `InferOptionsInputType<T extends Cli | Subcommand>`
468
-
469
- Infer options input type from the CLI/subcommand definition.
470
-
471
- #### `InferOptionsOutputType<T extends Cli | Subcommand>`
472
-
473
- Infer options output type from the CLI/subcommand definition.
474
-
475
- #### `InferArgumentsInputType<T extends Cli | Subcommand>`
476
-
477
- Infer arguments input type from the CLI/subcommand definition.
478
-
479
- #### `InferArgumentsOutputType<T extends Cli | Subcommand>`
480
-
481
- Infer arguments output type from the CLI/subcommand definition.
610
+ See [Error Reference](./docs/api-reference.md#error-types)
482
611
 
483
612
  ```ts
484
- import type { defineSubcommand, InferInputType, InferOutputType } from "zod-args-parser";
485
-
486
- const subcommand = defineSubcommand({
487
- // ...
488
- });
489
-
490
- type InputType = InferInputType<typeof subcommand>;
491
- type OutputType = InferOutputType<typeof subcommand>;
492
- ```
493
-
494
- ### Coerce Helpers
495
-
496
- - `coerce.string`
497
- - `coerce.number`
498
- - `coerce.boolean`
499
- - `coerce.stringArray(separator: string)`
500
- - `coerce.numberArray(separator: string)`
501
- - `coerce.booleanArray(separator: string)`
502
- - `coerce.stringSet(separator: string)`
503
- - `coerce.numberSet(separator: string)`
504
- - `coerce.booleanSet(separator: string)`
505
- - `coerce.json<T>()`
506
-
507
- ### Markdown Generation
508
-
509
- #### generateMarkdown
510
-
511
- `(cliDefinition: Cli) => string`
512
-
513
- Generate markdown documentation for a **CLI definition** and return it as a `string`.
514
-
515
- ### Autocomplete Script Generation
516
-
517
- #### generateBashAutocompleteScript
518
-
519
- `(cliDefinition: Cli) => string`
520
-
521
- Generate a Bash autocomplete script for a **CLI definition** and return it as a `string`.
522
-
523
- #### generateZshAutocompleteScript
524
-
525
- `(cliDefinition: Cli) => string`
526
-
527
- Generate a zsh autocomplete script for a **CLI definition** and return it as a `string`.
528
-
529
- #### generatePowerShellAutocompleteScript
530
-
531
- `(cliDefinition: Cli) => string`
613
+ import { ErrorCause, ValidationErrorCode } from "zod-args-parser";
532
614
 
533
- Generate a PowerShell autocomplete script for a **CLI definition** and return it as a `string`.
615
+ const results = listyCLI.run(input);
534
616
 
535
- ### Help Message
536
-
537
- #### generateCliHelpMessage
538
-
539
- `(cliDefinition: Cli, printOptions?: PrintHelpOptions) => string`
540
-
541
- Generate a help message for a **CLI definition** and return it as a `string`.
542
- See [`PrintHelpOptions`](#printhelpoptions) and [`Cli`](#cli).
543
-
544
- #### generateSubcommandHelpMessage
545
-
546
- `(commandDefinition: Subcommand, options?: PrintHelpOptions, cliName?: string) => string`
547
-
548
- Generate a help message for a **subcommand definition** and return it as a `string`.
549
- See [`PrintHelpOptions`](#printhelpoptions) and [`Subcommand`](#subcommand).
550
-
551
- #### printCliHelp
552
-
553
- `(cliDefinition: Cli, options?: PrintHelpOptions) => void`
554
-
555
- Print a help message for a **CLI definition**.
556
- See [`PrintHelpOptions`](#printhelpoptions) and [`Cli`](#cli).
617
+ if (results.error) {
618
+ // Check the type of error by its cause
619
+ if (results.error.cause === ErrorCause.Parse) {
620
+ // Handle parsing-related errors
621
+ }
557
622
 
558
- #### printSubcommandHelp
623
+ // Check for a specific error code
624
+ if (results.error.code === ValidationErrorCode.SchemaValidationFailed) {
625
+ const { commandKind, commandName, kind, name, inputValue, issues } = results.error.context;
559
626
 
560
- `(commandDefinition: Subcommand, options?: PrintHelpOptions, cliName?: string) => void`
627
+ console.error(
628
+ "validation error:",
629
+ `the ${kind} "${name}"`,
630
+ `for ${commandKind} "${commandName}" failed to validate the input:`,
631
+ inputValue,
632
+ );
561
633
 
562
- Print a help message for a **subcommand definition**.
563
- See [`PrintHelpOptions`](#printhelpoptions) and [`Subcommand`](#subcommand).
634
+ // Detailed validation issues
635
+ console.log(issues);
636
+ }
637
+ }
638
+ ```
564
639
 
565
- ### PrintHelpOptions
640
+ ### Loading from a CDN
566
641
 
567
- | Option | Type | Default | Description |
568
- | ----------------------- | ---------------------- | --------------------------- | ----------------------------------------------------------------------------------- |
569
- | style | `HelpMessageStyle` | `helpMessageStyles.default` | The style to use for the help message. |
570
- | kebabCaseArgumentName | `boolean` | `true` | Whether to transform the argument (not option) name to kebab case. |
571
- | markdownRenderer | `"terminal" \| "html"` | `"terminal"` | The renderer to use for the markdown. |
572
- | indentBeforeName | `number` | `2` | The number of spaces before the name of option/argument/subcommand. |
573
- | indentAfterName | `number` | `4` | Spaces after the name, between the name and description (space between columns). |
574
- | indentBeforePlaceholder | `number` | `1` | The number of spaces to put before the placeholder. |
575
- | newLineIndent | `number` | `0` | Spaces before a new line for description or example under description. |
576
- | emptyLines | `number` | `0` | Number of empty lines between lines. |
577
- | emptyLinesBeforeTitle | `number` | `1` | Number of empty lines before the title. |
578
- | emptyLinesAfterTitle | `number` | `0` | Number of empty lines after the title. |
579
- | exampleKeyword | `string` | `"Example:"` | The keyword to use for examples. |
580
- | optionalKeyword | `string` | `"(optional)"` | The keyword to use for optional values. |
581
- | defaultKeyword | `string` | `"(default: {{ value }})"` | The keyword to indicate default values, with `{{ value }}` replaced by the default. |
582
- | usageTitle | `string` | `"USAGE"` | The title to use for the usage section. |
583
- | descriptionTitle | `string` | `"DESCRIPTION"` | The title to use for the description section. |
584
- | commandsTitle | `string` | `"COMMANDS"` | The title to use for the commands section. |
585
- | optionsTitle | `string` | `"OPTIONS"` | The title to use for the options section. |
586
- | argumentsTitle | `string` | `"ARGUMENTS"` | The title to use for the arguments section. |
587
- | exampleTitle | `string` | `"EXAMPLE"` | The title to use for the examples section. |
642
+ **Global IIFE**
588
643
 
589
- ### Cli
644
+ ```html
645
+ <!-- using jsdelivr -->
646
+ <script src="https://cdn.jsdelivr.net/npm/zod-args-parser"></script>
590
647
 
591
- | Property | Type | Description |
592
- | ------------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
593
- | `cliName` | `string` | The name of the CLI program (main command). |
594
- | `subcommands?` | `Subcommand[]` | Array of subcommands. Do not manually construct subcommand objects; always create them via `defineSubcommand()` and pass the returned object. See [`Subcommand Definition`](#subcommand-definition). |
595
- | `allowPositionals?` | `boolean` | When `true`, enables positional arguments for the CLI; positionals are untyped `string[]`. If typed `arguments` are present, they are parsed first and any remaining args become `positionals`. |
596
- | `options?` | `Record<string, Option>` | A dictionary of option definitions keyed by a valid JavaScript variable name (e.g., `inputDir` → `--input-dir`). See [`Option Definition`](#option-definition). |
597
- | `arguments?` | `Record<string, Argument>` | Strictly ordered typed arguments. See [`Argument Definition`](#argument-definition). |
598
- | `meta?` | `CliMeta` | Metadata for the CLI used for help messages and documentation generation. |
648
+ <!-- using unpkg -->
649
+ <script src="https://unpkg.com/zod-args-parser"></script>
599
650
 
600
- ### CliMeta
651
+ <script>
652
+ // Access the library as a global
653
+ const { defineCLI, coerce } = ZodArgsParser;
654
+ </script>
655
+ ```
601
656
 
602
- | Property | Type | Description |
603
- | ---------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
604
- | `usage?` | `string` | Usage string example (e.g., `cliName subcommand [options] <arg1> <arg2>`). |
605
- | `description?` | `string` | Short explanation. Supports multi-line text and ANSI colors. Preferred for terminal output when present. |
606
- | `descriptionMarkdown?` | `string` | Markdown-formatted description used for generated documentation and terminal markdown. Used for Markdown generation if present. |
607
- | `example?` | `string` | Examples shown to the user (displayed as a code block in Markdown). |
657
+ **ESM Module**
608
658
 
609
- ### Subcommand
659
+ ```html
660
+ <script type="module">
661
+ import { defineCLI, coerce } from "https://cdn.jsdelivr.net/npm/zod-args-parser/+esm";
662
+ </script>
663
+ ```
610
664
 
611
- | Property | Type | Description |
612
- | ------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
613
- | `name` | `string` | The subcommand name. Must be unique within a CLI across names and aliases. |
614
- | `aliases?` | `string[]` | A list of aliases that can be used to invoke this subcommand. Must not collide with other names or aliases in the same CLI. |
615
- | `allowPositionals?` | `boolean` | When `true`, enables positional arguments for this subcommand. Positionals are untyped `string[]`. If typed `arguments` are present, they are parsed first and any remaining args become `positionals`. |
616
- | `options?` | `Record<string, Option>` | A dictionary of option definitions keyed by a valid JavaScript variable name (e.g., `inputDir` → `--input-dir`). See [`Option Definition`](#option-definition). |
617
- | `arguments?` | `Record<string, Argument>` | Strictly ordered, typed arguments (the order matters). [`Argument Definition`](#argument-definition). |
618
- | `meta?` | `SubcommandMeta` | Metadata used for help messages and documentation generation. Inlined in the table below. |
665
+ ## API Reference
619
666
 
620
- ### SubcommandMeta
621
-
622
- | Property | Type | Description |
623
- | ---------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
624
- | `placeholder?` | `string` | Text displayed after the subcommand name to show expected arguments (e.g., `<list> <items>`). |
625
- | `usage?` | `string` | Usage string example (e.g. `cliName subcommand [options] <arg1> <arg2>`). |
626
- | `description?` | `string` | Short explanation. Supports multi-line text and ANSI color styles. Preferred for terminal output if both `description` and `descriptionMarkdown` are provided. |
627
- | `descriptionMarkdown?` | `string` | Markdown-formatted description used for generated documentation and terminal markdown. If both `description` and `descriptionMarkdown` are provided, `descriptionMarkdown` is used for Markdown generation. |
628
- | `example?` | `string` | Examples shown to the user (displayed inside a code block in markdown). |
629
- | `hidden?` | `boolean` | When `true`, hide this item from documentation/help output. Useful for internal or undocumented commands/options. |
630
-
631
- ### Option
632
-
633
- | Property | Type | Description |
634
- | --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
635
- | `aliases?` | `string[]` | A list of short alias keys (JavaScript variable names) that map to short CLI flags (e.g., `i` → `-i`). |
636
- | `schema` | `Schema` | A schema to validate the user input. (e.g., Zod: `z.string().optional()`). |
637
- | `coerce?` | `CoerceMethod<...>` | Coercion function used to convert `string` input to the schema's output type. Not required when the expected input type is `string`. |
638
- | `exclusive?` | `boolean` | When `true`, this option must appear on its own (except for entries listed in `requires`). |
639
- | `requires?` | `string[]` | Names of other options/arguments that must be explicitly provided when this option is used. |
640
- | `conflictWith?` | `string[]` | Names of other options/arguments that conflict with this option. |
641
- | `meta?` | `OptionMeta` | Metadata used for help messages and documentation generation. Inlined in the table below. |
642
-
643
- ### OptionMeta
644
-
645
- | Property | Type | Description |
646
- | -------------- | --------- | ---------------------------------------------------------------------------------------------- |
647
- | `placeholder?` | `string` | Text to display as a placeholder for the expected value (e.g., `<path>`). |
648
- | `default?` | `string` | Custom default value shown in docs/help. Use an empty string to intentionally show no default. |
649
- | `optional?` | `boolean` | Override whether this option is considered optional in the generated help documentation. |
650
-
651
- ### Argument
652
-
653
- | Property | Type | Description |
654
- | --------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
655
- | `schema` | `Schema` | Schema to validate the user input. |
656
- | `coerce?` | `CoerceMethod<...>` | Coercion function used to convert `string` input to the schema's output type. Not required when the expected input type is `string`. |
657
- | `exclusive?` | `boolean` | When `true`, this argument must appear on its own (except for items listed in `requires`). |
658
- | `requires?` | `string[]` | Names of other options/arguments that must be explicitly provided when this argument is used. |
659
- | `conflictWith?` | `string[]` | Names of other options/arguments that conflict with this argument. |
660
- | `meta?` | `ArgumentMeta` | Metadata used for help messages and documentation generation. Inlined in the table below. |
661
-
662
- ### ArgumentMeta
663
-
664
- | Property | Type | Description |
665
- | ----------- | --------- | ---------------------------------------------------------------------------------------------- |
666
- | `name?` | `string` | Override the argument name in the help message and documentation. |
667
- | `default?` | `string` | Custom default value shown in help/docs. Use an empty string to intentionally show no default. |
668
- | `optional?` | `boolean` | Override whether this argument is considered optional in the generated help documentation. |
669
-
670
- ### Context Type
671
-
672
- Represents detailed information about how each option or argument was provided (terminal, default, or programmatic).
673
- Useful for inspecting where values came from and what raw input was used.
674
-
675
- #### Context
676
-
677
- | Field | Type | Description |
678
- | ------------- | --------------------------------- | ------------------------------------------------- |
679
- | `subcommand` | `string` \| `undefined` | Name of the executed subcommand, if any. |
680
- | `options` | `Record<string, OptionContext>` | Per-option context, with source and raw values. |
681
- | `arguments` | `Record<string, ArgumentContext>` | Per-argument context, with source and raw values. |
682
- | `positionals` | `string[]` \| `never` | Raw positional arguments when allowed. |
683
-
684
- #### OptionContext
685
-
686
- | Property | Description |
687
- | -------------- | ------------------------------------------------------------------------------------ |
688
- | `schema` | Schema used to validate the option. |
689
- | `optional` | Whether the option schema is optional. |
690
- | `defaultValue` | Default value from the schema, if any. |
691
- | `flag` | CLI flag used (e.g., `--foo`, `-f`) when source is `terminal`. |
692
- | `stringValue` | Raw string provided from CLI when source is `terminal`. |
693
- | `passedValue` | Value passed programmatically when source is `programmatic`. |
694
- | `source` | `"terminal"`, `"default"`, or `"programmatic"` indicates how the value was supplied. |
695
-
696
- #### ArgumentContext
697
-
698
- | Property | Description |
699
- | -------------- | ------------------------------------------------------------------------------------ |
700
- | `schema` | Schema used to validate the argument. |
701
- | `optional` | Whether the argument schema is optional. |
702
- | `defaultValue` | Default value from the schema, if any. |
703
- | `stringValue` | Raw string from CLI when source is `terminal`. |
704
- | `passedValue` | Value passed programmatically when source is `programmatic`. |
705
- | `source` | `"terminal"`, `"default"`, or `"programmatic"` indicates how the value was supplied. |
667
+ See the [API Reference](./docs/api-reference.md) for more information.
706
668
 
707
669
  ## License
708
670