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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (474) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +244 -282
  3. package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js +74 -2
  4. package/lib/esm/autocomplete-scripts/bash-autocomplete-script.js.map +7 -1
  5. package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js +90 -2
  6. package/lib/esm/autocomplete-scripts/powershell-autocomplete-script.js.map +7 -1
  7. package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js +39 -13
  8. package/lib/esm/autocomplete-scripts/zsh-autocomplete-script.js.map +7 -1
  9. package/lib/esm/cli-error/cli-error.js +38 -0
  10. package/lib/esm/cli-error/cli-error.js.map +7 -0
  11. package/lib/esm/cli-error/error-cause.js +12 -0
  12. package/lib/esm/cli-error/error-cause.js.map +7 -0
  13. package/lib/esm/cli-error/error-code/definition-error-code.js +23 -0
  14. package/lib/esm/cli-error/error-code/definition-error-code.js.map +7 -0
  15. package/lib/esm/cli-error/error-code/internal-error-code.js +10 -0
  16. package/lib/esm/cli-error/error-code/internal-error-code.js.map +7 -0
  17. package/lib/esm/cli-error/error-code/parse-error-code.js +18 -0
  18. package/lib/esm/cli-error/error-code/parse-error-code.js.map +7 -0
  19. package/lib/esm/cli-error/error-code/validation-error-code.js +17 -0
  20. package/lib/esm/cli-error/error-code/validation-error-code.js.map +7 -0
  21. package/lib/esm/cli-error/error-message/definition-error-message.js +70 -0
  22. package/lib/esm/cli-error/error-message/definition-error-message.js.map +7 -0
  23. package/lib/esm/cli-error/error-message/internal-error-message.js +16 -0
  24. package/lib/esm/cli-error/error-message/internal-error-message.js.map +7 -0
  25. package/lib/esm/cli-error/error-message/parse-error-message.js +40 -0
  26. package/lib/esm/cli-error/error-message/parse-error-message.js.map +7 -0
  27. package/lib/esm/cli-error/error-message/validation-error-message.js +60 -0
  28. package/lib/esm/cli-error/error-message/validation-error-message.js.map +7 -0
  29. package/lib/esm/coerce/coerce-methods.js +197 -2
  30. package/lib/esm/coerce/coerce-methods.js.map +7 -1
  31. package/lib/esm/coerce/string-to-array.js +17 -2
  32. package/lib/esm/coerce/string-to-array.js.map +7 -1
  33. package/lib/esm/coerce/string-to-primitive.js +73 -2
  34. package/lib/esm/coerce/string-to-primitive.js.map +7 -1
  35. package/lib/esm/coerce/string-to-set.js +17 -2
  36. package/lib/esm/coerce/string-to-set.js.map +7 -1
  37. package/lib/esm/definitions/define-arguments.js +10 -2
  38. package/lib/esm/definitions/define-arguments.js.map +7 -1
  39. package/lib/esm/definitions/define-cli.js +89 -2
  40. package/lib/esm/definitions/define-cli.js.map +7 -1
  41. package/lib/esm/definitions/define-options.js +10 -2
  42. package/lib/esm/definitions/define-options.js.map +7 -1
  43. package/lib/esm/definitions/define-subcommand.js +56 -2
  44. package/lib/esm/definitions/define-subcommand.js.map +7 -1
  45. package/lib/esm/definitions/validate-cli-definition.js +360 -2
  46. package/lib/esm/definitions/validate-cli-definition.js.map +7 -1
  47. package/lib/esm/help-message/format-arguments.js +48 -2
  48. package/lib/esm/help-message/format-arguments.js.map +7 -1
  49. package/lib/esm/help-message/format-options.js +50 -2
  50. package/lib/esm/help-message/format-options.js.map +7 -1
  51. package/lib/esm/help-message/format-subcommands.js +37 -2
  52. package/lib/esm/help-message/format-subcommands.js.map +7 -1
  53. package/lib/esm/help-message/generate-for-cli.js +71 -2
  54. package/lib/esm/help-message/generate-for-cli.js.map +7 -1
  55. package/lib/esm/help-message/generate-for-subcommand.js +23 -2
  56. package/lib/esm/help-message/generate-for-subcommand.js.map +7 -1
  57. package/lib/esm/help-message/print-help.js +14 -2
  58. package/lib/esm/help-message/print-help.js.map +7 -1
  59. package/lib/esm/help-message/set-defaults.js +29 -2
  60. package/lib/esm/help-message/set-defaults.js.map +7 -1
  61. package/lib/esm/help-message/styles.js +154 -2
  62. package/lib/esm/help-message/styles.js.map +7 -1
  63. package/lib/esm/help-message/terminal-markdown.js +121 -2
  64. package/lib/esm/help-message/terminal-markdown.js.map +7 -1
  65. package/lib/esm/index.js +52 -2
  66. package/lib/esm/index.js.map +7 -1
  67. package/lib/esm/markdown/generate-markdown.js +153 -2
  68. package/lib/esm/markdown/generate-markdown.js.map +7 -1
  69. package/lib/esm/metadata/arguments-metadata.js +26 -2
  70. package/lib/esm/metadata/arguments-metadata.js.map +7 -1
  71. package/lib/esm/metadata/cli-metadata.js +24 -2
  72. package/lib/esm/metadata/cli-metadata.js.map +7 -1
  73. package/lib/esm/metadata/options-metadata.js +35 -2
  74. package/lib/esm/metadata/options-metadata.js.map +7 -1
  75. package/lib/esm/metadata/subcommands-metadata.js +32 -2
  76. package/lib/esm/metadata/subcommands-metadata.js.map +7 -1
  77. package/lib/esm/parse/context/cli-context-builder.js +283 -2
  78. package/lib/esm/parse/context/cli-context-builder.js.map +7 -1
  79. package/lib/esm/parse/context/object-context-builder.js +62 -2
  80. package/lib/esm/parse/context/object-context-builder.js.map +7 -1
  81. package/lib/esm/parse/parser-utilities.js +108 -2
  82. package/lib/esm/parse/parser-utilities.js.map +7 -1
  83. package/lib/esm/parse/safe-parse.js +57 -2
  84. package/lib/esm/parse/safe-parse.js.map +7 -1
  85. package/lib/esm/parse/validation/validate-context.js +17 -2
  86. package/lib/esm/parse/validation/validate-context.js.map +7 -1
  87. package/lib/esm/parse/validation/validators/arguments.js +67 -2
  88. package/lib/esm/parse/validation/validators/arguments.js.map +7 -1
  89. package/lib/esm/parse/validation/validators/conflict.js +38 -2
  90. package/lib/esm/parse/validation/validators/conflict.js.map +7 -1
  91. package/lib/esm/parse/validation/validators/exclusive.js +39 -2
  92. package/lib/esm/parse/validation/validators/exclusive.js.map +7 -1
  93. package/lib/esm/parse/validation/validators/explicitly-passed.js +18 -2
  94. package/lib/esm/parse/validation/validators/explicitly-passed.js.map +7 -1
  95. package/lib/esm/parse/validation/validators/options.js +67 -2
  96. package/lib/esm/parse/validation/validators/options.js.map +7 -1
  97. package/lib/esm/parse/validation/validators/requires.js +43 -2
  98. package/lib/esm/parse/validation/validators/requires.js.map +7 -1
  99. package/lib/esm/utilities/parse-argv.js +61 -0
  100. package/lib/esm/utilities/parse-argv.js.map +7 -0
  101. package/lib/esm/utilities/schema-utilities.js +57 -0
  102. package/lib/esm/utilities/schema-utilities.js.map +7 -0
  103. package/lib/esm/utilities/utilities.js +122 -0
  104. package/lib/esm/utilities/utilities.js.map +7 -0
  105. package/lib/iife/index.js +41 -1
  106. package/lib/iife/index.js.map +1 -1
  107. package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs +74 -2
  108. package/lib/mjs/autocomplete-scripts/bash-autocomplete-script.mjs.map +7 -1
  109. package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs +90 -2
  110. package/lib/mjs/autocomplete-scripts/powershell-autocomplete-script.mjs.map +7 -1
  111. package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs +39 -13
  112. package/lib/mjs/autocomplete-scripts/zsh-autocomplete-script.mjs.map +7 -1
  113. package/lib/mjs/cli-error/cli-error.mjs +38 -0
  114. package/lib/mjs/cli-error/cli-error.mjs.map +7 -0
  115. package/lib/mjs/cli-error/error-cause.mjs +12 -0
  116. package/lib/mjs/cli-error/error-cause.mjs.map +7 -0
  117. package/lib/mjs/cli-error/error-code/definition-error-code.mjs +23 -0
  118. package/lib/mjs/cli-error/error-code/definition-error-code.mjs.map +7 -0
  119. package/lib/mjs/cli-error/error-code/internal-error-code.mjs +10 -0
  120. package/lib/mjs/cli-error/error-code/internal-error-code.mjs.map +7 -0
  121. package/lib/mjs/cli-error/error-code/parse-error-code.mjs +18 -0
  122. package/lib/mjs/cli-error/error-code/parse-error-code.mjs.map +7 -0
  123. package/lib/mjs/cli-error/error-code/validation-error-code.mjs +17 -0
  124. package/lib/mjs/cli-error/error-code/validation-error-code.mjs.map +7 -0
  125. package/lib/mjs/cli-error/error-message/definition-error-message.mjs +70 -0
  126. package/lib/mjs/cli-error/error-message/definition-error-message.mjs.map +7 -0
  127. package/lib/mjs/cli-error/error-message/internal-error-message.mjs +16 -0
  128. package/lib/mjs/cli-error/error-message/internal-error-message.mjs.map +7 -0
  129. package/lib/mjs/cli-error/error-message/parse-error-message.mjs +40 -0
  130. package/lib/mjs/cli-error/error-message/parse-error-message.mjs.map +7 -0
  131. package/lib/mjs/cli-error/error-message/validation-error-message.mjs +60 -0
  132. package/lib/mjs/cli-error/error-message/validation-error-message.mjs.map +7 -0
  133. package/lib/mjs/coerce/coerce-methods.mjs +197 -2
  134. package/lib/mjs/coerce/coerce-methods.mjs.map +7 -1
  135. package/lib/mjs/coerce/string-to-array.mjs +17 -2
  136. package/lib/mjs/coerce/string-to-array.mjs.map +7 -1
  137. package/lib/mjs/coerce/string-to-primitive.mjs +73 -2
  138. package/lib/mjs/coerce/string-to-primitive.mjs.map +7 -1
  139. package/lib/mjs/coerce/string-to-set.mjs +17 -2
  140. package/lib/mjs/coerce/string-to-set.mjs.map +7 -1
  141. package/lib/mjs/definitions/define-arguments.mjs +10 -2
  142. package/lib/mjs/definitions/define-arguments.mjs.map +7 -1
  143. package/lib/mjs/definitions/define-cli.mjs +89 -2
  144. package/lib/mjs/definitions/define-cli.mjs.map +7 -1
  145. package/lib/mjs/definitions/define-options.mjs +10 -2
  146. package/lib/mjs/definitions/define-options.mjs.map +7 -1
  147. package/lib/mjs/definitions/define-subcommand.mjs +56 -2
  148. package/lib/mjs/definitions/define-subcommand.mjs.map +7 -1
  149. package/lib/mjs/definitions/validate-cli-definition.mjs +360 -2
  150. package/lib/mjs/definitions/validate-cli-definition.mjs.map +7 -1
  151. package/lib/mjs/help-message/format-arguments.mjs +48 -2
  152. package/lib/mjs/help-message/format-arguments.mjs.map +7 -1
  153. package/lib/mjs/help-message/format-options.mjs +50 -2
  154. package/lib/mjs/help-message/format-options.mjs.map +7 -1
  155. package/lib/mjs/help-message/format-subcommands.mjs +37 -2
  156. package/lib/mjs/help-message/format-subcommands.mjs.map +7 -1
  157. package/lib/mjs/help-message/generate-for-cli.mjs +71 -2
  158. package/lib/mjs/help-message/generate-for-cli.mjs.map +7 -1
  159. package/lib/mjs/help-message/generate-for-subcommand.mjs +23 -2
  160. package/lib/mjs/help-message/generate-for-subcommand.mjs.map +7 -1
  161. package/lib/mjs/help-message/print-help.mjs +14 -2
  162. package/lib/mjs/help-message/print-help.mjs.map +7 -1
  163. package/lib/mjs/help-message/set-defaults.mjs +29 -2
  164. package/lib/mjs/help-message/set-defaults.mjs.map +7 -1
  165. package/lib/mjs/help-message/styles.mjs +154 -2
  166. package/lib/mjs/help-message/styles.mjs.map +7 -1
  167. package/lib/mjs/help-message/terminal-markdown.mjs +121 -2
  168. package/lib/mjs/help-message/terminal-markdown.mjs.map +7 -1
  169. package/lib/mjs/index.mjs +52 -2
  170. package/lib/mjs/index.mjs.map +7 -1
  171. package/lib/mjs/markdown/generate-markdown.mjs +153 -2
  172. package/lib/mjs/markdown/generate-markdown.mjs.map +7 -1
  173. package/lib/mjs/metadata/arguments-metadata.mjs +26 -2
  174. package/lib/mjs/metadata/arguments-metadata.mjs.map +7 -1
  175. package/lib/mjs/metadata/cli-metadata.mjs +24 -2
  176. package/lib/mjs/metadata/cli-metadata.mjs.map +7 -1
  177. package/lib/mjs/metadata/options-metadata.mjs +35 -2
  178. package/lib/mjs/metadata/options-metadata.mjs.map +7 -1
  179. package/lib/mjs/metadata/subcommands-metadata.mjs +32 -2
  180. package/lib/mjs/metadata/subcommands-metadata.mjs.map +7 -1
  181. package/lib/mjs/parse/context/cli-context-builder.mjs +283 -2
  182. package/lib/mjs/parse/context/cli-context-builder.mjs.map +7 -1
  183. package/lib/mjs/parse/context/object-context-builder.mjs +62 -2
  184. package/lib/mjs/parse/context/object-context-builder.mjs.map +7 -1
  185. package/lib/mjs/parse/parser-utilities.mjs +108 -2
  186. package/lib/mjs/parse/parser-utilities.mjs.map +7 -1
  187. package/lib/mjs/parse/safe-parse.mjs +57 -2
  188. package/lib/mjs/parse/safe-parse.mjs.map +7 -1
  189. package/lib/mjs/parse/validation/validate-context.mjs +17 -2
  190. package/lib/mjs/parse/validation/validate-context.mjs.map +7 -1
  191. package/lib/mjs/parse/validation/validators/arguments.mjs +67 -2
  192. package/lib/mjs/parse/validation/validators/arguments.mjs.map +7 -1
  193. package/lib/mjs/parse/validation/validators/conflict.mjs +38 -2
  194. package/lib/mjs/parse/validation/validators/conflict.mjs.map +7 -1
  195. package/lib/mjs/parse/validation/validators/exclusive.mjs +39 -2
  196. package/lib/mjs/parse/validation/validators/exclusive.mjs.map +7 -1
  197. package/lib/mjs/parse/validation/validators/explicitly-passed.mjs +18 -2
  198. package/lib/mjs/parse/validation/validators/explicitly-passed.mjs.map +7 -1
  199. package/lib/mjs/parse/validation/validators/options.mjs +67 -2
  200. package/lib/mjs/parse/validation/validators/options.mjs.map +7 -1
  201. package/lib/mjs/parse/validation/validators/requires.mjs +43 -2
  202. package/lib/mjs/parse/validation/validators/requires.mjs.map +7 -1
  203. package/lib/mjs/utilities/parse-argv.mjs +61 -0
  204. package/lib/mjs/utilities/parse-argv.mjs.map +7 -0
  205. package/lib/mjs/utilities/schema-utilities.mjs +57 -0
  206. package/lib/mjs/utilities/schema-utilities.mjs.map +7 -0
  207. package/lib/mjs/utilities/utilities.mjs +122 -0
  208. package/lib/mjs/utilities/utilities.mjs.map +7 -0
  209. package/lib/{typescript → types}/autocomplete-scripts/bash-autocomplete-script.d.ts.map +1 -1
  210. package/lib/types/autocomplete-scripts/powershell-autocomplete-script.d.ts +15 -0
  211. package/lib/{typescript → types}/autocomplete-scripts/powershell-autocomplete-script.d.ts.map +1 -1
  212. package/lib/types/autocomplete-scripts/zsh-autocomplete-script.d.ts +4 -0
  213. package/lib/{typescript → types}/autocomplete-scripts/zsh-autocomplete-script.d.ts.map +1 -1
  214. package/lib/types/cli-error/cli-error.d.ts +152 -0
  215. package/lib/types/cli-error/cli-error.d.ts.map +1 -0
  216. package/lib/types/cli-error/error-cause.d.ts +5 -0
  217. package/lib/types/cli-error/error-cause.d.ts.map +1 -0
  218. package/lib/types/cli-error/error-code/definition-error-code.d.ts +5 -0
  219. package/lib/types/cli-error/error-code/definition-error-code.d.ts.map +1 -0
  220. package/lib/types/cli-error/error-code/internal-error-code.d.ts +5 -0
  221. package/lib/types/cli-error/error-code/internal-error-code.d.ts.map +1 -0
  222. package/lib/types/cli-error/error-code/parse-error-code.d.ts +5 -0
  223. package/lib/types/cli-error/error-code/parse-error-code.d.ts.map +1 -0
  224. package/lib/types/cli-error/error-code/validation-error-code.d.ts +5 -0
  225. package/lib/types/cli-error/error-code/validation-error-code.d.ts.map +1 -0
  226. package/lib/types/cli-error/error-message/definition-error-message.d.ts +3 -0
  227. package/lib/types/cli-error/error-message/definition-error-message.d.ts.map +1 -0
  228. package/lib/types/cli-error/error-message/internal-error-message.d.ts +3 -0
  229. package/lib/types/cli-error/error-message/internal-error-message.d.ts.map +1 -0
  230. package/lib/types/cli-error/error-message/parse-error-message.d.ts +3 -0
  231. package/lib/types/cli-error/error-message/parse-error-message.d.ts.map +1 -0
  232. package/lib/types/cli-error/error-message/validation-error-message.d.ts +3 -0
  233. package/lib/types/cli-error/error-message/validation-error-message.d.ts.map +1 -0
  234. package/lib/types/coerce/coerce-methods.d.ts +122 -0
  235. package/lib/types/coerce/coerce-methods.d.ts.map +1 -0
  236. package/lib/{typescript → types}/coerce/string-to-array.d.ts +2 -2
  237. package/lib/types/coerce/string-to-array.d.ts.map +1 -0
  238. package/lib/types/coerce/string-to-primitive.d.ts +21 -0
  239. package/lib/types/coerce/string-to-primitive.d.ts.map +1 -0
  240. package/lib/{typescript → types}/coerce/string-to-set.d.ts +2 -2
  241. package/lib/{typescript → types}/coerce/string-to-set.d.ts.map +1 -1
  242. package/lib/{typescript → types}/definitions/define-cli.d.ts +2 -6
  243. package/lib/types/definitions/define-cli.d.ts.map +1 -0
  244. package/lib/{typescript → types}/definitions/define-subcommand.d.ts +2 -4
  245. package/lib/types/definitions/define-subcommand.d.ts.map +1 -0
  246. package/lib/{typescript → types}/definitions/validate-cli-definition.d.ts +1 -1
  247. package/lib/types/definitions/validate-cli-definition.d.ts.map +1 -0
  248. package/lib/{typescript → types}/help-message/terminal-markdown.d.ts.map +1 -1
  249. package/lib/{typescript → types}/index.d.ts +7 -0
  250. package/lib/{typescript → types}/index.d.ts.map +1 -1
  251. package/lib/{typescript → types}/metadata/arguments-metadata.d.ts.map +1 -1
  252. package/lib/{typescript → types}/metadata/options-metadata.d.ts.map +1 -1
  253. package/lib/{typescript → types}/parse/context/cli-context-builder.d.ts +1 -1
  254. package/lib/{typescript → types}/parse/context/cli-context-builder.d.ts.map +1 -1
  255. package/lib/{typescript → types}/parse/context/object-context-builder.d.ts +1 -1
  256. package/lib/types/parse/context/object-context-builder.d.ts.map +1 -0
  257. package/lib/{typescript → types}/parse/parser-utilities.d.ts +9 -0
  258. package/lib/{typescript → types}/parse/parser-utilities.d.ts.map +1 -1
  259. package/lib/{typescript → types}/parse/safe-parse.d.ts.map +1 -1
  260. package/lib/{typescript → types}/parse/validation/validate-context.d.ts +1 -1
  261. package/lib/{typescript → types}/parse/validation/validate-context.d.ts.map +1 -1
  262. package/lib/{typescript → types}/parse/validation/validators/arguments.d.ts +1 -1
  263. package/lib/{typescript → types}/parse/validation/validators/arguments.d.ts.map +1 -1
  264. package/lib/{typescript → types}/parse/validation/validators/conflict.d.ts +3 -3
  265. package/lib/{typescript → types}/parse/validation/validators/conflict.d.ts.map +1 -1
  266. package/lib/{typescript → types}/parse/validation/validators/exclusive.d.ts +3 -3
  267. package/lib/{typescript → types}/parse/validation/validators/exclusive.d.ts.map +1 -1
  268. package/lib/{typescript → types}/parse/validation/validators/options.d.ts +1 -1
  269. package/lib/{typescript → types}/parse/validation/validators/options.d.ts.map +1 -1
  270. package/lib/{typescript → types}/parse/validation/validators/requires.d.ts +3 -3
  271. package/lib/{typescript → types}/parse/validation/validators/requires.d.ts.map +1 -1
  272. package/lib/{typescript → types}/types/definitions-types.d.ts +35 -4
  273. package/lib/types/types/definitions-types.d.ts.map +1 -0
  274. package/lib/types/types/error-types.d.ts +275 -0
  275. package/lib/types/types/error-types.d.ts.map +1 -0
  276. package/lib/types/types/types.d.ts +146 -0
  277. package/lib/types/types/types.d.ts.map +1 -0
  278. package/lib/{typescript → types}/types/utilities-types.d.ts +0 -2
  279. package/lib/{typescript → types}/types/utilities-types.d.ts.map +1 -1
  280. package/lib/types/utilities/parse-argv.d.ts +3 -0
  281. package/lib/types/utilities/parse-argv.d.ts.map +1 -0
  282. package/lib/types/utilities/schema-utilities.d.ts +15 -0
  283. package/lib/types/utilities/schema-utilities.d.ts.map +1 -0
  284. package/lib/{typescript → types/utilities}/utilities.d.ts +12 -15
  285. package/lib/types/utilities/utilities.d.ts.map +1 -0
  286. package/package.json +10 -9
  287. package/src/autocomplete-scripts/bash-autocomplete-script.ts +14 -12
  288. package/src/autocomplete-scripts/powershell-autocomplete-script.ts +67 -33
  289. package/src/autocomplete-scripts/zsh-autocomplete-script.ts +39 -31
  290. package/src/cli-error/cli-error.ts +44 -0
  291. package/src/cli-error/error-cause.ts +10 -0
  292. package/src/cli-error/error-code/definition-error-code.ts +21 -0
  293. package/src/cli-error/error-code/internal-error-code.ts +8 -0
  294. package/src/cli-error/error-code/parse-error-code.ts +16 -0
  295. package/src/cli-error/error-code/validation-error-code.ts +15 -0
  296. package/src/cli-error/error-message/definition-error-message.ts +144 -0
  297. package/src/cli-error/error-message/internal-error-message.ts +19 -0
  298. package/src/cli-error/error-message/parse-error-message.ts +76 -0
  299. package/src/cli-error/error-message/validation-error-message.ts +104 -0
  300. package/src/coerce/coerce-methods.ts +194 -39
  301. package/src/coerce/string-to-array.ts +2 -2
  302. package/src/coerce/string-to-primitive.ts +72 -13
  303. package/src/coerce/string-to-set.ts +2 -2
  304. package/src/definitions/define-arguments.ts +1 -1
  305. package/src/definitions/define-cli.ts +65 -30
  306. package/src/definitions/define-options.ts +1 -1
  307. package/src/definitions/define-subcommand.ts +47 -17
  308. package/src/definitions/validate-cli-definition.ts +287 -172
  309. package/src/help-message/format-arguments.ts +1 -1
  310. package/src/help-message/format-options.ts +1 -1
  311. package/src/help-message/format-subcommands.ts +1 -1
  312. package/src/help-message/generate-for-cli.ts +1 -1
  313. package/src/help-message/terminal-markdown.ts +3 -4
  314. package/src/index.ts +16 -0
  315. package/src/markdown/generate-markdown.ts +5 -4
  316. package/src/metadata/arguments-metadata.ts +2 -1
  317. package/src/metadata/options-metadata.ts +2 -1
  318. package/src/parse/context/cli-context-builder.ts +166 -39
  319. package/src/parse/context/object-context-builder.ts +37 -11
  320. package/src/parse/parser-utilities.ts +24 -10
  321. package/src/parse/safe-parse.ts +3 -6
  322. package/src/parse/validation/validate-context.ts +1 -1
  323. package/src/parse/validation/validators/arguments.ts +42 -14
  324. package/src/parse/validation/validators/conflict.ts +11 -20
  325. package/src/parse/validation/validators/exclusive.ts +16 -25
  326. package/src/parse/validation/validators/options.ts +40 -12
  327. package/src/parse/validation/validators/requires.ts +11 -20
  328. package/src/types/definitions-types.ts +36 -8
  329. package/src/types/error-types.ts +326 -0
  330. package/src/types/types.ts +100 -7
  331. package/src/types/utilities-types.ts +0 -10
  332. package/src/utilities/parse-argv.ts +79 -0
  333. package/src/utilities/schema-utilities.ts +72 -0
  334. package/src/{utilities.ts → utilities/utilities.ts} +25 -138
  335. package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs +0 -2
  336. package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +0 -1
  337. package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs +0 -2
  338. package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +0 -1
  339. package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs +0 -42
  340. package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +0 -1
  341. package/lib/cjs/coerce/coerce-methods.cjs +0 -2
  342. package/lib/cjs/coerce/coerce-methods.cjs.map +0 -1
  343. package/lib/cjs/coerce/string-to-array.cjs +0 -2
  344. package/lib/cjs/coerce/string-to-array.cjs.map +0 -1
  345. package/lib/cjs/coerce/string-to-primitive.cjs +0 -2
  346. package/lib/cjs/coerce/string-to-primitive.cjs.map +0 -1
  347. package/lib/cjs/coerce/string-to-set.cjs +0 -2
  348. package/lib/cjs/coerce/string-to-set.cjs.map +0 -1
  349. package/lib/cjs/definitions/define-arguments.cjs +0 -2
  350. package/lib/cjs/definitions/define-arguments.cjs.map +0 -1
  351. package/lib/cjs/definitions/define-cli.cjs +0 -2
  352. package/lib/cjs/definitions/define-cli.cjs.map +0 -1
  353. package/lib/cjs/definitions/define-options.cjs +0 -2
  354. package/lib/cjs/definitions/define-options.cjs.map +0 -1
  355. package/lib/cjs/definitions/define-subcommand.cjs +0 -2
  356. package/lib/cjs/definitions/define-subcommand.cjs.map +0 -1
  357. package/lib/cjs/definitions/validate-cli-definition.cjs +0 -2
  358. package/lib/cjs/definitions/validate-cli-definition.cjs.map +0 -1
  359. package/lib/cjs/help-message/format-arguments.cjs +0 -2
  360. package/lib/cjs/help-message/format-arguments.cjs.map +0 -1
  361. package/lib/cjs/help-message/format-options.cjs +0 -2
  362. package/lib/cjs/help-message/format-options.cjs.map +0 -1
  363. package/lib/cjs/help-message/format-subcommands.cjs +0 -2
  364. package/lib/cjs/help-message/format-subcommands.cjs.map +0 -1
  365. package/lib/cjs/help-message/generate-for-cli.cjs +0 -2
  366. package/lib/cjs/help-message/generate-for-cli.cjs.map +0 -1
  367. package/lib/cjs/help-message/generate-for-subcommand.cjs +0 -2
  368. package/lib/cjs/help-message/generate-for-subcommand.cjs.map +0 -1
  369. package/lib/cjs/help-message/print-help.cjs +0 -2
  370. package/lib/cjs/help-message/print-help.cjs.map +0 -1
  371. package/lib/cjs/help-message/set-defaults.cjs +0 -2
  372. package/lib/cjs/help-message/set-defaults.cjs.map +0 -1
  373. package/lib/cjs/help-message/styles.cjs +0 -2
  374. package/lib/cjs/help-message/styles.cjs.map +0 -1
  375. package/lib/cjs/help-message/terminal-markdown.cjs +0 -2
  376. package/lib/cjs/help-message/terminal-markdown.cjs.map +0 -1
  377. package/lib/cjs/index.cjs +0 -2
  378. package/lib/cjs/index.cjs.map +0 -1
  379. package/lib/cjs/markdown/generate-markdown.cjs +0 -2
  380. package/lib/cjs/markdown/generate-markdown.cjs.map +0 -1
  381. package/lib/cjs/metadata/arguments-metadata.cjs +0 -2
  382. package/lib/cjs/metadata/arguments-metadata.cjs.map +0 -1
  383. package/lib/cjs/metadata/cli-metadata.cjs +0 -2
  384. package/lib/cjs/metadata/cli-metadata.cjs.map +0 -1
  385. package/lib/cjs/metadata/options-metadata.cjs +0 -2
  386. package/lib/cjs/metadata/options-metadata.cjs.map +0 -1
  387. package/lib/cjs/metadata/subcommands-metadata.cjs +0 -2
  388. package/lib/cjs/metadata/subcommands-metadata.cjs.map +0 -1
  389. package/lib/cjs/parse/context/cli-context-builder.cjs +0 -2
  390. package/lib/cjs/parse/context/cli-context-builder.cjs.map +0 -1
  391. package/lib/cjs/parse/context/object-context-builder.cjs +0 -2
  392. package/lib/cjs/parse/context/object-context-builder.cjs.map +0 -1
  393. package/lib/cjs/parse/parser-utilities.cjs +0 -2
  394. package/lib/cjs/parse/parser-utilities.cjs.map +0 -1
  395. package/lib/cjs/parse/safe-parse.cjs +0 -2
  396. package/lib/cjs/parse/safe-parse.cjs.map +0 -1
  397. package/lib/cjs/parse/validation/validate-context.cjs +0 -2
  398. package/lib/cjs/parse/validation/validate-context.cjs.map +0 -1
  399. package/lib/cjs/parse/validation/validators/arguments.cjs +0 -2
  400. package/lib/cjs/parse/validation/validators/arguments.cjs.map +0 -1
  401. package/lib/cjs/parse/validation/validators/conflict.cjs +0 -2
  402. package/lib/cjs/parse/validation/validators/conflict.cjs.map +0 -1
  403. package/lib/cjs/parse/validation/validators/exclusive.cjs +0 -2
  404. package/lib/cjs/parse/validation/validators/exclusive.cjs.map +0 -1
  405. package/lib/cjs/parse/validation/validators/explicitly-passed.cjs +0 -2
  406. package/lib/cjs/parse/validation/validators/explicitly-passed.cjs.map +0 -1
  407. package/lib/cjs/parse/validation/validators/options.cjs +0 -2
  408. package/lib/cjs/parse/validation/validators/options.cjs.map +0 -1
  409. package/lib/cjs/parse/validation/validators/requires.cjs +0 -2
  410. package/lib/cjs/parse/validation/validators/requires.cjs.map +0 -1
  411. package/lib/cjs/utilities.cjs +0 -2
  412. package/lib/cjs/utilities.cjs.map +0 -1
  413. package/lib/esm/utilities.js +0 -2
  414. package/lib/esm/utilities.js.map +0 -1
  415. package/lib/mjs/utilities.mjs +0 -2
  416. package/lib/mjs/utilities.mjs.map +0 -1
  417. package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +0 -14
  418. package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +0 -11
  419. package/lib/typescript/coerce/coerce-methods.d.ts +0 -20
  420. package/lib/typescript/coerce/coerce-methods.d.ts.map +0 -1
  421. package/lib/typescript/coerce/string-to-array.d.ts.map +0 -1
  422. package/lib/typescript/coerce/string-to-primitive.d.ts +0 -5
  423. package/lib/typescript/coerce/string-to-primitive.d.ts.map +0 -1
  424. package/lib/typescript/definitions/define-cli.d.ts.map +0 -1
  425. package/lib/typescript/definitions/define-subcommand.d.ts.map +0 -1
  426. package/lib/typescript/definitions/validate-cli-definition.d.ts.map +0 -1
  427. package/lib/typescript/parse/context/object-context-builder.d.ts.map +0 -1
  428. package/lib/typescript/types/definitions-types.d.ts.map +0 -1
  429. package/lib/typescript/types/types.d.ts +0 -61
  430. package/lib/typescript/types/types.d.ts.map +0 -1
  431. package/lib/typescript/utilities.d.ts.map +0 -1
  432. /package/lib/{typescript → types}/autocomplete-scripts/bash-autocomplete-script.d.ts +0 -0
  433. /package/lib/{typescript → types}/definitions/define-arguments.d.ts +0 -0
  434. /package/lib/{typescript → types}/definitions/define-arguments.d.ts.map +0 -0
  435. /package/lib/{typescript → types}/definitions/define-options.d.ts +0 -0
  436. /package/lib/{typescript → types}/definitions/define-options.d.ts.map +0 -0
  437. /package/lib/{typescript → types}/help-message/format-arguments.d.ts +0 -0
  438. /package/lib/{typescript → types}/help-message/format-arguments.d.ts.map +0 -0
  439. /package/lib/{typescript → types}/help-message/format-options.d.ts +0 -0
  440. /package/lib/{typescript → types}/help-message/format-options.d.ts.map +0 -0
  441. /package/lib/{typescript → types}/help-message/format-subcommands.d.ts +0 -0
  442. /package/lib/{typescript → types}/help-message/format-subcommands.d.ts.map +0 -0
  443. /package/lib/{typescript → types}/help-message/generate-for-cli.d.ts +0 -0
  444. /package/lib/{typescript → types}/help-message/generate-for-cli.d.ts.map +0 -0
  445. /package/lib/{typescript → types}/help-message/generate-for-subcommand.d.ts +0 -0
  446. /package/lib/{typescript → types}/help-message/generate-for-subcommand.d.ts.map +0 -0
  447. /package/lib/{typescript → types}/help-message/print-help.d.ts +0 -0
  448. /package/lib/{typescript → types}/help-message/print-help.d.ts.map +0 -0
  449. /package/lib/{typescript → types}/help-message/set-defaults.d.ts +0 -0
  450. /package/lib/{typescript → types}/help-message/set-defaults.d.ts.map +0 -0
  451. /package/lib/{typescript → types}/help-message/styles.d.ts +0 -0
  452. /package/lib/{typescript → types}/help-message/styles.d.ts.map +0 -0
  453. /package/lib/{typescript → types}/help-message/terminal-markdown.d.ts +0 -0
  454. /package/lib/{typescript → types}/markdown/generate-markdown.d.ts +0 -0
  455. /package/lib/{typescript → types}/markdown/generate-markdown.d.ts.map +0 -0
  456. /package/lib/{typescript → types}/metadata/arguments-metadata.d.ts +0 -0
  457. /package/lib/{typescript → types}/metadata/cli-metadata.d.ts +0 -0
  458. /package/lib/{typescript → types}/metadata/cli-metadata.d.ts.map +0 -0
  459. /package/lib/{typescript → types}/metadata/options-metadata.d.ts +0 -0
  460. /package/lib/{typescript → types}/metadata/subcommands-metadata.d.ts +0 -0
  461. /package/lib/{typescript → types}/metadata/subcommands-metadata.d.ts.map +0 -0
  462. /package/lib/{typescript → types}/parse/safe-parse.d.ts +0 -0
  463. /package/lib/{typescript → types}/parse/validation/validators/explicitly-passed.d.ts +0 -0
  464. /package/lib/{typescript → types}/parse/validation/validators/explicitly-passed.d.ts.map +0 -0
  465. /package/lib/{typescript → types}/types/context-types.d.ts +0 -0
  466. /package/lib/{typescript → types}/types/context-types.d.ts.map +0 -0
  467. /package/lib/{typescript → types}/types/help-message-types.d.ts +0 -0
  468. /package/lib/{typescript → types}/types/help-message-types.d.ts.map +0 -0
  469. /package/lib/{typescript → types}/types/io-types.d.ts +0 -0
  470. /package/lib/{typescript → types}/types/io-types.d.ts.map +0 -0
  471. /package/lib/{typescript → types}/types/metadata-types.d.ts +0 -0
  472. /package/lib/{typescript → types}/types/metadata-types.d.ts.map +0 -0
  473. /package/lib/{typescript → types}/types/schema-types.d.ts +0 -0
  474. /package/lib/{typescript → types}/types/schema-types.d.ts.map +0 -0
@@ -0,0 +1,144 @@
1
+ import { DefinitionErrorCode } from "../error-code/definition-error-code.ts";
2
+
3
+ import type { CliErrorOptionByCause } from "../../types/error-types.ts";
4
+
5
+ export function definitionErrorMessage({ code, context }: CliErrorOptionByCause<"Definition">) {
6
+ if (code === DefinitionErrorCode.MissingDefinitionName) {
7
+ const propertyName = context.commandKind === "command" ? "cliName" : "name";
8
+ return `invalid ${context.commandKind} definition: "${propertyName}" property is required.`;
9
+ }
10
+
11
+ if (code === DefinitionErrorCode.EmptyDefinitionGroup) {
12
+ return (
13
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
14
+ `"${context.kind}" property is optional but cannot be empty.`
15
+ );
16
+ }
17
+
18
+ if (code === DefinitionErrorCode.MissingSchema) {
19
+ return (
20
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
21
+ `the ${context.kind} "${context.name}" is missing the "schema" property.`
22
+ );
23
+ }
24
+
25
+ if (code === DefinitionErrorCode.InvalidDefinitionOptionName) {
26
+ if (context.negatedAliasName) {
27
+ return (
28
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
29
+ `the option "${context.optionName}" has the alias "${context.negatedAliasName}" which cannot be named as a negated option.`
30
+ );
31
+ }
32
+
33
+ return (
34
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
35
+ `the option "${context.optionName}" cannot be named as a negated option.`
36
+ );
37
+ }
38
+
39
+ if (code === DefinitionErrorCode.InvalidDefinitionArgumentName) {
40
+ return (
41
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
42
+ `the argument "${context.name}" cannot be a number..`
43
+ );
44
+ }
45
+
46
+ if (code === DefinitionErrorCode.DuplicateDefinitionName) {
47
+ const foundIn = context.foundInName
48
+ ? `conflict with the ${context.foundInKind} "${context.foundInName}" alias name`
49
+ : `conflict with other ${context.foundInKind} name`;
50
+
51
+ if (context.duplicatedAlias) {
52
+ return (
53
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
54
+ `the ${context.kind} "${context.name}" has the alias "${context.duplicatedAlias}" which ${foundIn}.`
55
+ );
56
+ }
57
+
58
+ return (
59
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
60
+ `the ${context.kind} "${context.name}" name ${foundIn}.`
61
+ );
62
+ }
63
+
64
+ if (code === DefinitionErrorCode.EmptyStringAliasName) {
65
+ if (context.optionName) {
66
+ return (
67
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
68
+ `the option "${context.optionName}" has an empty string alias name.`
69
+ );
70
+ }
71
+
72
+ return (
73
+ `invalid ${context.commandKind} definition "${context.commandName}": ` + `empty string alias name is not allowed.`
74
+ );
75
+ }
76
+
77
+ if (code === DefinitionErrorCode.SelfRequire) {
78
+ return (
79
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
80
+ `the ${context.kind} "${context.name}" cannot require itself.`
81
+ );
82
+ }
83
+
84
+ if (code === DefinitionErrorCode.UnknownRequireName) {
85
+ return (
86
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
87
+ `the ${context.kind} "${context.name}" requires a non-existent name "${context.requiredName}".`
88
+ );
89
+ }
90
+
91
+ if (code === DefinitionErrorCode.SelfConflict) {
92
+ return (
93
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
94
+ `the ${context.kind} "${context.name}" cannot conflict with itself.`
95
+ );
96
+ }
97
+
98
+ if (code === DefinitionErrorCode.UnknownConflictName) {
99
+ return (
100
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
101
+ `the ${context.kind} "${context.name}" conflicts with a non-existent name "${context.requiredName}".`
102
+ );
103
+ }
104
+
105
+ if (code === DefinitionErrorCode.DefinitionRequiresConflictOverlap) {
106
+ const s = context.intersectedNames.length > 1 ? "s" : "";
107
+ return (
108
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
109
+ `the ${context.kind} "${context.name}" has overlapping 'requires' and 'conflictsWith' name${s}: ` +
110
+ context.intersectedNames.join(", ")
111
+ );
112
+ }
113
+
114
+ if (code === DefinitionErrorCode.InvalidOptionalArgumentDefinition) {
115
+ if (context.allowPositionals) {
116
+ return (
117
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
118
+ `the argument "${context.name}" cannot be optional when "allowPositionals" is enabled.`
119
+ );
120
+ }
121
+
122
+ return (
123
+ `invalid ${context.commandKind} definition "${context.commandName}": ` +
124
+ `the argument "${context.name}" cannot be optional unless it is the last argument.`
125
+ );
126
+ }
127
+
128
+ if (code === DefinitionErrorCode.MissingOnExecute) {
129
+ return (
130
+ `trying to execute ${context.commandKind} "${context.commandName}" ` +
131
+ `which does not have an "onExecute" handler.`
132
+ );
133
+ }
134
+
135
+ if (code === DefinitionErrorCode.SubcommandHelpNotFound) {
136
+ return (
137
+ `cannot generate help message for subcommand "${context.subcommandName}" ` +
138
+ `because it does not exist in CLI "${context.cliName}".`
139
+ );
140
+ }
141
+
142
+ const executiveCheck: never = code;
143
+ return executiveCheck;
144
+ }
@@ -0,0 +1,19 @@
1
+ import { InternalErrorCode } from "../error-code/internal-error-code.ts";
2
+
3
+ import type { CliErrorOptionByCause } from "../../types/error-types.ts";
4
+
5
+ export function internalErrorMessage({ code, context }: CliErrorOptionByCause<"Internal">) {
6
+ if (code === InternalErrorCode.MissingPreparedTypes) {
7
+ return (
8
+ `internal error: missing prepared type ` +
9
+ `for option "${context.name}" in ${context.commandKind} "${context.commandName}"`
10
+ );
11
+ }
12
+
13
+ if (code === InternalErrorCode.CannotFindCliDefinition) {
14
+ return `internal error: cannot find cli definition "${context.cliName}"`;
15
+ }
16
+
17
+ const executiveCheck: never = code;
18
+ return executiveCheck;
19
+ }
@@ -0,0 +1,76 @@
1
+ import { ParseErrorCode } from "../error-code/parse-error-code.ts";
2
+
3
+ import type { CliErrorOptionByCause } from "../../types/error-types.ts";
4
+
5
+ export function parseErrorMessage({ code, context }: CliErrorOptionByCause<"Parse">) {
6
+ if (code === ParseErrorCode.UnknownSubcommand) {
7
+ return `parsing error: unknown subcommand "${context.commandName}".`;
8
+ }
9
+
10
+ if (code === ParseErrorCode.CommandWithoutOptions) {
11
+ return (
12
+ `parsing error: the ${context.commandKind} "${context.commandName}" ` +
13
+ `does not allow options, but received "${context.optionName}".`
14
+ );
15
+ }
16
+
17
+ if (code === ParseErrorCode.UnknownOption) {
18
+ return (
19
+ `parsing error: unknown option "${context.optionName}" ` +
20
+ `for the ${context.commandKind} "${context.commandName}".`
21
+ );
22
+ }
23
+
24
+ if (code === ParseErrorCode.DuplicateOptionProvided) {
25
+ return (
26
+ `parsing error: duplicate option "${context.optionName}" ` +
27
+ `provided for the ${context.commandKind} "${context.commandName}".`
28
+ );
29
+ }
30
+
31
+ if (code === ParseErrorCode.InvalidNegationForNonBooleanOption) {
32
+ return (
33
+ `parsing error: option "${context.optionName}" cannot be negated ` +
34
+ `because it is not a boolean option for the ${context.commandKind} "${context.commandName}".`
35
+ );
36
+ }
37
+
38
+ if (code === ParseErrorCode.PositionalArgumentNotAllowed) {
39
+ return (
40
+ `parsing error: positional argument "${context.argumentName}" ` +
41
+ `is not allowed for the ${context.commandKind} "${context.commandName}".`
42
+ );
43
+ }
44
+
45
+ if (code === ParseErrorCode.MissingRequiredOption) {
46
+ return (
47
+ `parsing error: missing required option "${context.optionName}" ` +
48
+ `for the ${context.commandKind} "${context.commandName}".`
49
+ );
50
+ }
51
+
52
+ if (code === ParseErrorCode.MissingRequiredArgument) {
53
+ return (
54
+ `parsing error: missing required argument "${context.argumentName}" ` +
55
+ `for the ${context.commandKind} "${context.commandName}".`
56
+ );
57
+ }
58
+
59
+ if (code === ParseErrorCode.OptionMissingValue) {
60
+ return (
61
+ `parsing error: the option "${context.optionName}" ` +
62
+ `for the ${context.commandKind} "${context.commandName}" expects a value but received none.`
63
+ );
64
+ }
65
+
66
+ if (code === ParseErrorCode.FlagAssignedValue) {
67
+ return (
68
+ `parsing error: ` +
69
+ `flag option "${context.flag}" in ${context.commandKind} "${context.commandName}" ` +
70
+ `cannot be assigned a value using "=" (provided: "${context.value}").`
71
+ );
72
+ }
73
+
74
+ const executiveCheck: never = code;
75
+ return executiveCheck;
76
+ }
@@ -0,0 +1,104 @@
1
+ import { prettifyError } from "../../utilities/schema-utilities.ts";
2
+ import { ValidationErrorCode } from "../error-code/validation-error-code.ts";
3
+
4
+ import type { CliErrorOptionByCause } from "../../types/error-types.ts";
5
+
6
+ export function validationErrorMessage({ code, context }: CliErrorOptionByCause<"Validation">) {
7
+ if (code === ValidationErrorCode.NoOptionsToValidate) {
8
+ return (
9
+ `validation error: trying to validate options ` +
10
+ `for ${context.commandKind} "${context.commandName}" which does not define any.`
11
+ );
12
+ }
13
+
14
+ if (code === ValidationErrorCode.NoArgumentsToValidate) {
15
+ return (
16
+ `validation error: trying to validate typed arguments ` +
17
+ `for ${context.commandKind} "${context.commandName}" which does not define any.`
18
+ );
19
+ }
20
+
21
+ if (code === ValidationErrorCode.UnknownOptionValidation) {
22
+ return (
23
+ `validation error: trying to validate a non-existent option "${context.optionName}" ` +
24
+ `for ${context.commandKind} "${context.commandName}".`
25
+ );
26
+ }
27
+
28
+ if (code === ValidationErrorCode.UnknownArgumentValidation) {
29
+ return (
30
+ `validation error: trying to validate a non-existent typed argument "${context.argumentName}" ` +
31
+ `for ${context.commandKind} "${context.commandName}".`
32
+ );
33
+ }
34
+
35
+ if (code === ValidationErrorCode.SchemaValidationFailed) {
36
+ return (
37
+ `validation error: ` +
38
+ `the ${context.kind} "${context.name}" for ${context.commandKind} "${context.commandName}" failed to validate ` +
39
+ `"${typeof context.inputValue === "string" ? context.inputValue : JSON.stringify(context.inputValue)}": ` +
40
+ prettifyError(context.issues)
41
+ );
42
+ }
43
+
44
+ if (code === ValidationErrorCode.MutuallyExclusiveConflict) {
45
+ const parts: string[] = [];
46
+
47
+ if (context.conflictedOptions.length > 0) {
48
+ const formatted = context.conflictedOptions.map(o => `"${o}"`).join(", ");
49
+ const s = context.conflictedOptions.length > 1 ? "s" : "";
50
+ parts.push(`option${s} ${formatted}`);
51
+ }
52
+
53
+ if (context.conflictedArguments.length > 0) {
54
+ const formatted = context.conflictedArguments.map(a => `"${a}"`).join(", ");
55
+ const s = context.conflictedArguments.length > 1 ? "s" : "";
56
+ parts.push(`argument${s} ${formatted}`);
57
+ }
58
+
59
+ return (
60
+ `validation error: the ${context.kind} "${context.name}" ` +
61
+ `cannot be used with the ${parts.join(" and ")} because they are mutually exclusive.`
62
+ );
63
+ }
64
+
65
+ if (code === ValidationErrorCode.RequiredDependencyMissing) {
66
+ const parts: string[] = [];
67
+
68
+ if (context.missingOptions.length > 0) {
69
+ const formatted = context.missingOptions.map(o => `"${o}"`).join(", ");
70
+ const s = context.missingOptions.length > 1 ? "s" : "";
71
+ parts.push(`option${s} ${formatted}`);
72
+ }
73
+
74
+ if (context.missingArguments.length > 0) {
75
+ const formatted = context.missingArguments.map(a => `"${a}"`).join(", ");
76
+ const s = context.missingArguments.length > 1 ? "s" : "";
77
+ parts.push(`argument${s} ${formatted}`);
78
+ }
79
+
80
+ return (
81
+ `validation error: the ${context.kind} "${context.name}" ` +
82
+ `cannot be used without the required "${parts.join(" and ")}".`
83
+ );
84
+ }
85
+
86
+ if (code === ValidationErrorCode.AsyncSchemaNotSupported) {
87
+ return (
88
+ `validation error: cannot validate async schema: ` +
89
+ `received ${typeof context.value === "string" ? context.value : JSON.stringify(context.value)}`
90
+ );
91
+ }
92
+
93
+ if (code === ValidationErrorCode.CoercionFailed) {
94
+ return (
95
+ `validation error: ` +
96
+ `failed to coerce the value ` +
97
+ `"${typeof context.providedValue === "string" ? context.providedValue : JSON.stringify(context.providedValue)}" ` +
98
+ `of type "${typeof context.providedValue}" to type "${context.coerceToType}".`
99
+ );
100
+ }
101
+
102
+ const executiveCheck: never = code;
103
+ return executiveCheck;
104
+ }
@@ -1,75 +1,230 @@
1
+ import { walkObject } from "../utilities/utilities.ts";
1
2
  import { stringToBooleanArray, stringToNumberArray, stringToStringArray } from "./string-to-array.ts";
2
- import { stringToBoolean, stringToNumber } from "./string-to-primitive.ts";
3
+ import { stringToBigint, stringToBoolean, stringToNumber } from "./string-to-primitive.ts";
3
4
  import { stringToBooleanSet, stringToNumberSet, stringToStringSet } from "./string-to-set.ts";
4
5
 
5
- import type { CoerceMethod } from "../types/types.ts";
6
+ import type { ObjectCoerceMethodOptions } from "../types/types.ts";
6
7
 
7
- const string: CoerceMethod<string> = terminalInput => terminalInput;
8
- string.type = "string";
9
-
10
- const boolean: CoerceMethod<boolean> = terminalInput => stringToBoolean(terminalInput);
8
+ const string = <T extends string | undefined>(terminalInput: string): T => terminalInput as T;
9
+ const number = <T extends number | undefined>(terminalInput: string): T => stringToNumber(terminalInput) as T;
10
+ const bigint = <T extends bigint | undefined>(terminalInput: string): T => stringToBigint(terminalInput) as T;
11
+ const json = <T>(terminalInput: string): T => JSON.parse(terminalInput) as T;
12
+ const boolean = <T extends boolean | undefined>(terminalInput: string): T => stringToBoolean(terminalInput) as T;
11
13
  boolean.type = "boolean";
12
14
 
13
- const number: CoerceMethod<number> = terminalInput => stringToNumber(terminalInput);
14
- number.type = "number";
15
-
16
- const json = <T>(reviver?: (this: any, key: string, value: any) => any): CoerceMethod<T> => {
17
- const coerceMethod: CoerceMethod<T> = terminalInput => JSON.parse(terminalInput, reviver) as T;
18
- coerceMethod.type = "unknown";
19
- return coerceMethod;
20
- };
21
-
22
- const stringArray = (separator: string): CoerceMethod<string[]> => {
23
- const coerceMethod: CoerceMethod<string[]> = terminalInput => stringToStringArray(terminalInput, separator);
24
- coerceMethod.type = "string[]";
25
- return coerceMethod;
15
+ const stringArray = (separator: string) => {
16
+ return <T extends string[] | undefined>(terminalInput: string): T =>
17
+ stringToStringArray(terminalInput, separator) as T;
26
18
  };
27
19
 
28
20
  const numberArray = (separator: string) => {
29
- const coerceMethod: CoerceMethod<number[]> = terminalInput => stringToNumberArray(terminalInput, separator);
30
- coerceMethod.type = "number[]";
31
- return coerceMethod;
21
+ return <T extends number[] | undefined>(terminalInput: string): T =>
22
+ stringToNumberArray(terminalInput, separator) as T;
32
23
  };
33
24
 
34
25
  const booleanArray = (separator: string) => {
35
- const coerceMethod: CoerceMethod<boolean[]> = terminalInput => stringToBooleanArray(terminalInput, separator);
36
- coerceMethod.type = "boolean[]";
37
- return coerceMethod;
26
+ return <T extends boolean[] | undefined>(terminalInput: string): T =>
27
+ stringToBooleanArray(terminalInput, separator) as T;
38
28
  };
39
29
 
40
30
  const stringSet = (separator: string) => {
41
- const coerceMethod: CoerceMethod<Set<string>> = terminalInput => stringToStringSet(terminalInput, separator);
42
- coerceMethod.type = "set<string>";
43
- return coerceMethod;
31
+ return <T extends Set<string> | undefined>(terminalInput: string): T =>
32
+ stringToStringSet(terminalInput, separator) as T;
44
33
  };
45
34
 
46
35
  const numberSet = (separator: string) => {
47
- const coerceMethod: CoerceMethod<Set<number>> = terminalInput => stringToNumberSet(terminalInput, separator);
48
- coerceMethod.type = "set<number>";
49
- return coerceMethod;
36
+ return <T extends Set<number> | undefined>(terminalInput: string): T =>
37
+ stringToNumberSet(terminalInput, separator) as T;
50
38
  };
51
39
 
52
40
  const booleanSet = (separator: string) => {
53
- const coerceMethod: CoerceMethod<Set<boolean>> = terminalInput => stringToBooleanSet(terminalInput, separator);
54
- coerceMethod.type = "set<boolean>";
41
+ return <T extends Set<boolean> | undefined>(terminalInput: string): T =>
42
+ stringToBooleanSet(terminalInput, separator) as T;
43
+ };
44
+
45
+ const object = (options: ObjectCoerceMethodOptions = {}) => {
46
+ const coerceMethod = <T extends Record<string, unknown> | undefined>(terminalInput: string): T => {
47
+ const object = JSON.parse(terminalInput) as T;
48
+
49
+ if (!options.coerceBoolean && !options.coerceNumber && !options.coerceBigint && !options.coerceDate) {
50
+ return object;
51
+ }
52
+
53
+ walkObject(object!, (_, value, path) => {
54
+ if (typeof value !== "string") return value;
55
+
56
+ const shouldCoerce = (boolOrArray: boolean | string[] | undefined) => {
57
+ if (!boolOrArray) return false;
58
+ if (typeof boolOrArray === "boolean") return boolOrArray;
59
+ return boolOrArray.includes(path);
60
+ };
61
+
62
+ if (shouldCoerce(options.coerceBoolean)) {
63
+ try {
64
+ return stringToBoolean(value);
65
+ } catch {
66
+ return value;
67
+ }
68
+ }
69
+
70
+ if (shouldCoerce(options.coerceNumber)) {
71
+ try {
72
+ return stringToNumber(value);
73
+ } catch {
74
+ return value;
75
+ }
76
+ }
77
+
78
+ if (shouldCoerce(options.coerceBigint)) {
79
+ try {
80
+ return BigInt(value);
81
+ } catch {
82
+ return value;
83
+ }
84
+ }
85
+
86
+ if (shouldCoerce(options.coerceDate)) {
87
+ try {
88
+ return new Date(value);
89
+ } catch {
90
+ return value;
91
+ }
92
+ }
93
+
94
+ return value;
95
+ });
96
+
97
+ return object;
98
+ };
99
+
55
100
  return coerceMethod;
56
101
  };
57
102
 
58
103
  export const coerce = {
104
+ /**
105
+ * Since the terminal input is a string, this method does nothing.
106
+ *
107
+ * @since 2.0.0
108
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
109
+ */
59
110
  string,
111
+
112
+ /**
113
+ * Coerces a string matching `"true"` or `"false"` (case-insensitive) to a boolean value.
114
+ *
115
+ * @since 2.0.0
116
+ * @throws {CliError} If input is not a valid boolean string.
117
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
118
+ */
60
119
  boolean,
120
+
121
+ /**
122
+ * Coerces a string matching a number to a number value.
123
+ *
124
+ * @since 2.0.0
125
+ * @throws {CliError} If input is empty or not a valid number.
126
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
127
+ */
61
128
  number,
62
- /** @param separator - The separator to use to split the string. **Default** is `","` */
129
+
130
+ /**
131
+ * Coerces a string matching a number to a bigint value.
132
+ *
133
+ * @since 2.0.0
134
+ * @throws {CliError} If input is empty or not a valid bigint.
135
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
136
+ */
137
+ bigint,
138
+
139
+ /**
140
+ * Coerces a JSON string into a JavaScript object, optionally converting certain string values into native types such
141
+ * as booleans, numbers, bigints, or dates.
142
+ *
143
+ * Each coercion option attempts conversion and silently falls back to the original string if the value cannot be
144
+ * converted.
145
+ *
146
+ * @since 2.0.0
147
+ * @throws {SyntaxError} If input is not a valid JSON string.
148
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/README.md##structured-object-options}
149
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
150
+ */
151
+ object,
152
+
153
+ /**
154
+ * Converts a string to an array of strings by splitting it on the specified separator.
155
+ *
156
+ * @since 2.0.0
157
+ * @param separator - The separator to use to split the string.`
158
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
159
+ */
63
160
  stringArray,
64
- /** @param separator - The separator to use to split the string. **Default** is `","` */
161
+
162
+ /**
163
+ * Converts a string to an array of numbers by splitting it on the specified separator.
164
+ *
165
+ * Items that match the number regex will be converted to numbers.
166
+ *
167
+ * @since 2.0.0
168
+ * @param separator - The separator to use to split the string.`
169
+ * @throws {CliError} - When an item cannot be converted to a number
170
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
171
+ */
65
172
  numberArray,
66
- /** @param separator - The separator to use to split the string. **Default** is `","` */
173
+
174
+ /**
175
+ * Converts a string to an array of booleans by splitting it on the specified separator.
176
+ *
177
+ * Items that match `"true"` or `"false"` (case-insensitive) will be converted to booleans.
178
+ *
179
+ * @since 2.0.0
180
+ * @param separator - The separator to use to split the string.`
181
+ * @throws {CliError} - When an item cannot be converted to a boolean
182
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
183
+ */
67
184
  booleanArray,
68
- /** @param separator - The separator to use to split the string. **Default** is `","` */
185
+
186
+ /**
187
+ * Converts a string to a set of strings by splitting it on the specified separator.
188
+ *
189
+ * Items that match the number regex will be converted to numbers.
190
+ *
191
+ * @since 2.0.0
192
+ * @param separator - The separator to use to split the string.`
193
+ * @throws {CliError} - When an item cannot be converted to a number
194
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
195
+ */
69
196
  stringSet,
70
- /** @param separator - The separator to use to split the string. **Default** is `","` */
197
+
198
+ /**
199
+ * Converts a string to a set of numbers by splitting it on the specified separator.
200
+ *
201
+ * Items that match the number regex will be converted to numbers.
202
+ *
203
+ * @since 2.0.0
204
+ * @param separator - The separator to use to split the string.
205
+ * @throws {CliError} - When an item cannot be converted to a number
206
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
207
+ */
71
208
  numberSet,
72
- /** @param separator - The separator to use to split the string. **Default** is `","` */
209
+
210
+ /**
211
+ * Converts a string to a set of booleans by splitting it on the specified separator.
212
+ *
213
+ * Items that match `"true"` or `"false"` (case-insensitive) will be converted to booleans.
214
+ *
215
+ * @since 2.0.0
216
+ * @param separator - The separator to use to split the string.
217
+ * @throws {CliError} - When an item cannot be converted to a boolean
218
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
219
+ */
73
220
  booleanSet,
221
+
222
+ /**
223
+ * Parses a JSON string into a JavaScript object.
224
+ *
225
+ * @since 2.0.0
226
+ * @throws {SyntaxError} If input is not a valid JSON string.
227
+ * @see {@link https://github.com/alabsi91/zod-args-parser/blob/main/docs/api-reference.md#coerce-helpers}
228
+ */
74
229
  json,
75
230
  };
@@ -7,12 +7,12 @@ export function stringToStringArray(stringValue: string, separator: string = ","
7
7
  .filter(Boolean);
8
8
  }
9
9
 
10
- /** @throws {TypeError} - Because of `stringToNumber` */
10
+ /** @throws {CliError} - Because of `stringToNumber` */
11
11
  export function stringToNumberArray(stringValue: string, separator: string = ","): number[] {
12
12
  return stringToStringArray(stringValue, separator).map(element => stringToNumber(element));
13
13
  }
14
14
 
15
- /** @throws {TypeError} - Because of `stringToBoolean` */
15
+ /** @throws {CliError} - Because of `stringToBoolean` */
16
16
  export function stringToBooleanArray(stringValue: string, separator: string = ","): boolean[] {
17
17
  return stringToStringArray(stringValue, separator).map(element => stringToBoolean(element));
18
18
  }