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,326 @@
1
+ import type { SchemaType } from "./schema-types.ts";
2
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
3
+
4
+ export interface ErrorCauseI {
5
+ /** Unexpected errors caused by the library itself */
6
+ readonly Internal: keyof InternalErrorI;
7
+
8
+ /** Errors occurring while parsing terminal arguments, usually due to user input */
9
+ readonly Parse: keyof ParseErrorI;
10
+
11
+ /** Errors occurring during validation of parsed arguments, usually due to user input */
12
+ readonly Validation: keyof ValidationErrorI;
13
+
14
+ /** Errors caused by incorrect CLI or subcommand definitions */
15
+ readonly Definition: keyof DefinitionErrorI;
16
+ }
17
+
18
+ export interface InternalErrorI {
19
+ /** The option or argument definition has undefined `_preparedType` */
20
+ readonly MissingPreparedTypes: {
21
+ readonly commandKind: "command" | "subcommand";
22
+ readonly commandName: string;
23
+ readonly kind: "option" | "argument";
24
+ readonly name: string;
25
+ };
26
+
27
+ /** Occurs when attempting to access an undefined subcommand, which should return a CLI definition. */
28
+ readonly CannotFindCliDefinition: {
29
+ readonly cliName: string;
30
+ };
31
+ }
32
+
33
+ export interface DefinitionErrorI {
34
+ /** The CLI or subcommand definition is missing the required `name` or `cliName` property. */
35
+ readonly MissingDefinitionName: {
36
+ readonly commandKind: "command" | "subcommand";
37
+ };
38
+
39
+ /** Calling */
40
+ readonly MissingOnExecute: {
41
+ readonly commandKind: "command" | "subcommand";
42
+ readonly commandName: string;
43
+ };
44
+
45
+ /** An option or argument definition is missing the required `schema` property. */
46
+ readonly MissingSchema: {
47
+ readonly commandKind: "command" | "subcommand";
48
+ readonly commandName: string;
49
+ readonly kind: "option" | "argument";
50
+ readonly name: string;
51
+ };
52
+
53
+ /** The `options` record, `arguments` record, or `subcommands` array is defined but empty. */
54
+ readonly EmptyDefinitionGroup: {
55
+ readonly commandKind: "command" | "subcommand";
56
+ readonly commandName: string;
57
+ readonly kind: "option" | "argument" | "subcommands";
58
+ };
59
+
60
+ /** An option or alias name is written as a negated name (e.g., `noFoo` → `--no-foo`). */
61
+ readonly InvalidDefinitionOptionName: {
62
+ readonly commandKind: "command" | "subcommand";
63
+ readonly commandName: string;
64
+ readonly optionName: string;
65
+ readonly negatedAliasName?: string | undefined;
66
+ };
67
+
68
+ /** An option, option alias, or argument name is duplicated within the same CLI or subcommand. */
69
+ readonly DuplicateDefinitionName: {
70
+ readonly commandKind: "command" | "subcommand";
71
+ readonly commandName: string;
72
+ readonly kind: "option" | "subcommand";
73
+ readonly name: string;
74
+
75
+ /** Present when the checked name is an alias. */
76
+ readonly duplicatedAlias?: string | undefined;
77
+
78
+ /** Where the duplicated name was found. */
79
+ readonly foundInKind: "option" | "argument" | "subcommand";
80
+
81
+ /** Present when the duplicate was found inside aliases of another kind. */
82
+ readonly foundInName?: string;
83
+ };
84
+
85
+ /** Argument names cannot be numeric. */
86
+ readonly InvalidDefinitionArgumentName: {
87
+ readonly commandKind: "command" | "subcommand";
88
+ readonly commandName: string;
89
+ readonly name: string;
90
+ };
91
+
92
+ /**
93
+ * Argument optionality rules:
94
+ *
95
+ * - When `allowPositionals` is enabled, typed arguments cannot be optional.
96
+ * - Otherwise, only the last typed argument may be optional.
97
+ */
98
+ readonly InvalidOptionalArgumentDefinition: {
99
+ readonly commandKind: "command" | "subcommand";
100
+ readonly commandName: string;
101
+ readonly name: string;
102
+ readonly allowPositionals: boolean;
103
+ };
104
+
105
+ /** The option has an `aliases` array containing an empty string. */
106
+ readonly EmptyStringAliasName: {
107
+ readonly commandKind: "command" | "subcommand";
108
+ readonly commandName: string;
109
+ readonly optionName?: string;
110
+ };
111
+
112
+ /** The option or argument definition incorrectly requires itself. */
113
+ readonly SelfRequire: {
114
+ readonly commandKind: "command" | "subcommand";
115
+ readonly commandName: string;
116
+ readonly kind: "option" | "argument";
117
+ readonly name: string;
118
+ };
119
+
120
+ /** The `requires` list contains a name that does not exist. */
121
+ readonly UnknownRequireName: {
122
+ readonly commandKind: "command" | "subcommand";
123
+ readonly commandName: string;
124
+ readonly kind: "option" | "argument";
125
+ readonly name: string;
126
+ readonly requiredName: string;
127
+ };
128
+
129
+ /** The `conflictWith` list contains the same name as the definition itself. */
130
+ readonly SelfConflict: DefinitionErrorI["SelfRequire"];
131
+
132
+ /** The `conflictWith` list contains a name that does not exist. */
133
+ readonly UnknownConflictName: DefinitionErrorI["UnknownRequireName"];
134
+
135
+ /** The `requires` list overlaps with the `conflictWith` list. */
136
+ readonly DefinitionRequiresConflictOverlap: {
137
+ readonly commandKind: "command" | "subcommand";
138
+ readonly commandName: string;
139
+ readonly kind: "option" | "argument";
140
+ readonly name: string;
141
+ readonly intersectedNames: readonly string[];
142
+ };
143
+
144
+ /** Triggered when attempting to generate a help message for a subcommand that does not exist in the CLI definition. */
145
+ readonly SubcommandHelpNotFound: {
146
+ readonly cliName: string;
147
+ readonly subcommandName: string;
148
+ };
149
+ }
150
+
151
+ export interface ParseErrorI {
152
+ /** The parser could not find a matching command in the CLI definition */
153
+ readonly UnknownSubcommand: {
154
+ readonly commandName: string;
155
+ };
156
+
157
+ /** Received an option for a cli or subcommand but no options were defined */
158
+ readonly CommandWithoutOptions: {
159
+ readonly commandKind: "command" | "subcommand";
160
+ readonly commandName: string;
161
+ readonly optionName: string;
162
+ };
163
+
164
+ /** The cli or subcommand define options but could not find a matching option */
165
+ readonly UnknownOption: {
166
+ readonly commandKind: "command" | "subcommand";
167
+ readonly commandName: string;
168
+ readonly optionName: string;
169
+ };
170
+
171
+ /** Triggered when a duplicate option is supplied to a command or subcommand. */
172
+ readonly DuplicateOptionProvided: {
173
+ readonly commandKind: "command" | "subcommand";
174
+ readonly commandName: string;
175
+ readonly optionName: string;
176
+ };
177
+
178
+ /** Triggered when a non-boolean option is incorrectly used with a negation prefix. */
179
+ readonly InvalidNegationForNonBooleanOption: {
180
+ readonly commandKind: "command" | "subcommand";
181
+ readonly commandName: string;
182
+ readonly optionName: string;
183
+ };
184
+
185
+ /** Triggered when a argument is provided to a command or subcommand that does not allow positional arguments. */
186
+ readonly PositionalArgumentNotAllowed: {
187
+ readonly commandKind: "command" | "subcommand";
188
+ readonly commandName: string;
189
+ readonly argumentName: string;
190
+ };
191
+
192
+ /** Triggered when a required option is not provided to a command or subcommand. */
193
+ readonly MissingRequiredOption: {
194
+ readonly commandKind: "command" | "subcommand";
195
+ readonly commandName: string;
196
+ readonly optionName: string;
197
+ };
198
+
199
+ /** Triggered when a required argument is not provided to a command or subcommand. */
200
+ readonly MissingRequiredArgument: {
201
+ readonly commandKind: "command" | "subcommand";
202
+ readonly commandName: string;
203
+ readonly argumentName: string;
204
+ };
205
+
206
+ /** Triggered when an option that requires a value is provided without one in a command or subcommand. */
207
+ readonly OptionMissingValue: {
208
+ readonly commandKind: "command" | "subcommand";
209
+ readonly commandName: string;
210
+ readonly optionName: string;
211
+ };
212
+
213
+ /** Triggered when a flag (single letter options: -v) argument is incorrectly assigned a value using "=". */
214
+ readonly FlagAssignedValue: {
215
+ readonly commandKind: "command" | "subcommand";
216
+ readonly commandName: string;
217
+ readonly flag: string;
218
+ readonly value: string;
219
+ };
220
+ }
221
+
222
+ export interface ValidationErrorI {
223
+ /** Triggered when validating an option on a command or subcommand that has no options defined. */
224
+ readonly NoOptionsToValidate: {
225
+ readonly commandKind: "command" | "subcommand";
226
+ readonly commandName: string;
227
+ };
228
+
229
+ /** Triggered when validating an argument on a command or subcommand that has no arguments defined. */
230
+ readonly NoArgumentsToValidate: {
231
+ readonly commandKind: "command" | "subcommand";
232
+ readonly commandName: string;
233
+ };
234
+
235
+ /** Triggered when attempting to validate an option that does not exist for a command or subcommand. */
236
+ readonly UnknownOptionValidation: {
237
+ readonly commandKind: "command" | "subcommand";
238
+ readonly commandName: string;
239
+ readonly optionName: string;
240
+ };
241
+
242
+ /** Triggered when attempting to validate an argument that does not exist for a command or subcommand. */
243
+ readonly UnknownArgumentValidation: {
244
+ readonly commandKind: "command" | "subcommand";
245
+ readonly commandName: string;
246
+ readonly argumentName: string;
247
+ };
248
+
249
+ /** Triggered when schema validation of an option or argument fails */
250
+ readonly SchemaValidationFailed: {
251
+ readonly commandKind: "command" | "subcommand";
252
+ readonly commandName: string;
253
+ readonly kind: "option" | "argument";
254
+ readonly name: string;
255
+ readonly inputValue: unknown;
256
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
257
+ };
258
+
259
+ /**
260
+ * Triggered when an option or argument cannot be used together with certain other options or arguments due to mutual
261
+ * exclusivity.
262
+ */
263
+ readonly MutuallyExclusiveConflict: {
264
+ readonly kind: "option" | "argument";
265
+ readonly name: string;
266
+ readonly conflictedOptions: readonly string[];
267
+ readonly conflictedArguments: readonly string[];
268
+ };
269
+
270
+ /** Triggered when an option or argument is missing a required dependent option or argument in a command or subcommand. */
271
+ readonly RequiredDependencyMissing: {
272
+ readonly kind: "option" | "argument";
273
+ readonly name: string;
274
+ readonly missingOptions: readonly string[];
275
+ readonly missingArguments: readonly string[];
276
+ };
277
+
278
+ /** Triggered when attempting to perform synchronous validation on an asynchronous schema. */
279
+ readonly AsyncSchemaNotSupported: {
280
+ value: unknown;
281
+ schema: SchemaType;
282
+ };
283
+
284
+ /** Triggered when coercion of a value to the expected type fails during validation. */
285
+ readonly CoercionFailed: {
286
+ readonly providedValue: unknown;
287
+ readonly coerceToType: string;
288
+ };
289
+ }
290
+
291
+ export interface CliErrorI extends DefinitionErrorI, ParseErrorI, ValidationErrorI, InternalErrorI {}
292
+
293
+ export interface CliErrorImpl<O extends CliErrorOptionUnion = CliErrorOptionUnion> extends Error {
294
+ readonly cause: O["cause"];
295
+ readonly code: O["code"];
296
+ readonly context: O["context"];
297
+ }
298
+
299
+ /**
300
+ * Represents a subset of CliErrorOptions filtered by the provided cause. Removes the 'message' property and narrows the
301
+ * union to only relevant cause.
302
+ */
303
+ export type CliErrorOptionByCause<K extends keyof ErrorCauseI, T = CliErrorOptionUnion> = T extends CliErrorOptionUnion
304
+ ? T["cause"] extends K
305
+ ? T
306
+ : never
307
+ : never;
308
+
309
+ interface CliErrorOption<Code extends keyof CliErrorI> {
310
+ cause: { [K in keyof ErrorCauseI]: Code extends ErrorCauseI[K] ? K : never }[keyof ErrorCauseI];
311
+ code: Code;
312
+ context: CliErrorI[Code];
313
+ message?: string;
314
+ }
315
+
316
+ /** A union of all possible CLI error options, one per error code. Each member includes: */
317
+ export type CliErrorOptionUnion = { [Code in keyof CliErrorI]: CliErrorOption<Code> }[keyof CliErrorI];
318
+
319
+ /** A union of all possible CLI error instances */
320
+ export type CliErrorInstanceUnion = CliErrorOptionUnion extends infer T
321
+ ? T extends CliErrorOptionUnion
322
+ ? CliErrorImpl<T>
323
+ : never
324
+ : never;
325
+
326
+ export type AllCliErrorInstances = CliErrorInstanceUnion & {};
@@ -1,9 +1,94 @@
1
1
  import type { Cli, Subcommand } from "./definitions-types.ts";
2
+ import type { AllCliErrorInstances } from "./error-types.ts";
2
3
  import type { PrintHelpOptions } from "./help-message-types.ts";
3
4
  import type { InferInputType, InputTypeWide, OutputType, OutputTypeWide } from "./io-types.ts";
4
5
 
5
- type PrimitiveTypeNames = "string" | "number" | "boolean" | "object" | "unknown";
6
- export type CoerceTypes = PrimitiveTypeNames | `${PrimitiveTypeNames}[]` | `set<${PrimitiveTypeNames}>` | (string & {});
6
+ export type CoerceTypes = "boolean" | (string & {});
7
+
8
+ export interface ObjectCoerceMethodOptions {
9
+ /**
10
+ * Converts `'true'` or `'false'` (case-sensitive) strings to boolean values.
11
+ *
12
+ * The coercion is applied after parsing the string as JSON.
13
+ *
14
+ * ```bash
15
+ * # coerced to boolean
16
+ * --obj.key=true # true
17
+ * --obj.key false # false
18
+ *
19
+ * # remains a string (case-sensitive)
20
+ * --obj.key=FALSE # "FALSE"
21
+ * ```
22
+ *
23
+ * @example
24
+ * coerce: coerce.object({ coerceBoolean: true }); // coerce all boolean-like keys
25
+ * coerce: coerce.object({ coerceBoolean: ["key.nested"] }); // coerce only specific keys
26
+ */
27
+ coerceBoolean?: boolean | string[];
28
+
29
+ /**
30
+ * Converts strings matching a number regex to numbers.
31
+ *
32
+ * The coercion is applied after parsing the string as JSON.
33
+ *
34
+ * ```bash
35
+ * # parsed as number
36
+ * --obj.key=123
37
+ * --obj.key 123.45
38
+ * --obj.key -123.45
39
+ * --obj.key +123.45
40
+ *
41
+ * # remains a string (invalid number)
42
+ * --obj.key 1.23.45
43
+ * --obj.key string
44
+ * ```
45
+ *
46
+ * @example
47
+ * coerce: coerce.object({ coerceNumber: true }); // coerce all numeric keys
48
+ * coerce: coerce.object({ coerceNumber: ["key.nested"] }); // coerce only specific keys
49
+ */
50
+ coerceNumber?: boolean | string[];
51
+
52
+ /**
53
+ * Converts strings matching a number regex to bigints.
54
+ *
55
+ * The coercion is applied after parsing the string as JSON.
56
+ *
57
+ * ```bash
58
+ * # parsed as bigint
59
+ * --obj.key=12345678901234567890
60
+ *
61
+ * # remains a string (invalid bigint)
62
+ * --obj.key 123.45
63
+ * --obj.key string
64
+ * ```
65
+ *
66
+ * @example
67
+ * coerce: coerce.object({ coerceBigint: true }); // coerce all bigint-like keys
68
+ * coerce: coerce.object({ coerceBigint: ["key.id"] }); // coerce only specific keys
69
+ */
70
+ coerceBigint?: boolean | string[];
71
+
72
+ /**
73
+ * Converts tries to convert any string to `Date` objects.
74
+ *
75
+ * The coercion is applied after parsing the string as JSON.
76
+ *
77
+ * ```bash
78
+ * # parsed as Date
79
+ * --obj.key="2024-03-12T10:30:00Z"
80
+ * --obj.key "2025-11-13"
81
+ *
82
+ * # remains a string (invalid date)
83
+ * --obj.key "invalid-date"
84
+ * ```
85
+ *
86
+ * @example
87
+ * coerce: coerce.object({ coerceDate: true }); // coerce all date-like keys
88
+ * coerce: coerce.object({ coerceDate: ["user.createdAt"] }); // coerce only specific keys
89
+ */
90
+ coerceDate?: boolean | string[];
91
+ }
7
92
 
8
93
  export interface CoerceMethod<Value> {
9
94
  (terminalInput: string): Value;
@@ -27,20 +112,27 @@ export interface AttachedMethods<T extends Cli | Subcommand> {
27
112
  */
28
113
  onExecute: (handler: (data: OutputType<[T]>) => void) => Unsubscribe;
29
114
 
30
- // Make the argument optional if it has undefined type
115
+ /** Execute the main command/subcommand programmatically */
31
116
  execute: InferInputType<T> extends infer InputType
32
117
  ? undefined extends InputType
33
118
  ? (input?: InputType) => void
34
119
  : (input: InputType) => void
35
120
  : never;
36
121
 
122
+ /** Execute the main command/subcommand programmatically */
123
+ executeAsync: InferInputType<T> extends infer InputType
124
+ ? undefined extends InputType
125
+ ? (input?: InputType) => Promise<void>
126
+ : (input: InputType) => Promise<void>
127
+ : never;
128
+
37
129
  /** **WARNING**: This will only be available after the CLI schema has been created */
38
130
  generateCliHelpMessage?: (options?: PrintHelpOptions) => string;
39
131
 
40
132
  /**
41
133
  * **WARNING**: This will only be available after the CLI schema has been created
42
134
  *
43
- * @throws {Error} - When the subcommand is not found
135
+ * @throws {CliError} - When the subcommand is not found
44
136
  */
45
137
  generateSubcommandHelpMessage?: (
46
138
  subcommandName: GetSubcommandsNames<T> | (string & {}),
@@ -49,10 +141,11 @@ export interface AttachedMethods<T extends Cli | Subcommand> {
49
141
  }
50
142
 
51
143
  export interface AttachedMethodsWide {
52
- onExecute: (handler: (data: OutputTypeWide) => void) => Unsubscribe;
144
+ onExecute: (handler: (data: OutputTypeWide) => void | Promise<void>) => Unsubscribe;
53
145
  execute: (input?: InputTypeWide) => void;
146
+ executeAsync: (input?: InputTypeWide) => Promise<void>;
54
147
  generateCliHelpMessage?: (options?: PrintHelpOptions) => void;
55
- /** @throws {Error} - When the subcommand is not found */
148
+ /** @throws {CliError} - When the subcommand is not found */
56
149
  generateSubcommandHelpMessage?: (subcommandName: string, options?: PrintHelpOptions) => void;
57
150
  }
58
151
 
@@ -62,7 +155,7 @@ export type CliOutputType<S extends Cli> =
62
155
 
63
156
  export type CliParseResult<S extends Cli> =
64
157
  | { value: CliOutputType<S>; error?: undefined }
65
- | { value?: never; error: Error };
158
+ | { value?: never; error: AllCliErrorInstances };
66
159
 
67
160
  export type CliParseResultWide = { value: OutputTypeWide; error?: undefined } | { value?: never; error: Error };
68
161
 
@@ -14,13 +14,3 @@ export type AllowUndefinedIfOptional<T> = {
14
14
  }[keyof T] extends never
15
15
  ? T | undefined
16
16
  : T;
17
-
18
- /** Widen literal and tuples */
19
- // prettier-ignore
20
- export type Widen<T> =
21
- T extends string ? string :
22
- T extends number ? number :
23
- T extends boolean ? boolean :
24
- T extends readonly (infer U)[] ? Widen<U>[] :
25
- T extends Set<infer U> ? Set<Widen<U>> :
26
- T;
@@ -0,0 +1,79 @@
1
+ /** Parse a string into an argv (array of arguments) */
2
+ export function parseArgv(input: string): string[] {
3
+ const argv = [];
4
+
5
+ let currentQuote: string | undefined = undefined;
6
+ let currentArgument: string | undefined = undefined;
7
+
8
+ for (let index = 0; index < input.length; index++) {
9
+ const char = input[index];
10
+ const previousChar = input[index - 1];
11
+ const nextChar = input[index + 1];
12
+ const end = index === input.length - 1;
13
+
14
+ // entering/leaving quote
15
+ if ((char === '"' || char === "'") && previousChar !== "\\") {
16
+ // leaving quote
17
+ if (currentQuote === char) {
18
+ currentQuote = undefined;
19
+ continue;
20
+ }
21
+
22
+ // entering quote
23
+ if (currentQuote === undefined) {
24
+ currentQuote = char;
25
+ continue;
26
+ }
27
+
28
+ // quote inside quote
29
+ if (currentQuote !== undefined && char !== currentQuote) {
30
+ currentArgument ??= "";
31
+ currentArgument += char;
32
+ continue;
33
+ }
34
+ continue;
35
+ }
36
+
37
+ // new line
38
+ if (char === "\\" && nextChar === "\n") {
39
+ index++;
40
+ continue;
41
+ }
42
+
43
+ // Add to argv
44
+ if (currentArgument !== undefined && currentQuote === undefined) {
45
+ if (char === " ") {
46
+ argv.push(currentArgument);
47
+ currentArgument = undefined;
48
+ continue;
49
+ }
50
+
51
+ if (end) {
52
+ currentArgument += char;
53
+ argv.push(currentArgument);
54
+ currentArgument = undefined;
55
+ continue;
56
+ }
57
+ }
58
+
59
+ // Ignore spaces outside of quotes
60
+ if (char === " " && currentQuote === undefined) {
61
+ continue;
62
+ }
63
+
64
+ // Ignore escaped characters
65
+ if (char === "\\" && (nextChar === "'" || nextChar === '"')) {
66
+ continue;
67
+ }
68
+
69
+ currentArgument ??= "";
70
+ currentArgument += char;
71
+ }
72
+
73
+ // Add last argument
74
+ if (currentArgument !== undefined) {
75
+ argv.push(currentArgument);
76
+ }
77
+
78
+ return argv;
79
+ }
@@ -0,0 +1,72 @@
1
+ import { CliError } from "../cli-error/cli-error.ts";
2
+ import { ErrorCause } from "../cli-error/error-cause.ts";
3
+ import { ValidationErrorCode } from "../cli-error/error-code/validation-error-code.ts";
4
+
5
+ import type { Argument, Option, PreparedType } from "../types/definitions-types.ts";
6
+ import type { SchemaResult, SchemaType } from "../types/schema-types.ts";
7
+ import type { CoerceMethod } from "../types/types.ts";
8
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
9
+
10
+ /** @throws {CliError} When schema is async */
11
+ export function validateSync(schema: SchemaType, value?: unknown): SchemaResult {
12
+ const results = schema["~standard"].validate(value);
13
+ if (results instanceof Promise) {
14
+ throw new CliError({
15
+ cause: ErrorCause.Validation,
16
+ code: ValidationErrorCode.AsyncSchemaNotSupported,
17
+ context: { schema, value },
18
+ });
19
+ }
20
+
21
+ return results;
22
+ }
23
+
24
+ /** @throws {CliError} When schema is async */
25
+ export function defaultValueAndIsOptional(schema: SchemaType): { defaultValue: unknown; optional: boolean } {
26
+ const results = validateSync(schema);
27
+
28
+ if (results.issues) {
29
+ return { defaultValue: undefined, optional: false };
30
+ }
31
+
32
+ return { defaultValue: results.value, optional: true };
33
+ }
34
+
35
+ /** @throws {CliError} When schema is async */
36
+ function PrepareType(schema: SchemaType, coerceHandler: CoerceMethod<unknown>): PreparedType {
37
+ const { optional, defaultValue } = defaultValueAndIsOptional(schema);
38
+
39
+ return {
40
+ schema,
41
+ optional,
42
+ defaultValue,
43
+ coerceTo: coerceHandler.type,
44
+ validate: (value?: string) => validateSync(schema, value && coerceHandler(value)),
45
+ };
46
+ }
47
+
48
+ /** @throws {CliError} When schema is async */
49
+ export function prepareDefinitionTypes(definition: Record<string, Argument> | Record<string, Option> | undefined) {
50
+ if (!definition) return;
51
+
52
+ for (const object of Object.values<Argument | Option>(definition)) {
53
+ if (!object.coerce) {
54
+ (object.coerce as CoerceMethod<string> | undefined) = (value: string) => value;
55
+ }
56
+
57
+ if (!object._preparedType) {
58
+ object._preparedType = PrepareType(object.schema, object.coerce!);
59
+ }
60
+ }
61
+ }
62
+
63
+ /** Prettify Standard Schema V1 issues */
64
+ export function prettifyError(issues: ReadonlyArray<StandardSchemaV1.Issue>): string {
65
+ return issues
66
+ .map(issue => {
67
+ const path = issue.path?.map(seg => (typeof seg === "object" && "key" in seg ? seg.key : seg));
68
+ const pathString = path && path.length > 0 ? ` at "${path.join(".")}"` : "";
69
+ return `${issue.message}${pathString}`;
70
+ })
71
+ .join(" : ");
72
+ }