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
package/README.md CHANGED
@@ -4,768 +4,705 @@
4
4
  [![GitHub](https://img.shields.io/github/license/alabsi91/zod-args-parser?style=for-the-badge)](https://github.com/alabsi91/zod-args-parser/blob/main/LICENSE)
5
5
  [![GitHub issues](https://img.shields.io/github/issues/alabsi91/zod-args-parser?style=for-the-badge)](https://github.com/alabsi91/zod-args-parser/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)
6
6
 
7
- A strictly typed command-line arguments parser powered by [Zod](https://github.com/colinhacks/zod).
7
+ A strictly typed command-line arguments parser powered by schema validation.
8
8
 
9
9
  ## Table of Contents
10
10
 
11
11
  - [Features](#features)
12
12
  - [Installation](#installation)
13
13
  - [Usage](#usage)
14
+ - [Example](#example)
14
15
  - [Guide](#guide)
15
- - [Subcommands](#subcommands)
16
- - [Type Zod Schemas](#type-zod-schemas)
17
- - [Options](#options)
18
- - [Arguments](#arguments)
19
- - [Positionals](#positionals)
20
- - [Pre-Validation Hook](#pre-validation-hook)
21
- - [Help Message](#help-message)
22
- - [Zod Utilities](#zod-utilities)
23
- - [Type Utilities](#type-utilities)
16
+ - [Creating a subcommand](#creating-a-subcommand)
17
+ - [Creating options](#creating-options)
18
+ - [Creating typed arguments](#creating-typed-arguments)
19
+ - [Using Schemas](#using-schemas)
20
+ - [Default Values and Optional Inputs](#default-values-and-optional-inputs)
21
+ - [Positionals vs Typed Arguments](#positionals-vs-typed-arguments)
22
+ - [Option and Argument Constraints](#option-and-argument-constraints)
23
+ - [Negating a boolean option](#negating-a-boolean-option)
24
+ - [Creating a Custom Help Message Style](#creating-a-custom-help-message-style)
25
+ - [Help Message as HTML](#help-message-as-html)
24
26
  - [API Reference](#api-reference)
25
- - [Methods](#methods)
26
- - [Types](#types)
27
- - [Example](#example)
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)
28
38
  - [License](#license)
29
39
 
30
40
  ## Features
31
41
 
32
- - **Strict typing for subcommands, options, and arguments**.
33
- - **Flag coupling support**: e.g., `-rf` to combine `-r` and `-f` flags.
34
- - **Negative flag support**: e.g., `--no-verbose` to negate `--verbose`.
35
- - **Flexible option value formatting**: Supports both `--input-dir path` and `--input-dir=path` styles.
36
- - **Help message generation**: Built-in methods to generate help text for the CLI and each subcommand.
37
- - **Auto completion**: Generate shell (bash, zsh, powershell) completion scripts for your CLI.
38
- - **Documentation**: Generate a markdown documentation for your CLI.
42
+ - **Strictly typed & validated**: Fully TypeScript-typed CLI arguments, backed by schema validation.
43
+ - **Flexible option syntax**: Supports both `--option value` and `--option=value`.
44
+ - **Boolean flags**: Handles negation (`--no-verbose`) and short flag coupling (`-rf`).
45
+ - **Typed subcommands**: Define subcommands with their own typed options and arguments.
46
+ - **Automatic help & docs**: Generate user-friendly CLI help messages and Markdown documentation.
47
+ - **Shell autocompletion**: Auto-generate scripts for Bash, Zsh, and PowerShell.
48
+ - **Schema-agnostic**: Works with any validation library supporting [`StandardSchemaV1`](https://github.com/standard-schema/standard-schema) and default/optional primitives.
49
+ - **Cross-platform**: Fully supports Node.js, Bun, Deno, and modern browsers.
39
50
 
40
51
  ## Installation
41
52
 
42
53
  > [!IMPORTANT]
43
- > `zod` version `3.25.0` or later (including `4.0.0`) is required.
54
+ > A validation library is required that supports [`StandardSchemaV1`](https://github.com/standard-schema/standard-schema) and allows primitive types to be optional or have default values.
44
55
 
45
56
  ```bash
46
- npm install zod chalk zod-args-parser
57
+ npm install zod zod-args-parser
47
58
  ```
48
59
 
49
60
  ## Usage
50
61
 
62
+ The following example uses `zod` as the validation library, but you can use any library that supports [`StandardSchemaV1`](https://github.com/standard-schema/standard-schema), as long as it allows primitive types to be optional or have default values.
63
+
51
64
  ```ts
52
65
  import * as z from "zod";
53
- import { createCli, createSubcommand, createOptions, safeParse } from "zod-args-parser";
54
-
55
- // Share options between schemas.
56
- const sharedOptions = createOptions([
57
- {
58
- name: "verbose",
59
- description: "Verbose mode",
60
- type: z.boolean().optional(),
61
- },
62
- ]);
63
-
64
- // Create the CLI program schema
65
- // This will be used when no subcommands are run
66
- const cliSchema = createCli({
67
- cliName: "my-cli",
68
- description: "A description for my CLI",
69
- example: "example of how to use my cli\nmy-cli --help",
70
- options: [
71
- {
72
- name: "help",
73
- aliases: ["h"],
74
- type: z.boolean().optional().describe("Show this help message"),
75
- },
76
- {
77
- name: "version",
78
- aliases: ["v"],
79
- description: "Show version",
80
- type: z.boolean().optional(),
81
- },
82
- ...sharedOptions,
83
- ],
84
- });
66
+ import { defineCLI, coerce } from "zod-args-parser";
85
67
 
86
- // Execute this function when the CLI is run (no subcommands)
87
- cliSchema.setAction(results => {
88
- const { help, version, verbose } = results;
68
+ // Define the CLI program (main command)
69
+ const listyCLI = defineCLI({
70
+ cliName: "listy",
89
71
 
90
- if (help) {
91
- results.printCliHelp();
92
- return;
93
- }
72
+ subcommands: [
73
+ // ...
74
+ ],
94
75
 
95
- if (version) {
96
- console.log("v1.0.0");
97
- return;
98
- }
76
+ options: {
77
+ help: {
78
+ schema: z.boolean().optional(),
79
+ coerce: coerce.boolean,
80
+ },
81
+ },
99
82
 
100
- if (verbose) {
101
- console.log("Verbose mode enabled");
102
- }
83
+ arguments: {
84
+ // ...
85
+ },
103
86
  });
104
87
 
105
- // Create a subcommand schema
106
- const helpCommandSchema = createSubcommand({
107
- name: "help",
108
- placeholder: "<command>",
109
- description: "Print help message for command",
110
- arguments: [
111
- {
112
- name: "command",
113
- description: "Command to print help for",
114
- type: z.enum(["build", "help", "init"]).optional(),
115
- },
116
- ],
117
- });
88
+ // When the CLI (main command) is executed
89
+ listyCLI.onExecute(results => {
90
+ const { help } = results.options;
118
91
 
119
- // Execute this function when the `help` subcommand is run
120
- helpCommandSchema.setAction(results => {
121
- const [command] = results.arguments;
122
- if (command) {
123
- results.printSubcommandHelp(command);
92
+ // print help for the CLI
93
+ if (help && listyCLI.generateCliHelpMessage) {
94
+ console.log(listyCLI.generateCliHelpMessage());
124
95
  return;
125
96
  }
126
97
 
127
- results.printCliHelp();
98
+ console.error("Please try `listy --help`");
128
99
  });
129
100
 
130
- const schemas = [cliSchema, helpCommandSchema /* Add more subcommands */] as const;
131
-
132
- const results = safeParse(process.argv.slice(2), ...schemas);
101
+ // Run the CLI and pass in the command line arguments
102
+ const results = listyCLI.run(process.argv.slice(2));
133
103
 
134
- // ! Error
135
- if (!results.success) {
104
+ // Inspect parsed results
105
+ if (results.error) {
136
106
  console.error(results.error.message);
137
- console.log("\n`my-cli --help` for more information, or `my-cli help <command>` for command-specific help\n");
138
- process.exit(1);
107
+ console.log("\n`listy --help` for more information");
139
108
  }
140
109
  ```
141
110
 
111
+ ## Example
112
+
113
+ - [Listy CLI Example](https://github.com/alabsi91/zod-args-parser/tree/main/example)
114
+
142
115
  ## Guide
143
116
 
144
- ### Subcommands
117
+ ### Creating a subcommand
145
118
 
146
- - Subcommands are defined using the `createSubcommand` function, which accepts an object with the type [`Subcommand`](#subcommand).
147
- - The following properties are optional and used only for **metadata** such as help messages and documentation:
148
- - `description`
149
- - `usage`
150
- - `example`
151
- - `placeholder`
152
- - Do not reuse the same subcommand name within the same CLI. TypeScript will throw a type error if a duplicate exist.
119
+ Subcommands are defined using the `defineSubcommand` function, which accepts a [`Subcommand`](#subcommand) definition object.
153
120
 
154
121
  ```ts
155
- import { createSubcommand } from "zod-args-parser";
156
-
157
- const subcommand = createSubcommand({
158
- name: "subcommand",
159
- description: "Description for the subcommand",
160
- usage: "my-cli subcommand [options] [arguments]",
161
- example: "subcommand --help",
162
- placeholder: "[options] [arguments]",
163
- allowPositional: false, // default: false
164
- options: [
165
- /* options */
166
- ],
167
- arguments: [
168
- /* arguments */
169
- ],
170
- });
122
+ import { defineSubcommand, helpMessageStyles } from "zod-args-parser";
171
123
 
172
- // Executed when the subcommand is run after parsing before validation
173
- subcommand.setPreValidationHook(ctx => {
174
- // ...
175
- });
124
+ import type { InferInputType, InferOutputType } from "zod-args-parser";
176
125
 
177
- // Executed when the subcommand is run
178
- subcommand.setAction(results => {
179
- // ...
180
- });
181
- ```
126
+ const createListCommand = defineSubcommand({
127
+ // The name used to call this subcommand from the CLI
128
+ name: "add",
182
129
 
183
- ### Type Zod Schemas
130
+ // Additional names that can be used to run the same subcommand
131
+ aliases: ["cl", "create"],
184
132
 
185
- - A schema with `.optional()` or `.default(<value>)` is treated as **optional**; all others are **required**.
186
- - Descriptions can be added either via the Zod schema’s `describe` method or the `description` property.
133
+ // When true: positional (untyped) arguments are allowed and parsed as string[]
134
+ // When typed arguments exist: they are parsed first, and leftover arguments become `positionals`
135
+ allowPositionals: false,
187
136
 
188
- > [!IMPORTANT]
189
- > All values from the terminal are passed as **strings**, so **coercion** is required except for simple booleans types which are inferred automatically.
137
+ // Extra information used for CLI help output and generated documentation
138
+ meta: {
139
+ // Shown in the terminal when displaying the help text for this subcommand
140
+ // Ignored in Markdown docs
141
+ usage: "listy add --list <list> --items <items> --tags <tags>",
190
142
 
191
- ```ts
192
- import * as z from "zod";
143
+ // Shown in terminal help alongside the subcommand name
144
+ // Also shown in Markdown docs next to the subcommand name
145
+ placeholder: "<list> <items> <tags>",
193
146
 
194
- // String examples
195
- z.string(); // required -> string
196
- z.string().optional(); // optional -> string | undefined
197
- z.string().default("hello"); // optional -> string
147
+ // Shown in terminal help if both description and descriptionMarkdown exist
148
+ // Not preferred in Markdown docs
149
+ description: "Plain text description shown in terminal help when both formats are provided.",
198
150
 
199
- // Boolean examples (simple booleans are inferred automatically no need to use coerce)
200
- z.boolean(); // required -> boolean
201
- z.boolean().optional(); // optional -> boolean | undefined
202
- z.boolean().default(true); // optional -> boolean
151
+ // Used as-is in Markdown docs and preferred over `description`
152
+ // When printed in the terminal, it will be parsed by `marked` and formatted for the terminal output
153
+ descriptionMarkdown: "**Formatted** for terminal and preferred when generating **Markdown documentation**.",
203
154
 
204
- // Number examples (need coercion because terminal inputs are strings)
205
- z.number(); // 🚫 invalid: will always throw
206
- z.coerce.number(); // ✅ converts string input -> number
155
+ // Displayed at the bottom of terminal help
156
+ // In Markdown docs, it is output inside a code block
157
+ example:
158
+ "listy add --list groceries --items egg,milk,bread --tags food\n" +
159
+ "listy add --list todos --items clean,cook --tags chores|work",
207
160
 
208
- // String boolean (zod v4) -> boolean
209
- z.stringbool({
210
- truthy: ["true", "1", "yes", "on", "y", "enabled"],
211
- falsy: ["false", "0", "no", "off", "n", "disabled"],
212
- });
161
+ // If true, this subcommand is hidden from both help output and documentation
162
+ // Useful for internal commands
163
+ hidden: false,
164
+ },
213
165
 
214
- // Enum -> "a" | "b" | "c"
215
- z.enum(["a", "b", "c"]);
166
+ // Available CLI options for this subcommand
167
+ options: {
168
+ // ...
169
+ },
216
170
 
217
- // Union -> number | "development"
218
- z.union([z.coerce.number(), z.literal("development")]);
171
+ // Typed command-line arguments for this subcommand
172
+ arguments: {
173
+ // ...
174
+ },
175
+ });
219
176
 
220
- // Custom preprocessing:
221
- import { stringToArray, stringToSet } from "zod-args-parser";
177
+ // Runs when the subcommand is executed
178
+ // Multiple handlers can be attached if needed
179
+ const unsubscribe = createListCommand.onExecute(results => {
180
+ const { ...options } = results.options;
181
+ const { ...args } = results.arguments;
182
+ const positionals = results.positionals;
183
+
184
+ // Inspect parsed results in detail
185
+ console.log(results.context.options);
186
+
187
+ // Print help for this subcommand
188
+ if (createListCommand.generateSubcommandHelpMessage) {
189
+ console.log(
190
+ createListCommand.generateSubcommandHelpMessage(results.subcommand, { style: helpMessageStyles.default }),
191
+ );
192
+ return;
193
+ }
222
194
 
223
- // Array -> string[]
224
- z.preprocess((value: string) => stringToArray(value), z.string().array());
195
+ // Print help for the CLI
196
+ if (listyCLI.generateCliHelpMessage) {
197
+ console.log(listyCLI.generateCliHelpMessage({ style: helpMessageStyles.default }));
198
+ return;
199
+ }
200
+ });
225
201
 
226
- // Tuple -> [string, number, boolean]
227
- z.preprocess(
228
- (value: string) => stringToArray(value, ";"), // second arg is the separator (default: ",")
229
- z.tuple([z.string(), z.coerce.number(), z.coerce.boolean()]),
230
- );
202
+ // Programmatic API for executing this subcommand
203
+ export const executeCreateListCommand = createListCommand.execute;
231
204
 
232
- // Set -> Set<string>
233
- z.preprocess((value: string) => stringToSet(value), z.set(z.string()));
205
+ // Useful inferred types for input/output payloads
206
+ type CreateListInput = InferInputType<typeof createListCommand>;
207
+ type CreateListOutput = InferOutputType<typeof createListCommand>;
234
208
  ```
235
209
 
236
- ### Options
210
+ ### Creating options
237
211
 
238
- - Option names and aliases must use a valid **JavaScript** variable name.
239
- - **Supports:** `camelCase`, `PascalCase`, `snake_case`, and `SCREAMING_SNAKE_CASE`.
240
- - **Examples:**
241
- - `I` or `i` ➡️ `-i`
242
- - `InputDir`, `inputDir`, or `INPUT_DIR` ➡️ `--input-dir`
243
- - `Help`, `help`, or `HELP` ➡️ `--help`
244
- - Do not use same options/aliases name with different casing.
245
- - Do not reuse the option/alias name within the same CLI/subcommand. TypeScript will throw a type error if duplicates exist.
246
- - The following properties are optional and used only for **metadata** such as help messages and documentation:
247
- - `description`
248
- - `example`
249
- - `placeholder`
212
+ Options can be defined directly inside the CLI or subcommand definition. Or using the `defineOptions` function.
250
213
 
251
- See the [Option](#option) type for more details.
214
+ Option names can use any common case style:
215
+ `camelCase`, `PascalCase`, `snake_case`, or `SCREAMING_SNAKE_CASE`.
216
+
217
+ - ListName `=>` --list-name
218
+ - list-name `=>` --list-name
219
+ - listName `=>` --list-name
220
+ - LIST_NAME `=>` --list-name
252
221
 
253
222
  ```ts
254
- import * as z from "zod";
255
- import { createCli } from "zod-args-parser";
256
-
257
- // Define the CLI schema
258
- const cliSchema = createCli({
259
- cliName: "my-cli",
260
- options: [
261
- {
262
- name: "inputDir", // camelCase option name becomes `--input-dir`
263
- aliases: ["i"], // single-letter alias becomes `-i`
264
- type: z.boolean().default(false), // optional because of default
265
- description: "Input directory",
266
- placeholder: "<dir>",
267
- example: "-i /path/to/dir",
268
- },
269
- {
270
- name: "verbose", // another option
271
- aliases: ["v"], // alias `-v`
272
- type: z.boolean().optional().describe("Enable verbose mode"), // using describe() instead of description
273
- },
274
- ],
275
- });
223
+ import { defineSubcommand, coerce } from "zod-args-parser";
276
224
 
277
- // Define the CLI action
278
- cliSchema.setAction(results => {
279
- const { inputDir, verbose } = results.options;
225
+ const createListCommand = defineSubcommand({
226
+ // ...
280
227
 
281
- // inputDir: boolean (optional, with default = false)
282
- // verbose: boolean | undefined (optional, no default)
283
- });
284
- ```
228
+ options: {
229
+ // The key is the option name
230
+ listName: {
231
+ // Aliases generate equivalent flags (e.g. -n, --name)
232
+ aliases: ["list", "name", "n"],
285
233
 
286
- ### Arguments
234
+ // Required string for this option
235
+ schema: z.string(),
287
236
 
288
- - Arguments are strictly typed **positional values**, defined as a tuple: `[arg1, arg2, arg3]`.
289
- - Each argument must have a **name**, which is used for help messages and documentation. TypeScript will throw a type error if duplicates name exist within the same CLI/subcommand.
290
- - The following properties are optional and used only for **metadata**:
291
- - `description`
292
- - `example`
237
+ // Converts the raw terminal input into a string.
238
+ // In this case, because the schema already expects a string, this coercion is redundant
239
+ coerce: coerce.string,
293
240
 
294
- > [!IMPORTANT]
295
- > Arguments are parsed strictly **in order**.
296
- >
297
- > - Only the **last argument** may be optional (when `allowPositional` is disabled).
298
- > - Mixing required and optional arguments (e.g., required → optional → required) will cause parsing errors because the parser cannot determine which value belongs to which argument.
299
- > - This means you **cannot have any optional arguments** if `allowPositional` is enabled.
300
- > - TypeScript will throw a type error if required and optional arguments are mixed, or when using `allowPositional: true` with optional arguments.
241
+ // When true: this option cannot appear alongside other options/arguments,
242
+ // except those listed in `requires`
243
+ exclusive: false,
301
244
 
302
- See the [Argument](#argument) type for more details.
245
+ // If this option is used, the listed options/arguments must also be provided
246
+ requires: [],
303
247
 
304
- ```ts
305
- import * as z from "zod";
306
- import { createCli } from "zod-args-parser";
307
-
308
- // Define the CLI schema
309
- const cliSchema = createCli({
310
- cliName: "my-cli",
311
- arguments: [
312
- {
313
- name: "inputFile", // argument name (camelCase for consistency)
314
- type: z.string(), // required
315
- description: "Input file",
316
- example: "input.txt",
317
- },
318
- {
319
- name: "outputFile", // second argument
320
- type: z.string().optional(), // optional (only allowed as the last arg)
321
- description: "Output file",
322
- example: "output.txt",
323
- },
324
- ],
325
- });
248
+ // Options/arguments that cannot be used together with this one
249
+ // Avoid using `conflictWith` when `exclusive` is true
250
+ conflictWith: [],
326
251
 
327
- // Define the CLI action
328
- cliSchema.setAction(results => {
329
- const [inputFile, outputFile] = results.arguments;
252
+ // Extra metadata used for help output and documentation
253
+ meta: {
254
+ // Shown next to the option name in terminal help and Markdown docs
255
+ placeholder: "<list> <items> <tags>",
330
256
 
331
- // inputFile: string (required)
332
- // outputFile: string | undefined (optional, no default)
333
- });
334
- ```
257
+ // Displayed in terminal help if both descriptions exist
258
+ // Not preferred in Markdown
259
+ description: "Plain text description shown in terminal help when both formats are provided.",
335
260
 
336
- ### Positionals
261
+ // Preferred in Markdown and kept formatted when printed in terminal output
262
+ descriptionMarkdown: "**Formatted** for terminal and preferred when generating **Markdown documentation**.",
337
263
 
338
- - Positionals are untyped **positional values**, always parsed as `string[]` of any length.
339
- - By default, positionals are **not allowed**. Enable them using the `allowPositional` option.
264
+ // Appears at the end of this option’s description in terminal help
265
+ // Rendered inside a code block in Markdown
266
+ example:
267
+ "listy add --list groceries --items egg,milk,bread --tags food\n" +
268
+ "listy add --list todos --items clean,cook --tags chores|work",
340
269
 
341
- > [!IMPORTANT]
342
- > If both typed arguments and positionals are used in the same CLI/subcommand, the **typed arguments are parsed first**, and only then are the remaining values collected as positionals.
270
+ // Shows this value as the default in help/docs (does not change runtime default)
271
+ default: `"default-list"`,
343
272
 
344
- ```ts
345
- import { createSubcommand } from "zod-args-parser";
346
-
347
- // Define the subcommand schema
348
- export const countSchema = createSubcommand({
349
- name: "count",
350
- aliases: ["list"],
351
- description: "Print a list of items provided by the user",
352
- allowPositional: true, // enable positionals
353
- });
273
+ // Shows this option as optional/required in help/docs (visual override only)
274
+ optional: false,
354
275
 
355
- // Define the subcommand action
356
- countSchema.setAction(results => {
357
- const items = results.positional; // string[]
276
+ // When true, hides this option from both help output and docs
277
+ hidden: false,
278
+ },
279
+ },
358
280
 
359
- if (items.length === 0) {
360
- console.log("No items provided");
361
- return;
362
- }
281
+ items: {
282
+ schema: z.string().array(),
283
+ // Parses comma-separated lists into string[]
284
+ coerce: coerce.stringArray(","),
285
+ },
363
286
 
364
- console.log("-- List of items --\n -", items.join("\n - "));
287
+ tags: {
288
+ schema: z.enum(["food", "work", "chores"]).array(),
289
+ // Parses pipe-separated tags into Set<string>
290
+ coerce: coerce.stringSet("|"),
291
+ },
292
+ },
365
293
  });
366
294
  ```
367
295
 
368
- ### Pre-Validation Hook
296
+ ### Creating typed arguments
369
297
 
370
- - The `preValidationHook` is called after parsing but before validation.
371
- - The provided context object can be modified before validation for advanced use cases.
372
- - When using **async** hooks, make sure to call [`parseAsync`](#parseasync) or [`safeParseAsync`](#parseasync).
298
+ Arguments can be defined directly inside the CLI or subcommand definition. Or using the `defineArguments` function.
373
299
 
374
- See the [Context](#context) type for more details.
300
+ The order of argument definitions matters.
375
301
 
376
- ```ts
377
- import * as z from "zod";
378
- import { createCli } from "zod-args-parser";
379
-
380
- // Define the CLI schema
381
- const cliSchema = createCli({
382
- cliName: "my-cli",
383
- options: [
384
- { name: "inputDir", type: z.string() },
385
- { name: "verbose", type: z.boolean().default(false) },
386
- ],
387
- arguments: [
388
- { name: "first-argument", type: z.string() },
389
- { name: "second-argument", type: z.string().optional() },
390
- ],
391
- });
302
+ **Rules**:
392
303
 
393
- // Define the pre-validation hook
394
- cliSchema.setPreValidationHook(ctx => {
395
- if (ctx.options.verbose.source === "default") {
396
- ctx.options.verbose.rawValue = "true";
397
- }
304
+ 1. If `allowPositionals: true` → typed arguments cannot be optional.
305
+ 2. If `allowPositionals: false` → only the last typed argument may be optional.
306
+ 3. Argument names cannot be numeric, because it affects argument ordering.
398
307
 
399
- if (ctx.arguments[0].source === "cli") {
400
- console.log("first-argument:", ctx.arguments[0].rawValue);
401
- }
402
- });
403
-
404
- // Define the CLI action
405
- cliSchema.setAction(results => {
406
- // can access `ctx` here
407
- console.log(results.ctx.options.verbose);
308
+ ```ts
309
+ import { defineSubcommand, coerce } from "zod-args-parser";
310
+
311
+ const createListCommand = defineSubcommand({
312
+ arguments: {
313
+ // In help output, argument names are automatically converted to kebab-case by default.
314
+ argumentName: {
315
+ // Same fields as options, but arguments do not support aliases
316
+ schema: z.string(),
317
+ coerce: coerce.string, // redundant (the input is already a string)
318
+ exclusive: false,
319
+ requires: [],
320
+ conflictWith: [],
321
+ meta: {
322
+ // Overrides the displayed argument name in help and documentation
323
+ name: "argument-name",
324
+
325
+ // Other meta fields work the same way as option metadata
326
+ },
327
+ },
328
+ },
408
329
  });
409
330
  ```
410
331
 
411
- ### Help Message
332
+ ### Using schemas
412
333
 
413
- Cli help message example preview
334
+ 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.
414
335
 
415
- <img width="1153" height="682" alt="image" src="https://github.com/user-attachments/assets/5610e5d0-8c08-4776-bbfc-b8e655241c39" /><br>
336
+ Here are some examples:
416
337
 
417
- Subcommand help message example preview
338
+ | Vendor | `string?` | `string="value"` | coerce |
339
+ | -------- | ------------------------ | --------------------------------- | --------------- |
340
+ | Zod | `z.string().optional()` | `z.string().default("value")` | `coerce.string` |
341
+ | Valibot | `v.optional(v.string())` | `v.optional(v.string(), "value")` | `coerce.string` |
342
+ | Decoders | `d.optional(v.string())` | `d.optional(v.string(), "value")` | `coerce.string` |
343
+ | Sury | `S.optional(v.string())` | `S.optional(v.string(), "value")` | `coerce.string` |
418
344
 
419
- <img width="1115" height="522" alt="image" src="https://github.com/user-attachments/assets/2a56a549-4059-45c4-84d2-93adaedaaac8" /><br>
345
+ | Vendor | `string[]?` | `string[]=["value"]` | coerce |
346
+ | -------- | --------------------------------- | -------------------------------------------- | ------------------------- |
347
+ | Zod | `z.array(z.string()).optional()` | `z.array(z.string()).default(["value"])` | `coerce.stringArray(",")` |
348
+ | Valibot | `v.optional(v.array(v.string()))` | `v.optional(v.array(v.string()), ["value"])` | `coerce.stringArray(",")` |
349
+ | Decoders | `d.optional(d.array(d.string))` | `d.optional(d.array(d.string), ["value"])` | `coerce.stringArray(",")` |
350
+ | Sury | `S.optional(S.array(S.string))` | `S.optional(S.array(S.string), ["value"])` | `coerce.stringArray(",")` |
420
351
 
421
- There are two ways to print the help message:
352
+ ### Default Values and Optional Inputs
422
353
 
423
- 1. `printCliHelp(style?: HelpMessageStyle)`
424
- Print the help message for the CLI.
354
+ - Optional values and defaults for **options and typed arguments** are controlled by the schema used for validation.
355
+ - `meta.optional` and `meta.default` only affect help/documentation output; they do **not** affect runtime behavior.
356
+ - The CLI parser enforces types and applies defaults according to the schema.
357
+ - Example schemas:
358
+ - `z.string().optional()` → optional input
359
+ - `z.string().default("value")` → input with default value
425
360
 
426
- 2. `printSubcommandHelp(subcommandName: string, style?: HelpMessageStyle)`
427
- Print the help message for a specific subcommand.
428
-
429
- See the [HelpMessageStyle](#helpmsgstyle) type for more details.
430
-
431
- ```ts
432
- import chalk from "chalk";
433
- import { formatCliHelpMsg, formatSubcommandHelpMsg, helpMessageStyles } from "zod-args-parser";
361
+ ### Positionals vs Typed Arguments
434
362
 
435
- // Define the CLI schema
436
- const cliSchema = createCli(/* ... */);
363
+ Think of typed arguments as **reserved seats** at the front of the line, and positionals as **everyone standing behind them**.
437
364
 
438
- // Define the subcommand schema
439
- const subcommandSchema = createSubcommand(/* ... */);
365
+ - Typed arguments are filled **in order from left to right**.
366
+ - Any remaining inputs become positionals **only if `allowPositionals: true`**.
440
367
 
441
- subcommandSchema.setAction(results => {
442
- // print help for CLI (without colors)
443
- results.printCliHelp(helpMessageStyles.noColors);
368
+ #### Rules
444
369
 
445
- // choose a style
446
- results.printCliHelp(helpMessageStyles.dracula);
370
+ | Setting | Behavior |
371
+ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
372
+ | `allowPositionals: true` | Typed arguments are parsed first. Remaining inputs go into `positionals`. Typed arguments **cannot** be optional in this mode. |
373
+ | `allowPositionals: false` | All inputs must match typed arguments. Only the **last** typed argument may be optional. Extra inputs cause an error. |
447
374
 
448
- // print help for subcommand (with custom title color)
449
- results.printSubcommandHelp("build", { title: chalk.red });
450
- });
375
+ ### Option and Argument Constraints
451
376
 
452
- const schemas = [cliSchema, subcommandSchema] as const;
377
+ Both options and typed arguments support rules to control valid combinations:
453
378
 
454
- // print help functions also accessible here
455
- const results = safeParse(args, ...schemas);
456
- if (results.success) {
457
- results.printCliHelp();
458
- }
379
+ #### `exclusive: boolean`
459
380
 
460
- // get the string without printing to console
461
- const cliHelp = formatCliHelpMsg(schemas, helpMessageStyles.html);
462
- console.log(`<pre style="background-color: #1e1e2e">${cliHelp}</pre>`);
381
+ - Cannot be used together with other options or arguments, except those explicitly listed in `requires`.
463
382
 
464
- const subcommandHelp = formatSubcommandHelpMsg(subcommandSchema, helpMessageStyles.html, cliSchema.cliName);
465
- console.log(`<pre style="background-color: #1e1e2e">${subcommandHelp}</pre>`);
466
- ```
383
+ #### `requires: string[]`
467
384
 
468
- ### Zod Utilities
385
+ - Lists other options/arguments names (not aliases) that **must be provided** if this one is used.
386
+ - Helps enforce dependencies between flags or arguments.
469
387
 
470
- - `isOptionalSchema(schema: ZodTypeAny): boolean`
471
- Check if a schema is optional or has a default value.
388
+ #### `conflictWith: string[]`
472
389
 
473
- - `schemaDefaultValue(schema: ZodTypeAny): unknown | undefined`
474
- Get the default value of a schema if it has one.
390
+ - Lists other options/arguments names (not aliases) that **cannot be used together** with this one.
391
+ - Prevents incompatible combinations and avoids ambiguous behavior.
475
392
 
476
- - `stringToArray(value: string, separator?: string = ","): string[]`
477
- A preprocessing handle to convert a string to an array.
393
+ ### Negating a boolean option
478
394
 
479
- - `stringToSet(value: string, separator?: string = ","): Set<string>`
480
- A preprocessing handle to convert a string to a set.
395
+ Boolean options can be negated by prefixing them with `no-` or by using the equals sign `=`.
481
396
 
482
- ```ts
483
- import * as z from "zod";
484
- import { createCli, isOptionalSchema, schemaDefaultValue, stringToArray } from "zod-args-parser";
485
-
486
- const cliSchema = createCli({
487
- cliName: "my-cli",
488
- options: [
489
- {
490
- name: "tags",
491
- aliases: ["t"],
492
- placeholder: "<list>",
493
- description: "tags separated by semicolon (;)",
494
- example: "--tags tag1;tag2;tag3",
495
- type: z.preprocess((value: string) => stringToArray(value, ";"), z.array(z.string())),
496
- },
497
- {
498
- name: "verbose",
499
- aliases: ["v"],
500
- description: "Verbose mode",
501
- type: z.boolean().default(false),
502
- },
503
- ],
504
- });
397
+ ```sh
398
+ --bool true
399
+ --no-bool false
505
400
 
506
- cliSchema.setAction(results => {
507
- const ctxOptions = results.ctx.options;
401
+ --bool=true true
402
+ --bool=false false
508
403
 
509
- console.log(
510
- isOptionalSchema(ctxOptions.verbose.schema), // true
511
- schemaDefaultValue(ctxOptions.verbose.schema), // false
512
- );
513
- });
404
+ -v true
405
+ --no-v false
514
406
  ```
515
407
 
516
- ### Type Utilities
517
-
518
- - `InferOptionsInput<Cli | Subcommand>`
519
- Infer the options input type (before zod validation) from the Cli or subcommand schema.
520
-
521
- - `InferOptionsOutput<Cli | Subcommand>`
522
- Infer the options Output type (after zod validation) from the Cli or subcommand schema.
408
+ ### Creating a Custom Help Message Style
523
409
 
524
- - `InferArgumentsInput<Cli | Subcommand>`
525
- Infer the arguments input type (before zod validation) from the Cli or subcommand schema.
526
-
527
- - `InferArgumentsOutput<Cli | Subcommand>`
528
- Infer the arguments Output type (after zod validation) from the Cli or subcommand schema.
410
+ You can define a custom style for CLI help messages by implementing the `HelpMessageStyle` interface. A common approach is to start from an existing style and override only the parts you want.
529
411
 
530
412
  ```ts
531
- import { createSubcommand } from "zod-args-parser";
532
- import type { InferOptionsOutput, InferArgumentsOutput } from "zod-args-parser";
533
-
534
- const subcommand = createSubcommand({
535
- name: "subcommand",
536
- options: [
537
- { name: "numberOption", type: z.coerce.number() },
538
- { name: "stringOption", type: z.string() },
539
- { name: "booleanOption", type: z.boolean() },
540
- { name: "optionalOption", type: z.boolean().optional() },
541
- ],
542
- arguments: [
543
- { name: "stringArgument", type: z.string() },
544
- { name: "numberArgument", type: z.coerce.number() },
545
- { name: "booleanArgument", type: z.boolean() },
546
- ],
547
- });
413
+ import chalk from "chalk";
414
+ import { HelpMessageStyle, helpMessageStyles } from "zod-args-parser";
548
415
 
549
- type Options = InferOptionsOutput<typeof subcommand>;
550
- // { numberOption: number; stringOption: string; booleanOption: boolean; optionalOption?: boolean | undefined; }
416
+ // Example: create a new style based on the default style
417
+ const myCustomStyle = new HelpMessageStyle(
418
+ {
419
+ title: chalk.bold.magenta,
420
+ option: chalk.yellow,
421
+ argument: chalk.green,
422
+ },
423
+ // optionally use default style as base
424
+ helpMessageStyles.default,
425
+ );
551
426
 
552
- type Arguments = InferArgumentsOutput<typeof subcommand>;
553
- // [string, number, boolean]
427
+ // Use the custom style when generating help
428
+ console.log(myCli.generateCliHelpMessage({ style: myCustomStyle }));
554
429
  ```
555
430
 
556
- ## API Reference
557
-
558
- ### Methods
559
-
560
- #### createCli
431
+ ### Help Message as HTML
561
432
 
562
- `(schema: Cli) => Cli & SetMethods<Cli>`
433
+ You can generate the CLI help message as HTML using the `html` style and insert it into a `<pre>` element.
563
434
 
564
- Creates the CLI program schema.
565
-
566
- See [Cli](#cli) object type.
435
+ ```ts
436
+ import { listyCLI, helpMessageStyles, generateCliHelpMessage } from "zod-args-parser";
567
437
 
568
- #### createSubcommand
438
+ // Generate help message as HTML string
439
+ const htmlHelp = generateCliHelpMessage(listyCLI, { style: helpMessageStyles.html, markdownRenderer: "html" });
569
440
 
570
- `(schema: Subcommand) => Subcommand & SetMethods<Subcommand>`
441
+ // Insert into a <pre> element in your page
442
+ const pre = document.createElement("pre");
443
+ pre.innerHTML = htmlHelp;
444
+ document.body.appendChild(pre);
445
+ ```
571
446
 
572
- Creates the subcommand schema.
447
+ You can style Markdown content using CSS:
573
448
 
574
- See [Subcommand](#subcommand) object type.
449
+ ```css
450
+ span._markdown * {
451
+ white-space: initial;
452
+ }
453
+ ```
575
454
 
576
- #### createOptions
455
+ ## API Reference
577
456
 
578
- `(schema: Option[]) => Option[]`
457
+ ### Type Utilities
579
458
 
580
- Creates an array of option schemas for option sharing.
459
+ #### `InferInputType<T extends Cli | Subcommand>`
581
460
 
582
- See [Option](#option) object type.
461
+ Infer options, arguments, and positionals input types from the CLI/subcommand definition.
583
462
 
584
- #### createArguments
463
+ #### `InferOutputType<T extends Cli | Subcommand>`
585
464
 
586
- `(schema: Argument[]) => Argument[]`
465
+ Infer options, arguments, and positionals output types from the CLI/subcommand definition.
587
466
 
588
- Creates an array of argument schemas for argument sharing.
467
+ #### `InferOptionsInputType<T extends Cli | Subcommand>`
589
468
 
590
- See [Argument](#argument) object type.
469
+ Infer options input type from the CLI/subcommand definition.
591
470
 
592
- #### parse
471
+ #### `InferOptionsOutputType<T extends Cli | Subcommand>`
593
472
 
594
- `(args: string[], cli: Cli, ...subcommands: Subcommand[]) => Result`
473
+ Infer options output type from the CLI/subcommand definition.
595
474
 
596
- Parses and validates the provided arguments and throws an error if parsing or validation failed.
475
+ #### `InferArgumentsInputType<T extends Cli | Subcommand>`
597
476
 
598
- See [Cli](#cli), [Subcommand](#subcommand), and [Results](#results)
477
+ Infer arguments input type from the CLI/subcommand definition.
599
478
 
600
- #### parseAsync
479
+ #### `InferArgumentsOutputType<T extends Cli | Subcommand>`
601
480
 
602
- `(args: string[], cli: Cli, ...subcommands: Subcommand[]) => Promise<Result>`
481
+ Infer arguments output type from the CLI/subcommand definition.
603
482
 
604
- Same as [`parse`](#parse), but returns a promise.
605
- Use this when you have async actions or hooks.
483
+ ```ts
484
+ import type { defineSubcommand, InferInputType, InferOutputType } from "zod-args-parser";
606
485
 
607
- See [Cli](#cli), [Subcommand](#subcommand), and [Results](#results)
486
+ const subcommand = defineSubcommand({
487
+ // ...
488
+ });
608
489
 
609
- #### safeParse
490
+ type InputType = InferInputType<typeof subcommand>;
491
+ type OutputType = InferOutputType<typeof subcommand>;
492
+ ```
610
493
 
611
- `(args: string[], cli: Cli, ...subcommands: Subcommand[]) => { success: false, error: Error } | { success: true, data: Result }`
494
+ ### Coerce Helpers
612
495
 
613
- Parses and validates the provided arguments without throwing an error.
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>()`
614
506
 
615
- See [Cli](#cli), [Subcommand](#subcommand), and [Results](#results)
507
+ ### Markdown Generation
616
508
 
617
- #### safeParseAsync
509
+ #### generateMarkdown
618
510
 
619
- `(args: string[], cli: Cli, ...subcommands: Subcommand[]) => Promise<...>`
511
+ `(cliDefinition: Cli) => string`
620
512
 
621
- Same as [`safeParse`](#safeparse), but returns a promise.
622
- Use this when you have async actions or hooks.
513
+ Generate markdown documentation for a **CLI definition** and return it as a `string`.
623
514
 
624
- See [Cli](#cli), [Subcommand](#subcommand), and [Results](#results)
515
+ ### Autocomplete Script Generation
625
516
 
626
517
  #### generateBashAutocompleteScript
627
518
 
628
- `(...params: [Cli, ...Subcommand[]]) => string`
629
-
630
- Generates an autocomplete script for `bash`.
631
-
632
- See [Cli](#cli) and [Subcommand](#subcommand)
519
+ `(cliDefinition: Cli) => string`
633
520
 
634
- #### generatePowerShellAutocompleteScript
635
-
636
- `(...params: [Cli, ...Subcommand[]]) => string`
637
-
638
- Generates an autocomplete script for `powershell`.
639
-
640
- See [Cli](#cli) and [Subcommand](#subcommand)
521
+ Generate a Bash autocomplete script for a **CLI definition** and return it as a `string`.
641
522
 
642
523
  #### generateZshAutocompleteScript
643
524
 
644
- `(...params: [Cli, ...Subcommand[]]) => string`
645
-
646
- Generates an autocomplete script for `zsh`.
647
-
648
- See [Cli](#cli) and [Subcommand](#subcommand)
649
-
650
- #### generateMarkdown
651
-
652
- `(...params: [Cli, ...Subcommand[]]) => string`
653
-
654
- Generates a markdown documentation for your CLI.
525
+ `(cliDefinition: Cli) => string`
655
526
 
656
- See [Cli](#cli) and [Subcommand](#subcommand)
527
+ Generate a zsh autocomplete script for a **CLI definition** and return it as a `string`.
657
528
 
658
- ### Types
659
-
660
- #### Cli
661
-
662
- | Name | Type | Description | Example |
663
- | --------------- | -------------------------- | ---------------------------------------------- | ------------------------------ |
664
- | cliName | `string` | The name of the CLI program. | `"my-cli"` |
665
- | description | `string?` | A description of the CLI for the help message. | `"Build the project"` |
666
- | usage | `string?` | The usage of the CLI for the help message. | `"my-cli build"` |
667
- | example | `string?` | An example of CLI usage for the help message. | `"my-cli <command> [options]"` |
668
- | options | [`Option[]?`](#option) | An array of options for the CLI. | |
669
- | arguments | [`Argument[]?`](#argument) | An array of arguments for the CLI. | |
670
- | allowPositional | `boolean?` | Allows positional arguments for the CLI. | |
671
-
672
- #### Subcommand
673
-
674
- | Name | Type | Description | Example |
675
- | --------------- | -------------------------- | ----------------------------------------------------- | -------------------------- |
676
- | name | `string` | The name of the subcommand. | `"build"` |
677
- | aliases | `string[]?` | An array of aliases for the subcommand. | `["b", "build"]` |
678
- | description | `string?` | A description of the subcommand for the help message. | `"Build the project"` |
679
- | usage | `string?` | The usage of the subcommand for the help message. | `"my-cli build"` |
680
- | placeholder | `string?` | A placeholder displayed in the help message. | `"[options]"` |
681
- | example | `string?` | An example of subcommand usage for the help message. | `"my-cli build [options]"` |
682
- | options | [`Option[]?`](#option) | An array of options for the subcommand. | |
683
- | arguments | [`Argument[]?`](#argument) | An array of arguments for the subcommand. | |
684
- | allowPositional | `boolean?` | Allows positional arguments for this subcommand. | |
529
+ #### generatePowerShellAutocompleteScript
685
530
 
686
- #### Option
531
+ `(cliDefinition: Cli) => string`
687
532
 
688
- | Name | Type | Description | Example |
689
- | ----------- | ----------- | ---------------------------------------------------- | ------------------------------- |
690
- | name | `string` | The name of the option. camelCase is recommended. | `"inputDir"` -> `--input-dir` |
691
- | type | `ZodType` | Specifies the type of the option using Zod schema. | `z.boolean().default(false)` |
692
- | aliases | `string[]?` | An array of aliases for the option. | `["i", "dir"]` -> `-i`, `--dir` |
693
- | description | `string?` | A description of the option for the help message. | `"Input directory"` |
694
- | placeholder | `string?` | Placeholder text for the option in the help message. | `"<dir>"` or `"<path>"` |
695
- | example | `string?` | An example of option usage for the help message. | `"-i /path/to/dir"` |
533
+ Generate a PowerShell autocomplete script for a **CLI definition** and return it as a `string`.
696
534
 
697
- #### Argument
535
+ ### Help Message
698
536
 
699
- | Name | Type | Description | Example |
700
- | ----------- | --------- | ---------------------------------------------------- | ----------------------------------- |
701
- | name | `string` | The name of the argument for the help message. | `"command-name"` |
702
- | type | `ZodType` | Specifies the type of the argument using Zod schema. | `z.enum(["build", "help", "init"])` |
703
- | description | `string?` | A description of the argument for the help message. | `"Command to print help for"` |
704
- | example | `string?` | An example of argument usage for the help message. | `"help build"` |
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).
557
+
558
+ #### printSubcommandHelp
559
+
560
+ `(commandDefinition: Subcommand, options?: PrintHelpOptions, cliName?: string) => void`
561
+
562
+ Print a help message for a **subcommand definition**.
563
+ See [`PrintHelpOptions`](#printhelpoptions) and [`Subcommand`](#subcommand).
564
+
565
+ ### PrintHelpOptions
566
+
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. |
588
+
589
+ ### Cli
590
+
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. |
599
+
600
+ ### CliMeta
601
+
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). |
608
+
609
+ ### Subcommand
610
+
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. |
619
+
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.
705
674
 
706
675
  #### Context
707
676
 
708
- The context object is generated after parsing the CLI arguments and before validation.
709
-
710
- | Name | Type | Description |
711
- | ---------- | ---------------------------------------- | -------------------------------------------------------------------------------------------------------- |
712
- | subcommand | `string \| undefined` | The name of the executed subcommand. |
713
- | options | `{ [OptionName: string]: ParsedOption }` | A map of parsed options for the CLI/subcommand. |
714
- | arguments | `ParsedArgument[] \| undefined` | An array of parsed arguments for the CLI/subcommand. See [`ParsedArgument`](#parsedargument) |
715
- | positional | `string[] \| undefined` | Contains positional arguments when `allowPositional` is enabled. See [`ParsedArgument`](#parsedargument) |
716
-
717
- ##### ParsedOption
718
-
719
- | Name | Type | Description |
720
- | -------- | --------------------- | ---------------------------------------------------------------------------------------------- |
721
- | name | `string` | The name of the option (e.g. `foo` or `f`). |
722
- | flag | `string \| undefined` | The CLI flag as provided in the terminal (e.g. `--foo` or `-f`). |
723
- | schema | `ZodTypeAny` | The schema that validates this option. |
724
- | rawValue | `string \| undefined` | The string value as provided in the terminal. boolean flags are inferred into boolean strings. |
725
- | source | `"cli" \| "default"` | `cli`: provided explicitly in the CLI, `default`: not provided, and the schema has a default. |
726
-
727
- ##### ParsedArgument
728
-
729
- | Name | Type | Description |
730
- | -------- | --------------------- | --------------------------------------------------------------------------------------------- |
731
- | schema | `ZodTypeAny` | The schema that validates this argument. |
732
- | rawValue | `string \| undefined` | The raw string value supplied for this argument from the CLI. |
733
- | source | `"cli" \| "default"` | `cli`: provided explicitly in the CLI, `default`: not provided, and the schema has a default. |
734
-
735
- #### Results
736
-
737
- | Name | Type | Description |
738
- | ---------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------- |
739
- | subcommand | `string \| undefined` | The name of the executed subcommand. |
740
- | `[optionName: string]` | `unknown` | Validated options for the CLI/subcommand. |
741
- | arguments | `unknown[] \| undefined` | Validated arguments for the CLI/subcommand. |
742
- | positional | `string[] \| undefined` | Positional array for the CLI/subcommand. |
743
- | printCliHelp | `(style?: HelpMessageStyle) => void` | Prints the CLI help message. See [HelpMessageStyle](#helpmsgstyle) |
744
- | printSubcommandHelp | `(subcommand: string, style?: HelpMessageStyle) => void` | Prints the help message for a specified subcommand. See [HelpMessageStyle](#helpmsgstyle) |
745
-
746
- #### HelpMessageStyle
747
-
748
- Available styles: `default`, `dracula`, `solarizedDark`, `nord`, `html`, `gruvboxDark`, `monokai`, `oneDark`, `noColors`
749
-
750
- Each style has the following properties:
751
-
752
- | Key | Type | Default |
753
- | ------------ | -------------------------------- | ---------------------- |
754
- | title | `(...text: unknown[]) => string` | `chalk.bold.blue` |
755
- | description | `(...text: unknown[]) => string` | `chalk.white` |
756
- | default | `(...text: unknown[]) => string` | `chalk.dim.italic` |
757
- | optional | `(...text: unknown[]) => string` | `chalk.dim.italic` |
758
- | exampleTitle | `(...text: unknown[]) => string` | `chalk.yellow` |
759
- | example | `(...text: unknown[]) => string` | `chalk.dim` |
760
- | command | `(...text: unknown[]) => string` | `chalk.yellow` |
761
- | option | `(...text: unknown[]) => string` | `chalk.cyan` |
762
- | argument | `(...text: unknown[]) => string` | `chalk.green` |
763
- | placeholder | `(...text: unknown[]) => string` | `chalk.hex("#FF9800")` |
764
- | punctuation | `(...text: unknown[]) => string` | `chalk.white.dim` |
765
-
766
- ## Example
767
-
768
- - [Example code](https://github.com/alabsi91/zod-args-parser/tree/main/example)
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. |
769
706
 
770
707
  ## License
771
708