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

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 +230 -289
  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 +1 -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 +7 -7
  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
@@ -1,2 +1,62 @@
1
- function buildObjectContext(o,e){const t={subcommand:"cliName"in e?void 0:e.name};return e.options&&buildForOptionsOrArguments(e.options,t,o.options,"options"),e.arguments&&buildForOptionsOrArguments(e.arguments,t,o.arguments,"arguments"),e.allowPositionals&&(t.positionals??(t.positionals=o.positionals)),t}function buildForOptionsOrArguments(o,e,t,n){const i=Object.entries(o);for(const[o,r]of i){if(!r._preparedType)throw new Error(`internal error: missing prepared type for ${n.slice(0,-1)} "${o}"`);const{schema:i,optional:s,defaultValue:a}=r._preparedType;if(t&&o in t){const r=t[o];e[n]??(e[n]={}),e[n][o]=void 0===r?{schema:i,optional:s,defaultValue:a,source:"default"}:{schema:i,optional:s,defaultValue:a,passedValue:r,source:"programmatic"};continue}if(!s)throw new Error(`the ${n.slice(0,-1)} "${o}" is required`);e[n]??(e[n]={}),e[n][o]={schema:i,optional:s,defaultValue:a,source:"default"}}}export{buildObjectContext};
2
- //# sourceMappingURL=object-context-builder.mjs.map
1
+ // src/parse/context/object-context-builder.ts
2
+ import { CliError } from "../../cli-error/cli-error.mjs";
3
+ import { ErrorCause } from "../../cli-error/error-cause.mjs";
4
+ import { InternalErrorCode } from "../../cli-error/error-code/internal-error-code.mjs";
5
+ import { ParseErrorCode } from "../../cli-error/error-code/parse-error-code.mjs";
6
+ function buildObjectContext(inputValues, commandDefinition) {
7
+ const context = {
8
+ subcommand: "cliName" in commandDefinition ? void 0 : commandDefinition.name
9
+ };
10
+ buildForOptionsOrArguments(commandDefinition, context, inputValues.options, "options");
11
+ buildForOptionsOrArguments(commandDefinition, context, inputValues.arguments, "arguments");
12
+ if (commandDefinition.allowPositionals) {
13
+ context.positionals ??= inputValues.positionals;
14
+ }
15
+ return context;
16
+ }
17
+ function buildForOptionsOrArguments(commandDefinition, context, inputRecord, type) {
18
+ if (!commandDefinition[type]) return;
19
+ const optionOrArgumentDefinitions = commandDefinition[type];
20
+ const kind = type.slice(0, -1);
21
+ const commandKind = "cliName" in commandDefinition ? "command" : "subcommand";
22
+ const commandName = "cliName" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;
23
+ const definitionEntries = Object.entries(optionOrArgumentDefinitions);
24
+ for (const [name, definition] of definitionEntries) {
25
+ if (!definition._preparedType) {
26
+ throw new CliError({
27
+ cause: ErrorCause.Internal,
28
+ code: InternalErrorCode.MissingPreparedTypes,
29
+ context: { commandKind, commandName, kind, name }
30
+ });
31
+ }
32
+ const { schema, optional, defaultValue } = definition._preparedType;
33
+ if (inputRecord && name in inputRecord) {
34
+ const passedValue = inputRecord[name];
35
+ context[type] ??= {};
36
+ context[type][name] = passedValue === void 0 ? { schema, optional, defaultValue, source: "default" } : { schema, optional, defaultValue, passedValue, source: "programmatic" };
37
+ continue;
38
+ }
39
+ if (!optional) {
40
+ if (kind === "option") {
41
+ throw new CliError({
42
+ cause: ErrorCause.Parse,
43
+ code: ParseErrorCode.MissingRequiredOption,
44
+ context: { commandKind, commandName, optionName: name }
45
+ });
46
+ }
47
+ if (kind === "argument") {
48
+ throw new CliError({
49
+ cause: ErrorCause.Parse,
50
+ code: ParseErrorCode.MissingRequiredArgument,
51
+ context: { commandKind, commandName, argumentName: name }
52
+ });
53
+ }
54
+ }
55
+ context[type] ??= {};
56
+ context[type][name] = { schema, optional, defaultValue, source: "default" };
57
+ }
58
+ }
59
+ export {
60
+ buildObjectContext
61
+ };
62
+ //# sourceMappingURL=object-context-builder.mjs.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["buildObjectContext","inputValues","commandDefinition","context","subcommand","name","options","buildForOptionsOrArguments","arguments","allowPositionals","positionals","definitionRecord","inputRecord","type","definitionEntries","Object","entries","definition","_preparedType","Error","slice","schema","optional","defaultValue","passedValue","source"],"sources":["../../../../src/parse/context/object-context-builder.ts"],"sourcesContent":["import type { ContextWide } from \"../../types/context-types.ts\";\nimport type { Argument, Cli, Option, Subcommand } from \"../../types/definitions-types.ts\";\nimport type { InputTypeWide } from \"../../types/io-types.ts\";\n\n/** @throws {Error} */\nexport function buildObjectContext(inputValues: InputTypeWide, commandDefinition: Subcommand | Cli) {\n const context: ContextWide = {\n subcommand: \"cliName\" in commandDefinition ? undefined : commandDefinition.name,\n };\n\n if (commandDefinition.options) {\n buildForOptionsOrArguments(commandDefinition.options, context, inputValues.options, \"options\");\n }\n\n if (commandDefinition.arguments) {\n buildForOptionsOrArguments(commandDefinition.arguments, context, inputValues.arguments, \"arguments\");\n }\n\n if (commandDefinition.allowPositionals) {\n context.positionals ??= inputValues.positionals;\n }\n\n return context;\n}\n\nfunction buildForOptionsOrArguments(\n definitionRecord: Record<string, Option> | Record<string, Argument>,\n context: ContextWide,\n inputRecord: Record<string, unknown> | undefined,\n type: \"options\" | \"arguments\",\n) {\n const definitionEntries = Object.entries(definitionRecord) as [string, Option][] | [string, Argument][];\n\n for (const [name, definition] of definitionEntries) {\n if (!definition._preparedType) {\n throw new Error(`internal error: missing prepared type for ${type.slice(0, -1)} \"${name}\"`);\n }\n\n const { schema, optional, defaultValue } = definition._preparedType;\n\n // Case the value is passed\n if (inputRecord && name in inputRecord) {\n const passedValue = inputRecord[name];\n\n context[type] ??= {};\n context[type][name] =\n passedValue === undefined\n ? { schema, optional, defaultValue, source: \"default\" }\n : { schema, optional, defaultValue, passedValue, source: \"programmatic\" };\n\n continue;\n }\n\n // case the value is not passed\n if (!optional) {\n throw new Error(`the ${type.slice(0, -1)} \"${name}\" is required`);\n }\n\n // case the value is optional\n context[type] ??= {};\n context[type][name] = { schema, optional, defaultValue, source: \"default\" };\n }\n}\n"],"mappings":"AAKO,SAASA,mBAAmBC,EAA4BC,GAC7D,MAAMC,EAAuB,CAC3BC,WAAY,YAAaF,OAAoB,EAAYA,EAAkBG,MAe7E,OAZIH,EAAkBI,SACpBC,2BAA2BL,EAAkBI,QAASH,EAASF,EAAYK,QAAS,WAGlFJ,EAAkBM,WACpBD,2BAA2BL,EAAkBM,UAAWL,EAASF,EAAYO,UAAW,aAGtFN,EAAkBO,mBACpBN,EAAQO,cAARP,EAAQO,YAAgBT,EAAYS,cAG/BP,CACT,CAEA,SAASI,2BACPI,EACAR,EACAS,EACAC,GAEA,MAAMC,EAAoBC,OAAOC,QAAQL,GAEzC,UAAYN,EAAMY,KAAeH,EAAmB,CAClD,IAAKG,EAAWC,cACd,MAAM,IAAIC,MAAM,6CAA6CN,EAAKO,MAAM,GAAG,OAAQf,MAGrF,MAAMgB,OAAEA,EAAAC,SAAQA,EAAAC,aAAUA,GAAiBN,EAAWC,cAGtD,GAAIN,GAAeP,KAAQO,EAAa,CACtC,MAAMY,EAAcZ,EAAYP,GAEhCF,EAAAU,KAAAV,EAAAU,GAAkB,CAAC,GACnBV,EAAQU,GAAMR,QACI,IAAhBmB,EACI,CAAEH,SAAQC,WAAUC,eAAcE,OAAQ,WAC1C,CAAEJ,SAAQC,WAAUC,eAAcC,cAAaC,OAAQ,gBAE7D,QACF,CAGA,IAAKH,EACH,MAAM,IAAIH,MAAM,OAAON,EAAKO,MAAM,GAAG,OAAQf,kBAI/CF,EAAAU,KAAAV,EAAAU,GAAkB,CAAC,GACnBV,EAAQU,GAAMR,GAAQ,CAAEgB,SAAQC,WAAUC,eAAcE,OAAQ,UAClE,CACF,Q","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/parse/context/object-context-builder.ts"],
4
+ "sourcesContent": ["import { CliError } from \"../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../cli-error/error-cause.ts\";\nimport { InternalErrorCode } from \"../../cli-error/error-code/internal-error-code.ts\";\nimport { ParseErrorCode } from \"../../cli-error/error-code/parse-error-code.ts\";\n\nimport type { ContextWide } from \"../../types/context-types.ts\";\nimport type { Argument, Cli, Option, Subcommand } from \"../../types/definitions-types.ts\";\nimport type { InputTypeWide } from \"../../types/io-types.ts\";\n\n/** @throws {CliError} */\nexport function buildObjectContext(inputValues: InputTypeWide, commandDefinition: Subcommand | Cli) {\n const context: ContextWide = {\n subcommand: \"cliName\" in commandDefinition ? undefined : commandDefinition.name,\n };\n\n buildForOptionsOrArguments(commandDefinition, context, inputValues.options, \"options\");\n\n buildForOptionsOrArguments(commandDefinition, context, inputValues.arguments, \"arguments\");\n\n if (commandDefinition.allowPositionals) {\n context.positionals ??= inputValues.positionals;\n }\n\n return context;\n}\n\nfunction buildForOptionsOrArguments(\n commandDefinition: Subcommand | Cli,\n context: ContextWide,\n inputRecord: Record<string, unknown> | undefined,\n type: \"options\" | \"arguments\",\n) {\n if (!commandDefinition[type]) return;\n\n const optionOrArgumentDefinitions = commandDefinition[type];\n const kind = type.slice(0, -1) as \"option\" | \"argument\";\n const commandKind = \"cliName\" in commandDefinition ? \"command\" : \"subcommand\";\n const commandName = \"cliName\" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;\n\n const definitionEntries = Object.entries(optionOrArgumentDefinitions) as [string, Option][] | [string, Argument][];\n\n for (const [name, definition] of definitionEntries) {\n if (!definition._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: { commandKind, commandName, kind, name },\n });\n }\n\n const { schema, optional, defaultValue } = definition._preparedType;\n\n // Case the value is passed\n if (inputRecord && name in inputRecord) {\n const passedValue = inputRecord[name];\n\n context[type] ??= {};\n context[type][name] =\n passedValue === undefined\n ? { schema, optional, defaultValue, source: \"default\" }\n : { schema, optional, defaultValue, passedValue, source: \"programmatic\" };\n\n continue;\n }\n\n // case the value is not passed\n if (!optional) {\n if (kind === \"option\") {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.MissingRequiredOption,\n context: { commandKind, commandName, optionName: name },\n });\n }\n\n if (kind === \"argument\") {\n throw new CliError({\n cause: ErrorCause.Parse,\n code: ParseErrorCode.MissingRequiredArgument,\n context: { commandKind, commandName, argumentName: name },\n });\n }\n }\n\n // case the value is optional\n context[type] ??= {};\n context[type][name] = { schema, optional, defaultValue, source: \"default\" };\n }\n}\n"],
5
+ "mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAOxB,SAAS,mBAAmB,aAA4B,mBAAqC;AAClG,QAAM,UAAuB;AAAA,IAC3B,YAAY,aAAa,oBAAoB,SAAY,kBAAkB;AAAA,EAC7E;AAEA,6BAA2B,mBAAmB,SAAS,YAAY,SAAS,SAAS;AAErF,6BAA2B,mBAAmB,SAAS,YAAY,WAAW,WAAW;AAEzF,MAAI,kBAAkB,kBAAkB;AACtC,YAAQ,gBAAgB,YAAY;AAAA,EACtC;AAEA,SAAO;AACT;AAEA,SAAS,2BACP,mBACA,SACA,aACA,MACA;AACA,MAAI,CAAC,kBAAkB,IAAI,EAAG;AAE9B,QAAM,8BAA8B,kBAAkB,IAAI;AAC1D,QAAM,OAAO,KAAK,MAAM,GAAG,EAAE;AAC7B,QAAM,cAAc,aAAa,oBAAoB,YAAY;AACjE,QAAM,cAAc,aAAa,oBAAoB,kBAAkB,UAAU,kBAAkB;AAEnG,QAAM,oBAAoB,OAAO,QAAQ,2BAA2B;AAEpE,aAAW,CAAC,MAAM,UAAU,KAAK,mBAAmB;AAClD,QAAI,CAAC,WAAW,eAAe;AAC7B,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,kBAAkB;AAAA,QACxB,SAAS,EAAE,aAAa,aAAa,MAAM,KAAK;AAAA,MAClD,CAAC;AAAA,IACH;AAEA,UAAM,EAAE,QAAQ,UAAU,aAAa,IAAI,WAAW;AAGtD,QAAI,eAAe,QAAQ,aAAa;AACtC,YAAM,cAAc,YAAY,IAAI;AAEpC,cAAQ,IAAI,MAAM,CAAC;AACnB,cAAQ,IAAI,EAAE,IAAI,IAChB,gBAAgB,SACZ,EAAE,QAAQ,UAAU,cAAc,QAAQ,UAAU,IACpD,EAAE,QAAQ,UAAU,cAAc,aAAa,QAAQ,eAAe;AAE5E;AAAA,IACF;AAGA,QAAI,CAAC,UAAU;AACb,UAAI,SAAS,UAAU;AACrB,cAAM,IAAI,SAAS;AAAA,UACjB,OAAO,WAAW;AAAA,UAClB,MAAM,eAAe;AAAA,UACrB,SAAS,EAAE,aAAa,aAAa,YAAY,KAAK;AAAA,QACxD,CAAC;AAAA,MACH;AAEA,UAAI,SAAS,YAAY;AACvB,cAAM,IAAI,SAAS;AAAA,UACjB,OAAO,WAAW;AAAA,UAClB,MAAM,eAAe;AAAA,UACrB,SAAS,EAAE,aAAa,aAAa,cAAc,KAAK;AAAA,QAC1D,CAAC;AAAA,MACH;AAAA,IACF;AAGA,YAAQ,IAAI,MAAM,CAAC;AACnB,YAAQ,IAAI,EAAE,IAAI,IAAI,EAAE,QAAQ,UAAU,cAAc,QAAQ,UAAU;AAAA,EAC5E;AACF;",
6
+ "names": []
7
+ }
@@ -1,2 +1,108 @@
1
- function findSubcommandDefinition(e,n){return void 0===e?n:n.subcommands?n.subcommands.find(n=>n.name===e||e&&n.aliases&&n.aliases.includes(e)):void 0}function findOption(e,n){const t=optionArgumentToVariableNames(e),o=e.startsWith("--no-");return Object.entries(n).find(([e,n])=>{if(t.has(e))return!0;const a=n._preparedType&&"boolean"===n._preparedType.coerceTo;return!!(o&&a&&t.has(negateOption(e)))||!!n.aliases&&(!!n.aliases.some(e=>t.has(e))||!!(o&&a&&n.aliases.map(e=>negateOption(e)).some(e=>t.has(e))))})}function decoupleFlags(e){const n=/^-[a-z0-9]{2,}$/i,t=[];for(const o of e){if(!n.test(o)){t.push(o);continue}const e=o.slice(1).split("").map(e=>"-"+e);t.push(...e)}return t}function optionArgumentToVariableNames(e){if(!e.startsWith("-"))throw new Error(`invalid option name: ${e}`);e=(e=e.startsWith("--")?e.slice(2):e.slice(1)).toLowerCase();const n=new Set,t=e.replace(/-(.)/g,e=>e[1].toUpperCase());n.add(t),n.add(t.replace(/^(.)/,e=>e.toUpperCase()));const o=e.replace(/-(.)/g,e=>"_"+e[1]);return n.add(o),n.add(o.toUpperCase()),n}function isFlagArgument(e){return/^-[A-Za-z]$/.test(e)}function isLongArgument(e){return/^--[A-Za-z-]+[A-Za-z0-9]$/.test(e)}function isOptionArgument(e){return"string"==typeof e&&(isFlagArgument(e)||isLongArgument(e))}function negateOption(e){return"no"+e.replace(/^[a-z]/,e=>e.toUpperCase())}function transformOptionToArgument(e){return 1===e.length?`-${e.toLowerCase()}`:/^[a-z_]+$/.test(e)||/^[A-Z_]+$/.test(e)?`--${(e=e.replace(/_/g,"-")).toLowerCase()}`:`--${(e=e.replace(/[A-Z]/g,(e,n)=>n>0?"-"+e:e)).toLowerCase()}`}export{decoupleFlags,findOption,findSubcommandDefinition,isFlagArgument,isOptionArgument,negateOption,optionArgumentToVariableNames,transformOptionToArgument};
2
- //# sourceMappingURL=parser-utilities.mjs.map
1
+ // src/parse/parser-utilities.ts
2
+ function findSubcommandDefinition(subcommandName, cliDefinition) {
3
+ if (subcommandName === void 0) {
4
+ return cliDefinition;
5
+ }
6
+ if (!cliDefinition.subcommands) {
7
+ return;
8
+ }
9
+ return cliDefinition.subcommands.find((c) => {
10
+ if (c.name === subcommandName) {
11
+ return true;
12
+ }
13
+ return subcommandName && c.aliases && c.aliases.includes(subcommandName);
14
+ });
15
+ }
16
+ function findOption(optionArgument, options) {
17
+ const validVariableNames = optionArgumentToVariableNames(optionArgument);
18
+ const isNegated = optionArgument.startsWith("--no-");
19
+ const option = Object.entries(options).find(([optionName, option2]) => {
20
+ if (validVariableNames.has(optionName)) {
21
+ return true;
22
+ }
23
+ if (isNegated && validVariableNames.has(negateOption(optionName))) {
24
+ return true;
25
+ }
26
+ if (!option2.aliases) {
27
+ return false;
28
+ }
29
+ if (option2.aliases.some((a) => validVariableNames.has(a))) {
30
+ return true;
31
+ }
32
+ if (isNegated && option2.aliases.map((alias) => negateOption(alias)).some((a) => validVariableNames.has(a))) {
33
+ return true;
34
+ }
35
+ return false;
36
+ });
37
+ return option;
38
+ }
39
+ function decoupleFlags(arguments_) {
40
+ const flagsRe = /^-[a-z0-9]{2,}$/i;
41
+ const result = [];
42
+ for (const argument of arguments_) {
43
+ const isCoupled = flagsRe.test(argument);
44
+ if (!isCoupled) {
45
+ result.push(argument);
46
+ continue;
47
+ }
48
+ const decoupledArray = argument.slice(1).split("").map((c) => "-" + c);
49
+ result.push(...decoupledArray);
50
+ }
51
+ return result;
52
+ }
53
+ function optionArgumentToVariableNames(name) {
54
+ name = name.startsWith("--") ? name.slice(2) : name.slice(1);
55
+ name = name.toLowerCase();
56
+ const results = /* @__PURE__ */ new Set();
57
+ const camelCase = name.replace(/-(.)/g, (m) => m[1].toUpperCase());
58
+ results.add(camelCase);
59
+ results.add(camelCase.replace(/^(.)/, (m) => m.toUpperCase()));
60
+ const snake_case = name.replace(/-(.)/g, (g) => "_" + g[1]);
61
+ results.add(snake_case);
62
+ results.add(snake_case.toUpperCase());
63
+ return results;
64
+ }
65
+ function isFlagArgument(name) {
66
+ return /^-[A-Za-z]$/.test(name);
67
+ }
68
+ function isLongArgument(name) {
69
+ return /^--.{2,}/.test(name);
70
+ }
71
+ function isOptionArgument(name) {
72
+ if (typeof name !== "string") {
73
+ return false;
74
+ }
75
+ return isFlagArgument(name) || isLongArgument(name);
76
+ }
77
+ function negateOption(name) {
78
+ return "no" + name.replace(/^[a-z]/, (g) => g.toUpperCase());
79
+ }
80
+ function transformOptionToArgument(name) {
81
+ if (name.length === 1) {
82
+ return `-${name.toLowerCase()}`;
83
+ }
84
+ if (/^[a-z_]+$/.test(name) || /^[A-Z_]+$/.test(name)) {
85
+ name = name.replace(/_/g, "-");
86
+ return `--${name.toLowerCase()}`;
87
+ }
88
+ name = name.replace(/[A-Z]/g, (match, index) => index > 0 ? "-" + match : match);
89
+ return `--${name.toLowerCase()}`;
90
+ }
91
+ function splitAndGetKeys(option) {
92
+ const parts = option.split(".");
93
+ const optionName = parts[0];
94
+ const keys = parts.slice(1).filter(Boolean);
95
+ return [optionName, keys];
96
+ }
97
+ export {
98
+ decoupleFlags,
99
+ findOption,
100
+ findSubcommandDefinition,
101
+ isFlagArgument,
102
+ isOptionArgument,
103
+ negateOption,
104
+ optionArgumentToVariableNames,
105
+ splitAndGetKeys,
106
+ transformOptionToArgument
107
+ };
108
+ //# sourceMappingURL=parser-utilities.mjs.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["findSubcommandDefinition","subcommandName","cliDefinition","subcommands","find","c","name","aliases","includes","findOption","optionArgument","options","validVariableNames","optionArgumentToVariableNames","isNegated","startsWith","Object","entries","optionName","option","has","isBool","_preparedType","coerceTo","negateOption","some","a","map","alias","decoupleFlags","arguments_","flagsRe","result","argument","test","push","decoupledArray","slice","split","Error","toLowerCase","results","Set","camelCase","replace","m","toUpperCase","add","snake_case","g","isFlagArgument","isLongArgument","isOptionArgument","transformOptionToArgument","length","match","index"],"sources":["../../../src/parse/parser-utilities.ts"],"sourcesContent":["import type { Cli, Option, Subcommand } from \"../types/definitions-types.ts\";\n\n/**\n * Retrieves a subcommand object from an array of subcommands by matching the provided subcommand name against the\n * subcommand's name or its aliases.\n *\n * @param subcommandName - The name or alias of the subcommand to search for.\n * @param subcommandArr - An array of `Subcommand` objects to search within.\n * @returns The matching `Subcommand` object if found; otherwise, `undefined`.\n */\nexport function findSubcommandDefinition(\n subcommandName: string | undefined,\n cliDefinition: Cli,\n): Subcommand | Cli | undefined {\n if (subcommandName === undefined) {\n return cliDefinition;\n }\n\n if (!cliDefinition.subcommands) {\n return;\n }\n\n return cliDefinition.subcommands.find(c => {\n // match for undefined too\n if (c.name === subcommandName) {\n return true;\n }\n\n // match for aliases\n return subcommandName && c.aliases && c.aliases.includes(subcommandName);\n });\n}\n\n/**\n * Finds and returns an `Option` object from the provided list that matches the given argument string.\n *\n * The function supports matching by option name, aliases, and their negated forms (e.g., `--no-` prefix).\n *\n * @param optionArgument - The argument string to match (e.g., `--foo`, `--no-bar`, `-f`).\n * @param options - An array of `Option` objects to search through.\n * @returns The matching `Option` object if found; otherwise, `undefined`.\n */\nexport function findOption(optionArgument: string, options: Record<string, Option>): [string, Option] | undefined {\n const validVariableNames = optionArgumentToVariableNames(optionArgument);\n const isNegated = optionArgument.startsWith(\"--no-\");\n\n const option = Object.entries(options).find(([optionName, option]) => {\n if (validVariableNames.has(optionName)) {\n return true;\n }\n\n const isBool = option._preparedType && option._preparedType.coerceTo === \"boolean\";\n\n if (isNegated && isBool && validVariableNames.has(negateOption(optionName))) {\n return true;\n }\n\n if (!option.aliases) {\n return false;\n }\n\n if (option.aliases.some(a => validVariableNames.has(a))) {\n return true;\n }\n\n if (isNegated && isBool && option.aliases.map(alias => negateOption(alias)).some(a => validVariableNames.has(a))) {\n return true;\n }\n\n return false;\n });\n\n return option;\n}\n\n/** - Decouple flags E.g. `-rf` -> `-r, -f` */\nexport function decoupleFlags(arguments_: string[]): string[] {\n const flagsRe = /^-[a-z0-9]{2,}$/i;\n\n const result = [];\n for (const argument of arguments_) {\n const isCoupled = flagsRe.test(argument);\n\n if (!isCoupled) {\n result.push(argument);\n continue;\n }\n\n const decoupledArray = argument\n .slice(1)\n .split(\"\")\n .map(c => \"-\" + c);\n\n result.push(...decoupledArray);\n }\n\n return result;\n}\n\n/**\n * Transforms an option name to a set of variants: `camelCase`, `PascalCase`, `snake_case`, `SCREAMING_SNAKE_CASE`.\n *\n * **Example** for `--input-dir`\n *\n * - CamelCase: `inputDir`\n * - PascalCase: `InputDir`\n * - Snake_case: `input_dir`\n * - SCREAMING_SNAKE_CASE: `INPUT_DIR`\n *\n * @param name - Should start with `'--'` or `'-'`\n */\nexport function optionArgumentToVariableNames(name: string): Set<string> {\n if (!name.startsWith(\"-\")) {\n throw new Error(`invalid option name: ${name}`);\n }\n\n name = name.startsWith(\"--\") ? name.slice(2) : name.slice(1); // remove prefix\n name = name.toLowerCase(); // lowercase\n\n const results = new Set<string>();\n\n // camelCase\n const camelCase = name.replace(/-(.)/g, m => m[1].toUpperCase());\n results.add(camelCase);\n\n // PascalCase (UpperCamelCase)\n results.add(camelCase.replace(/^(.)/, m => m.toUpperCase()));\n\n // snake_case\n const snake_case = name.replace(/-(.)/g, g => \"_\" + g[1]);\n results.add(snake_case);\n\n // SCREAMING_SNAKE_CASE\n results.add(snake_case.toUpperCase());\n\n return results;\n}\n\n/** - Check if an arg string is a short arg. E.g. `-i` -> `true` */\nexport function isFlagArgument(name: string): boolean {\n return /^-[A-Za-z]$/.test(name);\n}\n\n/** - Check if an arg string is a long arg. E.g. `--input-dir` -> `true` */\nfunction isLongArgument(name: string): boolean {\n return /^--[A-Za-z-]+[A-Za-z0-9]$/.test(name);\n}\n\n/** - Check if an arg string is an options arg. E.g. `--input-dir` -> `true` , `-i` -> `true` */\nexport function isOptionArgument(name: string | boolean): boolean {\n if (typeof name !== \"string\") {\n return false;\n }\n\n return isFlagArgument(name) || isLongArgument(name);\n}\n\n/**\n * Transform option name to no name.\n *\n * - `verbose` -> `noVerbose`\n * - `v` -> `noV`\n */\nexport function negateOption(name: string): string {\n return \"no\" + name.replace(/^[a-z]/, g => g.toUpperCase());\n}\n\n/** - Reverse of `transformArg`. E.g. `InputDir` -> `--input-dir` , `i` -> `-i` */\nexport function transformOptionToArgument(name: string): string {\n // single letter option name\n if (name.length === 1) {\n return `-${name.toLowerCase()}`;\n }\n\n // snake_case, SCREAMING_SNAKE_CASE\n if (/^[a-z_]+$/.test(name) || /^[A-Z_]+$/.test(name)) {\n name = name.replace(/_/g, \"-\");\n return `--${name.toLowerCase()}`;\n }\n\n // camelCase, PascalCase\n\n // add \"-\" before camel case letters except for the first letter\n name = name.replace(/[A-Z]/g, (match, index: number) => (index > 0 ? \"-\" + match : match));\n\n return `--${name.toLowerCase()}`;\n}\n"],"mappings":"AAUO,SAASA,yBACdC,EACAC,GAEA,YAAuB,IAAnBD,EACKC,EAGJA,EAAcC,YAIZD,EAAcC,YAAYC,KAAKC,GAEhCA,EAAEC,OAASL,GAKRA,GAAkBI,EAAEE,SAAWF,EAAEE,QAAQC,SAASP,SAX3D,CAaF,CAWO,SAASQ,WAAWC,EAAwBC,GACjD,MAAMC,EAAqBC,8BAA8BH,GACnDI,EAAYJ,EAAeK,WAAW,SA4B5C,OA1BeC,OAAOC,QAAQN,GAASP,KAAK,EAAEc,EAAYC,MACxD,GAAIP,EAAmBQ,IAAIF,GACzB,OAAO,EAGT,MAAMG,EAASF,EAAOG,eAAmD,YAAlCH,EAAOG,cAAcC,SAE5D,SAAIT,GAAaO,GAAUT,EAAmBQ,IAAII,aAAaN,QAI1DC,EAAOZ,YAIRY,EAAOZ,QAAQkB,KAAKC,GAAKd,EAAmBQ,IAAIM,QAIhDZ,GAAaO,GAAUF,EAAOZ,QAAQoB,IAAIC,GAASJ,aAAaI,IAAQH,KAAKC,GAAKd,EAAmBQ,IAAIM,OAQjH,CAGO,SAASG,cAAcC,GAC5B,MAAMC,EAAU,mBAEVC,EAAS,GACf,UAAWC,KAAYH,EAAY,CAGjC,IAFkBC,EAAQG,KAAKD,GAEf,CACdD,EAAOG,KAAKF,GACZ,QACF,CAEA,MAAMG,EAAiBH,EACpBI,MAAM,GACNC,MAAM,IACNX,IAAItB,GAAK,IAAMA,GAElB2B,EAAOG,QAAQC,EACjB,CAEA,OAAOJ,CACT,CAcO,SAASnB,8BAA8BP,GAC5C,IAAKA,EAAKS,WAAW,KACnB,MAAM,IAAIwB,MAAM,wBAAwBjC,KAI1CA,GADAA,EAAOA,EAAKS,WAAW,MAAQT,EAAK+B,MAAM,GAAK/B,EAAK+B,MAAM,IAC9CG,cAEZ,MAAMC,EAAU,IAAIC,IAGdC,EAAYrC,EAAKsC,QAAQ,QAASC,GAAKA,EAAE,GAAGC,eAClDL,EAAQM,IAAIJ,GAGZF,EAAQM,IAAIJ,EAAUC,QAAQ,OAAQC,GAAKA,EAAEC,gBAG7C,MAAME,EAAa1C,EAAKsC,QAAQ,QAASK,GAAK,IAAMA,EAAE,IAMtD,OALAR,EAAQM,IAAIC,GAGZP,EAAQM,IAAIC,EAAWF,eAEhBL,CACT,CAGO,SAASS,eAAe5C,GAC7B,MAAO,cAAc4B,KAAK5B,EAC5B,CAGA,SAAS6C,eAAe7C,GACtB,MAAO,4BAA4B4B,KAAK5B,EAC1C,CAGO,SAAS8C,iBAAiB9C,GAC/B,MAAoB,iBAATA,IAIJ4C,eAAe5C,IAAS6C,eAAe7C,GAChD,CAQO,SAASkB,aAAalB,GAC3B,MAAO,KAAOA,EAAKsC,QAAQ,SAAUK,GAAKA,EAAEH,cAC9C,CAGO,SAASO,0BAA0B/C,GAExC,OAAoB,IAAhBA,EAAKgD,OACA,IAAIhD,EAAKkC,gBAId,YAAYN,KAAK5B,IAAS,YAAY4B,KAAK5B,GAEtC,MADPA,EAAOA,EAAKsC,QAAQ,KAAM,MACTJ,gBAQZ,MAFPlC,EAAOA,EAAKsC,QAAQ,SAAU,CAACW,EAAOC,IAAmBA,EAAQ,EAAI,IAAMD,EAAQA,IAElEf,eACnB,Q","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/parse/parser-utilities.ts"],
4
+ "sourcesContent": ["import type { Cli, Option, Subcommand } from \"../types/definitions-types.ts\";\n\n/**\n * Retrieves a subcommand object from an array of subcommands by matching the provided subcommand name against the\n * subcommand's name or its aliases.\n *\n * @param subcommandName - The name or alias of the subcommand to search for.\n * @param subcommandArr - An array of `Subcommand` objects to search within.\n * @returns The matching `Subcommand` object if found; otherwise, `undefined`.\n */\nexport function findSubcommandDefinition(\n subcommandName: string | undefined,\n cliDefinition: Cli,\n): Subcommand | Cli | undefined {\n if (subcommandName === undefined) {\n return cliDefinition;\n }\n\n if (!cliDefinition.subcommands) {\n return;\n }\n\n return cliDefinition.subcommands.find(c => {\n // match for undefined too\n if (c.name === subcommandName) {\n return true;\n }\n\n // match for aliases\n return subcommandName && c.aliases && c.aliases.includes(subcommandName);\n });\n}\n\n/**\n * Finds and returns an `Option` object from the provided list that matches the given argument string.\n *\n * The function supports matching by option name, aliases, and their negated forms (e.g., `--no-` prefix).\n *\n * @param optionArgument - The argument string to match (e.g., `--foo`, `--no-bar`, `-f`).\n * @param options - An array of `Option` objects to search through.\n * @returns The matching `Option` object if found; otherwise, `undefined`.\n */\nexport function findOption(optionArgument: string, options: Record<string, Option>): [string, Option] | undefined {\n const validVariableNames = optionArgumentToVariableNames(optionArgument);\n const isNegated = optionArgument.startsWith(\"--no-\");\n\n const option = Object.entries(options).find(([optionName, option]) => {\n if (validVariableNames.has(optionName)) {\n return true;\n }\n\n if (isNegated && validVariableNames.has(negateOption(optionName))) {\n return true;\n }\n\n if (!option.aliases) {\n return false;\n }\n\n if (option.aliases.some(a => validVariableNames.has(a))) {\n return true;\n }\n\n if (isNegated && option.aliases.map(alias => negateOption(alias)).some(a => validVariableNames.has(a))) {\n return true;\n }\n\n return false;\n });\n\n return option;\n}\n\n/** - Decouple flags E.g. `-rf` -> `-r, -f` */\nexport function decoupleFlags(arguments_: string[]): string[] {\n const flagsRe = /^-[a-z0-9]{2,}$/i;\n\n const result = [];\n for (const argument of arguments_) {\n const isCoupled = flagsRe.test(argument);\n\n if (!isCoupled) {\n result.push(argument);\n continue;\n }\n\n const decoupledArray = argument\n .slice(1)\n .split(\"\")\n .map(c => \"-\" + c);\n\n result.push(...decoupledArray);\n }\n\n return result;\n}\n\n/**\n * Transforms an option name to a set of variants: `camelCase`, `PascalCase`, `snake_case`, `SCREAMING_SNAKE_CASE`.\n *\n * **Example** for `--input-dir`\n *\n * - CamelCase: `inputDir`\n * - PascalCase: `InputDir`\n * - Snake_case: `input_dir`\n * - SCREAMING_SNAKE_CASE: `INPUT_DIR`\n *\n * @param name - Should start with `'--'` or `'-'`\n */\nexport function optionArgumentToVariableNames(name: string): Set<string> {\n name = name.startsWith(\"--\") ? name.slice(2) : name.slice(1); // remove prefix\n name = name.toLowerCase(); // lowercase\n\n const results = new Set<string>();\n\n // camelCase\n const camelCase = name.replace(/-(.)/g, m => m[1].toUpperCase());\n results.add(camelCase);\n\n // PascalCase (UpperCamelCase)\n results.add(camelCase.replace(/^(.)/, m => m.toUpperCase()));\n\n // snake_case\n const snake_case = name.replace(/-(.)/g, g => \"_\" + g[1]);\n results.add(snake_case);\n\n // SCREAMING_SNAKE_CASE\n results.add(snake_case.toUpperCase());\n\n return results;\n}\n\n/** - Check if an arg string is a short arg. E.g. `-i` -> `true` */\nexport function isFlagArgument(name: string): boolean {\n return /^-[A-Za-z]$/.test(name);\n}\n\n/**\n * - Check if an arg string is a long arg.\n * - `--input-dir` -> `true`\n * - `-h` -> `false`\n * - `--db.https` -> `true`\n */\nfunction isLongArgument(name: string): boolean {\n return /^--.{2,}/.test(name);\n}\n\n/** - Check if an arg string is an options arg. E.g. `--input-dir` -> `true` , `-i` -> `true` */\nexport function isOptionArgument(name: string | boolean): boolean {\n if (typeof name !== \"string\") {\n return false;\n }\n\n return isFlagArgument(name) || isLongArgument(name);\n}\n\n/**\n * Transform option name to no name.\n *\n * - `verbose` -> `noVerbose`\n * - `v` -> `noV`\n */\nexport function negateOption(name: string): string {\n return \"no\" + name.replace(/^[a-z]/, g => g.toUpperCase());\n}\n\n/** - Reverse of `transformArg`. E.g. `InputDir` -> `--input-dir` , `i` -> `-i` */\nexport function transformOptionToArgument(name: string): string {\n // single letter option name\n if (name.length === 1) {\n return `-${name.toLowerCase()}`;\n }\n\n // snake_case, SCREAMING_SNAKE_CASE\n if (/^[a-z_]+$/.test(name) || /^[A-Z_]+$/.test(name)) {\n name = name.replace(/_/g, \"-\");\n return `--${name.toLowerCase()}`;\n }\n\n // camelCase, PascalCase\n\n // add \"-\" before camel case letters except for the first letter\n name = name.replace(/[A-Z]/g, (match, index: number) => (index > 0 ? \"-\" + match : match));\n\n return `--${name.toLowerCase()}`;\n}\n\n/**\n * Split an option with keys into name and a set of keys\n *\n * - `--foo` -> `[--foo, []]`\n * - `--foo.bar` -> `[--foo, [\"bar\"]]`\n * - `--foo.bar.baz` -> `[--foo, [\"bar\", \"baz\"]]`\n * - `--foo.bar.` -> `[--foo, Set(1) [\"bar\"]]`\n */\nexport function splitAndGetKeys(option: string): [string, string[]] {\n const parts = option.split(\".\");\n const optionName = parts[0];\n const keys = parts.slice(1).filter(Boolean);\n return [optionName, keys];\n}\n"],
5
+ "mappings": ";AAUO,SAAS,yBACd,gBACA,eAC8B;AAC9B,MAAI,mBAAmB,QAAW;AAChC,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,cAAc,aAAa;AAC9B;AAAA,EACF;AAEA,SAAO,cAAc,YAAY,KAAK,OAAK;AAEzC,QAAI,EAAE,SAAS,gBAAgB;AAC7B,aAAO;AAAA,IACT;AAGA,WAAO,kBAAkB,EAAE,WAAW,EAAE,QAAQ,SAAS,cAAc;AAAA,EACzE,CAAC;AACH;AAWO,SAAS,WAAW,gBAAwB,SAA+D;AAChH,QAAM,qBAAqB,8BAA8B,cAAc;AACvE,QAAM,YAAY,eAAe,WAAW,OAAO;AAEnD,QAAM,SAAS,OAAO,QAAQ,OAAO,EAAE,KAAK,CAAC,CAAC,YAAYA,OAAM,MAAM;AACpE,QAAI,mBAAmB,IAAI,UAAU,GAAG;AACtC,aAAO;AAAA,IACT;AAEA,QAAI,aAAa,mBAAmB,IAAI,aAAa,UAAU,CAAC,GAAG;AACjE,aAAO;AAAA,IACT;AAEA,QAAI,CAACA,QAAO,SAAS;AACnB,aAAO;AAAA,IACT;AAEA,QAAIA,QAAO,QAAQ,KAAK,OAAK,mBAAmB,IAAI,CAAC,CAAC,GAAG;AACvD,aAAO;AAAA,IACT;AAEA,QAAI,aAAaA,QAAO,QAAQ,IAAI,WAAS,aAAa,KAAK,CAAC,EAAE,KAAK,OAAK,mBAAmB,IAAI,CAAC,CAAC,GAAG;AACtG,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,CAAC;AAED,SAAO;AACT;AAGO,SAAS,cAAc,YAAgC;AAC5D,QAAM,UAAU;AAEhB,QAAM,SAAS,CAAC;AAChB,aAAW,YAAY,YAAY;AACjC,UAAM,YAAY,QAAQ,KAAK,QAAQ;AAEvC,QAAI,CAAC,WAAW;AACd,aAAO,KAAK,QAAQ;AACpB;AAAA,IACF;AAEA,UAAM,iBAAiB,SACpB,MAAM,CAAC,EACP,MAAM,EAAE,EACR,IAAI,OAAK,MAAM,CAAC;AAEnB,WAAO,KAAK,GAAG,cAAc;AAAA,EAC/B;AAEA,SAAO;AACT;AAcO,SAAS,8BAA8B,MAA2B;AACvE,SAAO,KAAK,WAAW,IAAI,IAAI,KAAK,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC;AAC3D,SAAO,KAAK,YAAY;AAExB,QAAM,UAAU,oBAAI,IAAY;AAGhC,QAAM,YAAY,KAAK,QAAQ,SAAS,OAAK,EAAE,CAAC,EAAE,YAAY,CAAC;AAC/D,UAAQ,IAAI,SAAS;AAGrB,UAAQ,IAAI,UAAU,QAAQ,QAAQ,OAAK,EAAE,YAAY,CAAC,CAAC;AAG3D,QAAM,aAAa,KAAK,QAAQ,SAAS,OAAK,MAAM,EAAE,CAAC,CAAC;AACxD,UAAQ,IAAI,UAAU;AAGtB,UAAQ,IAAI,WAAW,YAAY,CAAC;AAEpC,SAAO;AACT;AAGO,SAAS,eAAe,MAAuB;AACpD,SAAO,cAAc,KAAK,IAAI;AAChC;AAQA,SAAS,eAAe,MAAuB;AAC7C,SAAO,WAAW,KAAK,IAAI;AAC7B;AAGO,SAAS,iBAAiB,MAAiC;AAChE,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO,eAAe,IAAI,KAAK,eAAe,IAAI;AACpD;AAQO,SAAS,aAAa,MAAsB;AACjD,SAAO,OAAO,KAAK,QAAQ,UAAU,OAAK,EAAE,YAAY,CAAC;AAC3D;AAGO,SAAS,0BAA0B,MAAsB;AAE9D,MAAI,KAAK,WAAW,GAAG;AACrB,WAAO,IAAI,KAAK,YAAY,CAAC;AAAA,EAC/B;AAGA,MAAI,YAAY,KAAK,IAAI,KAAK,YAAY,KAAK,IAAI,GAAG;AACpD,WAAO,KAAK,QAAQ,MAAM,GAAG;AAC7B,WAAO,KAAK,KAAK,YAAY,CAAC;AAAA,EAChC;AAKA,SAAO,KAAK,QAAQ,UAAU,CAAC,OAAO,UAAmB,QAAQ,IAAI,MAAM,QAAQ,KAAM;AAEzF,SAAO,KAAK,KAAK,YAAY,CAAC;AAChC;AAUO,SAAS,gBAAgB,QAAoC;AAClE,QAAM,QAAQ,OAAO,MAAM,GAAG;AAC9B,QAAM,aAAa,MAAM,CAAC;AAC1B,QAAM,OAAO,MAAM,MAAM,CAAC,EAAE,OAAO,OAAO;AAC1C,SAAO,CAAC,YAAY,IAAI;AAC1B;",
6
+ "names": ["option"]
7
+ }
@@ -1,2 +1,57 @@
1
- import{validateCliDefinition}from"../definitions/validate-cli-definition.mjs";import{parseArgv}from"../utilities.mjs";import{buildCliContext}from"./context/cli-context-builder.mjs";import{findSubcommandDefinition}from"./parser-utilities.mjs";import{validate}from"./validation/validate-context.mjs";function safeParse(r,e){const t=safeParseCore(r,e);if(t.error)return{error:t.error};const{validateResult:o,subcommandObject:i}=t;if(i._onExecute)for(const r of i._onExecute)r(o);return{error:void 0,value:o}}async function safeParseAsync(r,e){const t=safeParseCore(r,e);if(t.error)return{error:t.error};const{validateResult:o,subcommandObject:i}=t;if(i._onExecute)for(const r of i._onExecute)await r(o);return{error:void 0,value:o}}function safeParseCore(r,e){const t="string"==typeof r?parseArgv(r):r;try{validateCliDefinition(e)}catch(r){return{error:r}}let o;try{o=buildCliContext(t,e)}catch(r){return{error:r}}const i=findSubcommandDefinition(o.subcommand,e);if(!i){return{error:new Error(`Subcommand "${o.subcommand}" does not exist`)}}let n;try{n=validate(o,i)}catch(r){return{error:r}}return{error:void 0,validateResult:n,subcommandObject:i}}export{safeParse,safeParseAsync};
2
- //# sourceMappingURL=safe-parse.mjs.map
1
+ // src/parse/safe-parse.ts
2
+ import { validateCliDefinition } from "../definitions/validate-cli-definition.mjs";
3
+ import { parseArgv } from "../utilities/parse-argv.mjs";
4
+ import { buildCliContext } from "./context/cli-context-builder.mjs";
5
+ import { findSubcommandDefinition } from "./parser-utilities.mjs";
6
+ import { validate } from "./validation/validate-context.mjs";
7
+ function safeParse(stringOrArgv, cliDefinition) {
8
+ const core = safeParseCore(stringOrArgv, cliDefinition);
9
+ if (core.error) return { error: core.error };
10
+ const { validateResult, subcommandObject } = core;
11
+ if (subcommandObject._onExecute) {
12
+ for (const handler of subcommandObject._onExecute) {
13
+ void handler(validateResult);
14
+ }
15
+ }
16
+ return { error: void 0, value: validateResult };
17
+ }
18
+ async function safeParseAsync(stringOrArgv, cliDefinition) {
19
+ const core = safeParseCore(stringOrArgv, cliDefinition);
20
+ if (core.error) return { error: core.error };
21
+ const { validateResult, subcommandObject } = core;
22
+ if (subcommandObject._onExecute) {
23
+ await Promise.all(subcommandObject._onExecute.map(async (handler) => await handler(validateResult)));
24
+ }
25
+ return { error: void 0, value: validateResult };
26
+ }
27
+ function safeParseCore(stringOrArgv, cliDefinition) {
28
+ const argv = typeof stringOrArgv === "string" ? parseArgv(stringOrArgv) : stringOrArgv;
29
+ try {
30
+ validateCliDefinition(cliDefinition);
31
+ } catch (error) {
32
+ return { error };
33
+ }
34
+ let cliContext;
35
+ try {
36
+ cliContext = buildCliContext(argv, cliDefinition);
37
+ } catch (error) {
38
+ return { error };
39
+ }
40
+ const subcommandObject = findSubcommandDefinition(cliContext.subcommand, cliDefinition);
41
+ if (!subcommandObject) {
42
+ const error = new Error(`Subcommand "${cliContext.subcommand}" does not exist`);
43
+ return { error };
44
+ }
45
+ let validateResult;
46
+ try {
47
+ validateResult = validate(cliContext, subcommandObject);
48
+ } catch (error) {
49
+ return { error };
50
+ }
51
+ return { error: void 0, validateResult, subcommandObject };
52
+ }
53
+ export {
54
+ safeParse,
55
+ safeParseAsync
56
+ };
57
+ //# sourceMappingURL=safe-parse.mjs.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["validateCliDefinition","parseArgv","buildCliContext","findSubcommandDefinition","validate","safeParse","stringOrArgv","cliDefinition","core","safeParseCore","error","validateResult","subcommandObject","_onExecute","handler","value","async","safeParseAsync","argv","cliContext","subcommand","Error"],"sources":["../../../src/parse/safe-parse.ts"],"sourcesContent":["import { validateCliDefinition } from \"../definitions/validate-cli-definition.ts\";\nimport { parseArgv } from \"../utilities.ts\";\nimport { buildCliContext } from \"./context/cli-context-builder.ts\";\nimport { findSubcommandDefinition } from \"./parser-utilities.ts\";\nimport { validate } from \"./validation/validate-context.ts\";\n\nimport type { Cli } from \"../types/definitions-types.ts\";\nimport type { CliParseResultWide } from \"../types/types.ts\";\n\nexport function safeParse(stringOrArgv: string | string[], cliDefinition: Cli): CliParseResultWide {\n const core = safeParseCore(stringOrArgv, cliDefinition);\n if (core.error) return { error: core.error };\n\n const { validateResult, subcommandObject } = core;\n\n // Fire action (throw errors caused by the usage of the action hook)\n if (subcommandObject._onExecute) {\n for (const handler of subcommandObject._onExecute) {\n handler(validateResult);\n }\n }\n\n return { error: undefined, value: validateResult };\n}\n\nexport async function safeParseAsync(stringOrArgv: string | string[], cliDefinition: Cli): Promise<CliParseResultWide> {\n const core = safeParseCore(stringOrArgv, cliDefinition);\n if (core.error) return { error: core.error };\n\n const { validateResult, subcommandObject } = core;\n\n // Fire action (throw errors caused by the usage of the action hook)\n if (subcommandObject._onExecute) {\n for (const handler of subcommandObject._onExecute) {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n await handler(validateResult);\n }\n }\n\n return { error: undefined, value: validateResult };\n}\n\nfunction safeParseCore(stringOrArgv: string | string[], cliDefinition: Cli) {\n const argv = typeof stringOrArgv === \"string\" ? parseArgv(stringOrArgv) : stringOrArgv;\n\n // validate cli definition\n try {\n validateCliDefinition(cliDefinition);\n } catch (error) {\n return { error: error as Error };\n }\n\n // Parse\n let cliContext;\n try {\n cliContext = buildCliContext(argv, cliDefinition);\n } catch (error) {\n return { error: error as Error };\n }\n\n const subcommandObject = findSubcommandDefinition(cliContext.subcommand, cliDefinition);\n if (!subcommandObject) {\n const error = new Error(`Subcommand \"${cliContext.subcommand}\" does not exist`);\n return { error };\n }\n\n // Validate context\n let validateResult;\n try {\n validateResult = validate(cliContext, subcommandObject);\n } catch (error) {\n return { error: error as Error };\n }\n\n return { error: undefined, validateResult, subcommandObject };\n}\n"],"mappings":"OAASA,0BAA6B,oDAC7BC,cAAiB,0BACjBC,oBAAuB,2CACvBC,6BAAgC,gCAChCC,aAAgB,oCAKlB,SAASC,UAAUC,EAAiCC,GACzD,MAAMC,EAAOC,cAAcH,EAAcC,GACzC,GAAIC,EAAKE,MAAO,MAAO,CAAEA,MAAOF,EAAKE,OAErC,MAAMC,eAAEA,EAAAC,iBAAgBA,GAAqBJ,EAG7C,GAAII,EAAiBC,WACnB,UAAWC,KAAWF,EAAiBC,WACrCC,EAAQH,GAIZ,MAAO,CAAED,WAAO,EAAWK,MAAOJ,EACpC,CAEAK,eAAsBC,eAAeX,EAAiCC,GACpE,MAAMC,EAAOC,cAAcH,EAAcC,GACzC,GAAIC,EAAKE,MAAO,MAAO,CAAEA,MAAOF,EAAKE,OAErC,MAAMC,eAAEA,EAAAC,iBAAgBA,GAAqBJ,EAG7C,GAAII,EAAiBC,WACnB,UAAWC,KAAWF,EAAiBC,iBAE/BC,EAAQH,GAIlB,MAAO,CAAED,WAAO,EAAWK,MAAOJ,EACpC,CAEA,SAASF,cAAcH,EAAiCC,GACtD,MAAMW,EAA+B,iBAAjBZ,EAA4BL,UAAUK,GAAgBA,EAG1E,IACEN,sBAAsBO,EACxB,OAASG,GACP,MAAO,CAAEA,QACX,CAGA,IAAIS,EACJ,IACEA,EAAajB,gBAAgBgB,EAAMX,EACrC,OAASG,GACP,MAAO,CAAEA,QACX,CAEA,MAAME,EAAmBT,yBAAyBgB,EAAWC,WAAYb,GACzE,IAAKK,EAAkB,CAErB,MAAO,CAAEF,MADK,IAAIW,MAAM,eAAeF,EAAWC,8BAEpD,CAGA,IAAIT,EACJ,IACEA,EAAiBP,SAASe,EAAYP,EACxC,OAASF,GACP,MAAO,CAAEA,QACX,CAEA,MAAO,CAAEA,WAAO,EAAWC,iBAAgBC,mBAC7C,Q","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/parse/safe-parse.ts"],
4
+ "sourcesContent": ["import { validateCliDefinition } from \"../definitions/validate-cli-definition.ts\";\nimport { parseArgv } from \"../utilities/parse-argv.ts\";\nimport { buildCliContext } from \"./context/cli-context-builder.ts\";\nimport { findSubcommandDefinition } from \"./parser-utilities.ts\";\nimport { validate } from \"./validation/validate-context.ts\";\n\nimport type { Cli } from \"../types/definitions-types.ts\";\nimport type { CliParseResultWide } from \"../types/types.ts\";\n\nexport function safeParse(stringOrArgv: string | string[], cliDefinition: Cli): CliParseResultWide {\n const core = safeParseCore(stringOrArgv, cliDefinition);\n if (core.error) return { error: core.error };\n\n const { validateResult, subcommandObject } = core;\n\n // Fire action (throw errors caused by the usage of the action hook)\n if (subcommandObject._onExecute) {\n for (const handler of subcommandObject._onExecute) {\n void handler(validateResult);\n }\n }\n\n return { error: undefined, value: validateResult };\n}\n\nexport async function safeParseAsync(stringOrArgv: string | string[], cliDefinition: Cli): Promise<CliParseResultWide> {\n const core = safeParseCore(stringOrArgv, cliDefinition);\n if (core.error) return { error: core.error };\n\n const { validateResult, subcommandObject } = core;\n\n // Fire action (throw errors caused by the usage of the action hook)\n if (subcommandObject._onExecute) {\n await Promise.all(subcommandObject._onExecute.map(async handler => await handler(validateResult)));\n }\n\n return { error: undefined, value: validateResult };\n}\n\nfunction safeParseCore(stringOrArgv: string | string[], cliDefinition: Cli) {\n const argv = typeof stringOrArgv === \"string\" ? parseArgv(stringOrArgv) : stringOrArgv;\n\n // validate cli definition\n try {\n validateCliDefinition(cliDefinition);\n } catch (error) {\n return { error: error as Error };\n }\n\n // Parse\n let cliContext;\n try {\n cliContext = buildCliContext(argv, cliDefinition);\n } catch (error) {\n return { error: error as Error };\n }\n\n const subcommandObject = findSubcommandDefinition(cliContext.subcommand, cliDefinition);\n if (!subcommandObject) {\n const error = new Error(`Subcommand \"${cliContext.subcommand}\" does not exist`);\n return { error };\n }\n\n // Validate context\n let validateResult;\n try {\n validateResult = validate(cliContext, subcommandObject);\n } catch (error) {\n return { error: error as Error };\n }\n\n return { error: undefined, validateResult, subcommandObject };\n}\n"],
5
+ "mappings": ";AAAA,SAAS,6BAA6B;AACtC,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AACzC,SAAS,gBAAgB;AAKlB,SAAS,UAAU,cAAiC,eAAwC;AACjG,QAAM,OAAO,cAAc,cAAc,aAAa;AACtD,MAAI,KAAK,MAAO,QAAO,EAAE,OAAO,KAAK,MAAM;AAE3C,QAAM,EAAE,gBAAgB,iBAAiB,IAAI;AAG7C,MAAI,iBAAiB,YAAY;AAC/B,eAAW,WAAW,iBAAiB,YAAY;AACjD,WAAK,QAAQ,cAAc;AAAA,IAC7B;AAAA,EACF;AAEA,SAAO,EAAE,OAAO,QAAW,OAAO,eAAe;AACnD;AAEA,eAAsB,eAAe,cAAiC,eAAiD;AACrH,QAAM,OAAO,cAAc,cAAc,aAAa;AACtD,MAAI,KAAK,MAAO,QAAO,EAAE,OAAO,KAAK,MAAM;AAE3C,QAAM,EAAE,gBAAgB,iBAAiB,IAAI;AAG7C,MAAI,iBAAiB,YAAY;AAC/B,UAAM,QAAQ,IAAI,iBAAiB,WAAW,IAAI,OAAM,YAAW,MAAM,QAAQ,cAAc,CAAC,CAAC;AAAA,EACnG;AAEA,SAAO,EAAE,OAAO,QAAW,OAAO,eAAe;AACnD;AAEA,SAAS,cAAc,cAAiC,eAAoB;AAC1E,QAAM,OAAO,OAAO,iBAAiB,WAAW,UAAU,YAAY,IAAI;AAG1E,MAAI;AACF,0BAAsB,aAAa;AAAA,EACrC,SAAS,OAAO;AACd,WAAO,EAAE,MAAsB;AAAA,EACjC;AAGA,MAAI;AACJ,MAAI;AACF,iBAAa,gBAAgB,MAAM,aAAa;AAAA,EAClD,SAAS,OAAO;AACd,WAAO,EAAE,MAAsB;AAAA,EACjC;AAEA,QAAM,mBAAmB,yBAAyB,WAAW,YAAY,aAAa;AACtF,MAAI,CAAC,kBAAkB;AACrB,UAAM,QAAQ,IAAI,MAAM,eAAe,WAAW,UAAU,kBAAkB;AAC9E,WAAO,EAAE,MAAM;AAAA,EACjB;AAGA,MAAI;AACJ,MAAI;AACF,qBAAiB,SAAS,YAAY,gBAAgB;AAAA,EACxD,SAAS,OAAO;AACd,WAAO,EAAE,MAAsB;AAAA,EACjC;AAEA,SAAO,EAAE,OAAO,QAAW,gBAAgB,iBAAiB;AAC9D;",
6
+ "names": []
7
+ }
@@ -1,2 +1,17 @@
1
- import{validateArguments}from"./validators/arguments.mjs";import{validateOptions}from"./validators/options.mjs";function validate(t,o){const i={subcommand:t.subcommand,positionals:t.positionals,context:t};return validateOptions({commandDefinition:o,context:t,output:i}),validateArguments({commandDefinition:o,context:t,output:i}),i}export{validate};
2
- //# sourceMappingURL=validate-context.mjs.map
1
+ // src/parse/validation/validate-context.ts
2
+ import { validateArguments } from "./validators/arguments.mjs";
3
+ import { validateOptions } from "./validators/options.mjs";
4
+ function validate(context, commandDefinition) {
5
+ const output = {
6
+ subcommand: context.subcommand,
7
+ positionals: context.positionals,
8
+ context
9
+ };
10
+ validateOptions({ commandDefinition, context, output });
11
+ validateArguments({ commandDefinition, context, output });
12
+ return output;
13
+ }
14
+ export {
15
+ validate
16
+ };
17
+ //# sourceMappingURL=validate-context.mjs.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["validateArguments","validateOptions","validate","context","commandDefinition","output","subcommand","positionals"],"sources":["../../../../src/parse/validation/validate-context.ts"],"sourcesContent":["import { validateArguments } from \"./validators/arguments.ts\";\nimport { validateOptions } from \"./validators/options.ts\";\n\nimport type { ContextWide } from \"../../types/context-types.ts\";\nimport type { Cli, Subcommand } from \"../../types/definitions-types.ts\";\nimport type { OutputTypeWide } from \"../../types/io-types.ts\";\n\n/** @throws {Error} */\nexport function validate(context: ContextWide, commandDefinition: Subcommand | Cli) {\n const output: OutputTypeWide = {\n subcommand: context.subcommand,\n positionals: context.positionals,\n context: context,\n };\n\n // validate options\n validateOptions({ commandDefinition, context, output });\n\n // validate arguments\n validateArguments({ commandDefinition, context, output });\n\n return output;\n}\n"],"mappings":"OAASA,sBAAyB,oCACzBC,oBAAuB,2BAOzB,SAASC,SAASC,EAAsBC,GAC7C,MAAMC,EAAyB,CAC7BC,WAAYH,EAAQG,WACpBC,YAAaJ,EAAQI,YACrBJ,WASF,OALAF,gBAAgB,CAAEG,oBAAmBD,UAASE,WAG9CL,kBAAkB,CAAEI,oBAAmBD,UAASE,WAEzCA,CACT,Q","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/parse/validation/validate-context.ts"],
4
+ "sourcesContent": ["import { validateArguments } from \"./validators/arguments.ts\";\nimport { validateOptions } from \"./validators/options.ts\";\n\nimport type { ContextWide } from \"../../types/context-types.ts\";\nimport type { Cli, Subcommand } from \"../../types/definitions-types.ts\";\nimport type { OutputTypeWide } from \"../../types/io-types.ts\";\n\n/** @throws {CliError} */\nexport function validate(context: ContextWide, commandDefinition: Subcommand | Cli) {\n const output: OutputTypeWide = {\n subcommand: context.subcommand,\n positionals: context.positionals,\n context: context,\n };\n\n // validate options\n validateOptions({ commandDefinition, context, output });\n\n // validate arguments\n validateArguments({ commandDefinition, context, output });\n\n return output;\n}\n"],
5
+ "mappings": ";AAAA,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAOzB,SAAS,SAAS,SAAsB,mBAAqC;AAClF,QAAM,SAAyB;AAAA,IAC7B,YAAY,QAAQ;AAAA,IACpB,aAAa,QAAQ;AAAA,IACrB;AAAA,EACF;AAGA,kBAAgB,EAAE,mBAAmB,SAAS,OAAO,CAAC;AAGtD,oBAAkB,EAAE,mBAAmB,SAAS,OAAO,CAAC;AAExD,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,2 +1,67 @@
1
- import{validateSync}from"../../../utilities.mjs";import{validateConflictWith}from"./conflict.mjs";import{validateExclusive}from"./exclusive.mjs";import{validateRequires}from"./requires.mjs";function validateArguments({commandDefinition:e,context:t,output:r}){if(!t.arguments)return;r.arguments??(r.arguments={});const n=e.arguments;if(!n)throw new Error(`Subcommand "${t.subcommand}" does not have arguments`);for(const[r,o]of Object.entries(n))validateRequires({name:r,commandDefinition:e,optionOrArgument:o,context:t,type:"option"}),validateExclusive({name:r,optionOrArgument:o,context:t,type:"option"}),validateConflictWith({name:r,optionOrArgument:o,context:t,type:"option"});const o=Object.entries(t.arguments);for(const[e,{passedValue:i,stringValue:a,source:m,schema:s}]of o){const o="programmatic"===m,u=n[e];if(!u)throw new Error(`Subcommand "${t.subcommand}" does not have the argument "${e}"`);if(!u._preparedType)throw new Error(`internal error: missing prepared type for the argument "${e}"`);const c=o?validateSync(s,i):u._preparedType.validate(a);if(c.issues)throw new Error(`The argument ${e} argument ${o?"":`"${a}"`} is invalid: ${c.issues.map(e=>e.message).join(", ")}`);r.arguments[e]=c.value}}export{validateArguments};
2
- //# sourceMappingURL=arguments.mjs.map
1
+ // src/parse/validation/validators/arguments.ts
2
+ import { CliError } from "../../../cli-error/cli-error.mjs";
3
+ import { ErrorCause } from "../../../cli-error/error-cause.mjs";
4
+ import { InternalErrorCode } from "../../../cli-error/error-code/internal-error-code.mjs";
5
+ import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.mjs";
6
+ import { validateSync } from "../../../utilities/schema-utilities.mjs";
7
+ import { validateConflictWith } from "./conflict.mjs";
8
+ import { validateExclusive } from "./exclusive.mjs";
9
+ import { validateRequires } from "./requires.mjs";
10
+ function validateArguments({ commandDefinition, context, output }) {
11
+ if (!context.arguments) return;
12
+ output.arguments ??= {};
13
+ const commandKind = "cliName" in commandDefinition ? "command" : "subcommand";
14
+ const commandName = "cliName" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;
15
+ const argumentsDefinition = commandDefinition.arguments;
16
+ if (!argumentsDefinition) {
17
+ throw new CliError({
18
+ cause: ErrorCause.Validation,
19
+ code: ValidationErrorCode.NoArgumentsToValidate,
20
+ context: { commandKind, commandName }
21
+ });
22
+ }
23
+ for (const [argumentName, argument] of Object.entries(argumentsDefinition)) {
24
+ validateRequires({ name: argumentName, commandDefinition, optionOrArgument: argument, context, kind: "option" });
25
+ validateExclusive({ name: argumentName, optionOrArgument: argument, context, kind: "option" });
26
+ validateConflictWith({ name: argumentName, optionOrArgument: argument, context, kind: "option" });
27
+ }
28
+ const argumentContextEntries = Object.entries(context.arguments);
29
+ for (const [argumentName, { passedValue, stringValue, source, schema }] of argumentContextEntries) {
30
+ const isProgrammatic = source === "programmatic";
31
+ const argument = argumentsDefinition[argumentName];
32
+ if (!argument) {
33
+ throw new CliError({
34
+ cause: ErrorCause.Validation,
35
+ code: ValidationErrorCode.UnknownArgumentValidation,
36
+ context: { commandKind, commandName, argumentName }
37
+ });
38
+ }
39
+ if (!argument._preparedType) {
40
+ throw new CliError({
41
+ cause: ErrorCause.Internal,
42
+ code: InternalErrorCode.MissingPreparedTypes,
43
+ context: { commandKind, commandName, kind: "argument", name: argumentName }
44
+ });
45
+ }
46
+ const safeParseResult = isProgrammatic ? validateSync(schema, passedValue) : argument._preparedType.validate(stringValue);
47
+ if (safeParseResult.issues) {
48
+ throw new CliError({
49
+ cause: ErrorCause.Validation,
50
+ code: ValidationErrorCode.SchemaValidationFailed,
51
+ context: {
52
+ commandKind,
53
+ commandName,
54
+ kind: "option",
55
+ name: argumentName,
56
+ inputValue: isProgrammatic ? passedValue : stringValue,
57
+ issues: safeParseResult.issues
58
+ }
59
+ });
60
+ }
61
+ output.arguments[argumentName] = safeParseResult.value;
62
+ }
63
+ }
64
+ export {
65
+ validateArguments
66
+ };
67
+ //# sourceMappingURL=arguments.mjs.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["validateSync","validateConflictWith","validateExclusive","validateRequires","validateArguments","commandDefinition","context","output","arguments","argumentsDefinition","Error","subcommand","argumentName","argument","Object","entries","name","optionOrArgument","type","argumentContextEntries","passedValue","stringValue","source","schema","isProgrammatic","_preparedType","safeParseResult","validate","issues","map","issue","message","join","value"],"sources":["../../../../../src/parse/validation/validators/arguments.ts"],"sourcesContent":["import { validateSync } from \"../../../utilities.ts\";\nimport { validateConflictWith } from \"./conflict.ts\";\nimport { validateExclusive } from \"./exclusive.ts\";\nimport { validateRequires } from \"./requires.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Cli, Subcommand } from \"../../../types/definitions-types.ts\";\nimport type { OutputTypeWide } from \"../../../types/io-types.ts\";\n\ninterface ValidateArgument {\n commandDefinition: Subcommand | Cli;\n context: ContextWide;\n output: OutputTypeWide;\n}\n\n/** @throws {Error} */\nexport function validateArguments({ commandDefinition, context, output }: ValidateArgument) {\n if (!context.arguments) return;\n\n output.arguments ??= {};\n\n const argumentsDefinition = commandDefinition.arguments;\n if (!argumentsDefinition) {\n throw new Error(`Subcommand \"${context.subcommand}\" does not have arguments`);\n }\n\n for (const [argumentName, argument] of Object.entries(argumentsDefinition)) {\n validateRequires({ name: argumentName, commandDefinition, optionOrArgument: argument, context, type: \"option\" });\n validateExclusive({ name: argumentName, optionOrArgument: argument, context, type: \"option\" });\n validateConflictWith({ name: argumentName, optionOrArgument: argument, context, type: \"option\" });\n }\n\n const argumentContextEntries = Object.entries(context.arguments);\n\n for (const [name, { passedValue, stringValue, source, schema }] of argumentContextEntries) {\n const isProgrammatic = source === \"programmatic\";\n\n const argument = argumentsDefinition[name];\n if (!argument) {\n throw new Error(`Subcommand \"${context.subcommand}\" does not have the argument \"${name}\"`);\n }\n\n if (!argument._preparedType) {\n throw new Error(`internal error: missing prepared type for the argument \"${name}\"`);\n }\n\n const safeParseResult = isProgrammatic\n ? validateSync(schema, passedValue)\n : argument._preparedType.validate(stringValue);\n\n if (safeParseResult.issues) {\n throw new Error(\n `The argument ${name} argument ${isProgrammatic ? \"\" : `\"${stringValue}\"`} is invalid: ${safeParseResult.issues.map(issue => issue.message).join(\", \")}`,\n );\n }\n\n output.arguments[name] = safeParseResult.value;\n }\n}\n"],"mappings":"OAASA,iBAAoB,gCACpBC,yBAA4B,wBAC5BC,sBAAyB,yBACzBC,qBAAwB,iBAa1B,SAASC,mBAAkBC,kBAAEA,EAAAC,QAAmBA,EAAAC,OAASA,IAC9D,IAAKD,EAAQE,UAAW,OAExBD,EAAOC,YAAPD,EAAOC,UAAc,CAAC,GAEtB,MAAMC,EAAsBJ,EAAkBG,UAC9C,IAAKC,EACH,MAAM,IAAIC,MAAM,eAAeJ,EAAQK,uCAGzC,UAAYC,EAAcC,KAAaC,OAAOC,QAAQN,GACpDN,iBAAiB,CAAEa,KAAMJ,EAAcP,oBAAmBY,iBAAkBJ,EAAUP,UAASY,KAAM,WACrGhB,kBAAkB,CAAEc,KAAMJ,EAAcK,iBAAkBJ,EAAUP,UAASY,KAAM,WACnFjB,qBAAqB,CAAEe,KAAMJ,EAAcK,iBAAkBJ,EAAUP,UAASY,KAAM,WAGxF,MAAMC,EAAyBL,OAAOC,QAAQT,EAAQE,WAEtD,UAAYQ,GAAMI,YAAEA,EAAAC,YAAaA,EAAAC,OAAaA,EAAAC,OAAQA,MAAaJ,EAAwB,CACzF,MAAMK,EAA4B,iBAAXF,EAEjBT,EAAWJ,EAAoBO,GACrC,IAAKH,EACH,MAAM,IAAIH,MAAM,eAAeJ,EAAQK,2CAA2CK,MAGpF,IAAKH,EAASY,cACZ,MAAM,IAAIf,MAAM,2DAA2DM,MAG7E,MAAMU,EAAkBF,EACpBxB,aAAauB,EAAQH,GACrBP,EAASY,cAAcE,SAASN,GAEpC,GAAIK,EAAgBE,OAClB,MAAM,IAAIlB,MACR,gBAAgBM,cAAiBQ,EAAiB,GAAK,IAAIH,oBAA8BK,EAAgBE,OAAOC,IAAIC,GAASA,EAAMC,SAASC,KAAK,SAIrJzB,EAAOC,UAAUQ,GAAQU,EAAgBO,KAC3C,CACF,Q","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/parse/validation/validators/arguments.ts"],
4
+ "sourcesContent": ["import { CliError } from \"../../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../../cli-error/error-cause.ts\";\nimport { InternalErrorCode } from \"../../../cli-error/error-code/internal-error-code.ts\";\nimport { ValidationErrorCode } from \"../../../cli-error/error-code/validation-error-code.ts\";\nimport { validateSync } from \"../../../utilities/schema-utilities.ts\";\nimport { validateConflictWith } from \"./conflict.ts\";\nimport { validateExclusive } from \"./exclusive.ts\";\nimport { validateRequires } from \"./requires.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Cli, Subcommand } from \"../../../types/definitions-types.ts\";\nimport type { OutputTypeWide } from \"../../../types/io-types.ts\";\n\ninterface ValidateArgument {\n commandDefinition: Subcommand | Cli;\n context: ContextWide;\n output: OutputTypeWide;\n}\n\n/** @throws {CliError} */\nexport function validateArguments({ commandDefinition, context, output }: ValidateArgument) {\n if (!context.arguments) return;\n\n output.arguments ??= {};\n\n const commandKind = \"cliName\" in commandDefinition ? \"command\" : \"subcommand\";\n const commandName = \"cliName\" in commandDefinition ? commandDefinition.cliName : commandDefinition.name;\n\n const argumentsDefinition = commandDefinition.arguments;\n if (!argumentsDefinition) {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.NoArgumentsToValidate,\n context: { commandKind, commandName },\n });\n }\n\n for (const [argumentName, argument] of Object.entries(argumentsDefinition)) {\n validateRequires({ name: argumentName, commandDefinition, optionOrArgument: argument, context, kind: \"option\" });\n validateExclusive({ name: argumentName, optionOrArgument: argument, context, kind: \"option\" });\n validateConflictWith({ name: argumentName, optionOrArgument: argument, context, kind: \"option\" });\n }\n\n const argumentContextEntries = Object.entries(context.arguments);\n\n for (const [argumentName, { passedValue, stringValue, source, schema }] of argumentContextEntries) {\n const isProgrammatic = source === \"programmatic\";\n\n const argument = argumentsDefinition[argumentName];\n if (!argument) {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.UnknownArgumentValidation,\n context: { commandKind, commandName, argumentName },\n });\n }\n\n if (!argument._preparedType) {\n throw new CliError({\n cause: ErrorCause.Internal,\n code: InternalErrorCode.MissingPreparedTypes,\n context: { commandKind, commandName, kind: \"argument\", name: argumentName },\n });\n }\n\n const safeParseResult = isProgrammatic\n ? validateSync(schema, passedValue)\n : argument._preparedType.validate(stringValue);\n\n if (safeParseResult.issues) {\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.SchemaValidationFailed,\n context: {\n commandKind,\n commandName,\n kind: \"option\",\n name: argumentName,\n inputValue: isProgrammatic ? passedValue : stringValue,\n issues: safeParseResult.issues,\n },\n });\n }\n\n output.arguments[argumentName] = safeParseResult.value;\n }\n}\n"],
5
+ "mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AACpC,SAAS,oBAAoB;AAC7B,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAa1B,SAAS,kBAAkB,EAAE,mBAAmB,SAAS,OAAO,GAAqB;AAC1F,MAAI,CAAC,QAAQ,UAAW;AAExB,SAAO,cAAc,CAAC;AAEtB,QAAM,cAAc,aAAa,oBAAoB,YAAY;AACjE,QAAM,cAAc,aAAa,oBAAoB,kBAAkB,UAAU,kBAAkB;AAEnG,QAAM,sBAAsB,kBAAkB;AAC9C,MAAI,CAAC,qBAAqB;AACxB,UAAM,IAAI,SAAS;AAAA,MACjB,OAAO,WAAW;AAAA,MAClB,MAAM,oBAAoB;AAAA,MAC1B,SAAS,EAAE,aAAa,YAAY;AAAA,IACtC,CAAC;AAAA,EACH;AAEA,aAAW,CAAC,cAAc,QAAQ,KAAK,OAAO,QAAQ,mBAAmB,GAAG;AAC1E,qBAAiB,EAAE,MAAM,cAAc,mBAAmB,kBAAkB,UAAU,SAAS,MAAM,SAAS,CAAC;AAC/G,sBAAkB,EAAE,MAAM,cAAc,kBAAkB,UAAU,SAAS,MAAM,SAAS,CAAC;AAC7F,yBAAqB,EAAE,MAAM,cAAc,kBAAkB,UAAU,SAAS,MAAM,SAAS,CAAC;AAAA,EAClG;AAEA,QAAM,yBAAyB,OAAO,QAAQ,QAAQ,SAAS;AAE/D,aAAW,CAAC,cAAc,EAAE,aAAa,aAAa,QAAQ,OAAO,CAAC,KAAK,wBAAwB;AACjG,UAAM,iBAAiB,WAAW;AAElC,UAAM,WAAW,oBAAoB,YAAY;AACjD,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS,EAAE,aAAa,aAAa,aAAa;AAAA,MACpD,CAAC;AAAA,IACH;AAEA,QAAI,CAAC,SAAS,eAAe;AAC3B,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,kBAAkB;AAAA,QACxB,SAAS,EAAE,aAAa,aAAa,MAAM,YAAY,MAAM,aAAa;AAAA,MAC5E,CAAC;AAAA,IACH;AAEA,UAAM,kBAAkB,iBACpB,aAAa,QAAQ,WAAW,IAChC,SAAS,cAAc,SAAS,WAAW;AAE/C,QAAI,gBAAgB,QAAQ;AAC1B,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS;AAAA,UACP;AAAA,UACA;AAAA,UACA,MAAM;AAAA,UACN,MAAM;AAAA,UACN,YAAY,iBAAiB,cAAc;AAAA,UAC3C,QAAQ,gBAAgB;AAAA,QAC1B;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO,UAAU,YAAY,IAAI,gBAAgB;AAAA,EACnD;AACF;",
6
+ "names": []
7
+ }
@@ -1,2 +1,38 @@
1
- import{isOptionOrArgumentExplicitlyPassed}from"./explicitly-passed.mjs";function validateConflictWith({name:t,optionOrArgument:e,context:n,type:i}){const o=e.conflictWith;if(!o||0===o.length)return;if(!isOptionOrArgumentExplicitlyPassed(t,n))return;const s=[],r=[];if(n.options)for(const[e,i]of Object.entries(n.options))e!==t&&o.includes(e)&&"default"!==i.source&&s.push(e);if(n.arguments)for(const[e,i]of Object.entries(n.arguments))e!==t&&o.includes(e)&&"default"!==i.source&&r.push(e);if(0===s.length&&0===r.length)return;const c=[];if(s.length>0){const t=s.map(t=>`"${t}"`).join(", "),e=s.length>1?"s":"";c.push(`option${e} ${t}`)}if(r.length>0){const t=r.map(t=>`"${t}"`).join(", "),e=r.length>1?"s":"";c.push(`argument${e} ${t}`)}const l=c.join(" and ");throw new Error(`${i} "${t}" cannot be used with the ${l} because they are mutually exclusive.`)}export{validateConflictWith};
2
- //# sourceMappingURL=conflict.mjs.map
1
+ // src/parse/validation/validators/conflict.ts
2
+ import { CliError } from "../../../cli-error/cli-error.mjs";
3
+ import { ErrorCause } from "../../../cli-error/error-cause.mjs";
4
+ import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.mjs";
5
+ import { isOptionOrArgumentExplicitlyPassed } from "./explicitly-passed.mjs";
6
+ function validateConflictWith({ name, optionOrArgument, context, kind }) {
7
+ const conflictWith = optionOrArgument.conflictWith;
8
+ if (!conflictWith || conflictWith.length === 0) return;
9
+ if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;
10
+ const conflictedOptions = [];
11
+ const conflictedArguments = [];
12
+ if (context.options) {
13
+ for (const [optionName, optionContext] of Object.entries(context.options)) {
14
+ if (optionName === name) continue;
15
+ if (!conflictWith.includes(optionName)) continue;
16
+ if (optionContext.source === "default") continue;
17
+ conflictedOptions.push(optionName);
18
+ }
19
+ }
20
+ if (context.arguments) {
21
+ for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {
22
+ if (argumentName === name) continue;
23
+ if (!conflictWith.includes(argumentName)) continue;
24
+ if (argumentContext.source === "default") continue;
25
+ conflictedArguments.push(argumentName);
26
+ }
27
+ }
28
+ if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return;
29
+ throw new CliError({
30
+ cause: ErrorCause.Validation,
31
+ code: ValidationErrorCode.MutuallyExclusiveConflict,
32
+ context: { kind, name, conflictedOptions, conflictedArguments }
33
+ });
34
+ }
35
+ export {
36
+ validateConflictWith
37
+ };
38
+ //# sourceMappingURL=conflict.mjs.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["isOptionOrArgumentExplicitlyPassed","validateConflictWith","name","optionOrArgument","context","type","conflictWith","length","conflictedOptions","conflictedArguments","options","optionName","optionContext","Object","entries","includes","source","push","arguments","argumentName","argumentContext","parts","formatted","map","o","join","s","a","joinedParts","Error"],"sources":["../../../../../src/parse/validation/validators/conflict.ts"],"sourcesContent":["import { isOptionOrArgumentExplicitlyPassed } from \"./explicitly-passed.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Argument, Option } from \"../../../types/definitions-types.ts\";\n\ninterface ValidateConflictOptions {\n /** The option or argument name to check its `requires` */\n name: string;\n\n /** The option or argument to check */\n optionOrArgument: Option | Argument;\n\n /** The parsed context */\n context: ContextWide;\n\n /** What we're checking */\n type: \"option\" | \"argument\";\n}\n\n/** @throws {Error} */\nexport function validateConflictWith({ name, optionOrArgument, context, type }: ValidateConflictOptions) {\n const conflictWith = optionOrArgument.conflictWith;\n if (!conflictWith || conflictWith.length === 0) return;\n\n // Check if the options/argument is passed\n if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;\n\n const conflictedOptions: string[] = [];\n const conflictedArguments: string[] = [];\n\n if (context.options) {\n for (const [optionName, optionContext] of Object.entries(context.options)) {\n if (optionName === name) continue; // don't check self\n if (!conflictWith.includes(optionName)) continue; // not a conflict\n if (optionContext.source === \"default\") continue; // not explicitly passed\n conflictedOptions.push(optionName);\n }\n }\n\n if (context.arguments) {\n for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {\n if (argumentName === name) continue; // don't check self\n if (!conflictWith.includes(argumentName)) continue; // not a conflict\n if (argumentContext.source === \"default\") continue; // not explicitly passed\n conflictedArguments.push(argumentName);\n }\n }\n\n if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return; // OK\n\n const parts: string[] = [];\n\n if (conflictedOptions.length > 0) {\n const formatted = conflictedOptions.map(o => `\"${o}\"`).join(\", \");\n const s = conflictedOptions.length > 1 ? \"s\" : \"\";\n parts.push(`option${s} ${formatted}`);\n }\n\n if (conflictedArguments.length > 0) {\n const formatted = conflictedArguments.map(a => `\"${a}\"`).join(\", \");\n const s = conflictedArguments.length > 1 ? \"s\" : \"\";\n parts.push(`argument${s} ${formatted}`);\n }\n\n const joinedParts = parts.join(\" and \");\n\n throw new Error(`${type} \"${name}\" cannot be used with the ${joinedParts} because they are mutually exclusive.`);\n}\n"],"mappings":"OAASA,uCAA0C,0BAoB5C,SAASC,sBAAqBC,KAAEA,EAAAC,iBAAMA,EAAAC,QAAkBA,EAAAC,KAASA,IACtE,MAAMC,EAAeH,EAAiBG,aACtC,IAAKA,GAAwC,IAAxBA,EAAaC,OAAc,OAGhD,IAAKP,mCAAmCE,EAAME,GAAU,OAExD,MAAMI,EAA8B,GAC9BC,EAAgC,GAEtC,GAAIL,EAAQM,QACV,UAAYC,EAAYC,KAAkBC,OAAOC,QAAQV,EAAQM,SAC3DC,IAAeT,GACdI,EAAaS,SAASJ,IACE,YAAzBC,EAAcI,QAClBR,EAAkBS,KAAKN,GAI3B,GAAIP,EAAQc,UACV,UAAYC,EAAcC,KAAoBP,OAAOC,QAAQV,EAAQc,WAC/DC,IAAiBjB,GAChBI,EAAaS,SAASI,IACI,YAA3BC,EAAgBJ,QACpBP,EAAoBQ,KAAKE,GAI7B,GAAiC,IAA7BX,EAAkBD,QAA+C,IAA/BE,EAAoBF,OAAc,OAExE,MAAMc,EAAkB,GAExB,GAAIb,EAAkBD,OAAS,EAAG,CAChC,MAAMe,EAAYd,EAAkBe,IAAIC,GAAK,IAAIA,MAAMC,KAAK,MACtDC,EAAIlB,EAAkBD,OAAS,EAAI,IAAM,GAC/Cc,EAAMJ,KAAK,SAASS,KAAKJ,IAC3B,CAEA,GAAIb,EAAoBF,OAAS,EAAG,CAClC,MAAMe,EAAYb,EAAoBc,IAAII,GAAK,IAAIA,MAAMF,KAAK,MACxDC,EAAIjB,EAAoBF,OAAS,EAAI,IAAM,GACjDc,EAAMJ,KAAK,WAAWS,KAAKJ,IAC7B,CAEA,MAAMM,EAAcP,EAAMI,KAAK,SAE/B,MAAM,IAAII,MAAM,GAAGxB,MAASH,8BAAiC0B,yCAC/D,Q","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/parse/validation/validators/conflict.ts"],
4
+ "sourcesContent": ["import { CliError } from \"../../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../../cli-error/error-cause.ts\";\nimport { ValidationErrorCode } from \"../../../cli-error/error-code/validation-error-code.ts\";\nimport { isOptionOrArgumentExplicitlyPassed } from \"./explicitly-passed.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Argument, Option } from \"../../../types/definitions-types.ts\";\n\ninterface ValidateConflictOptions {\n /** The option or argument name to check its `requires` */\n name: string;\n\n /** The option or argument to check */\n optionOrArgument: Option | Argument;\n\n /** The parsed context */\n context: ContextWide;\n\n /** What we're checking */\n kind: \"option\" | \"argument\";\n}\n\n/** @throws {CliError} */\nexport function validateConflictWith({ name, optionOrArgument, context, kind }: ValidateConflictOptions) {\n const conflictWith = optionOrArgument.conflictWith;\n if (!conflictWith || conflictWith.length === 0) return;\n\n // Check if the options/argument is passed\n if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;\n\n const conflictedOptions: string[] = [];\n const conflictedArguments: string[] = [];\n\n if (context.options) {\n for (const [optionName, optionContext] of Object.entries(context.options)) {\n if (optionName === name) continue; // don't check self\n if (!conflictWith.includes(optionName)) continue; // not a conflict\n if (optionContext.source === \"default\") continue; // not explicitly passed\n conflictedOptions.push(optionName);\n }\n }\n\n if (context.arguments) {\n for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {\n if (argumentName === name) continue; // don't check self\n if (!conflictWith.includes(argumentName)) continue; // not a conflict\n if (argumentContext.source === \"default\") continue; // not explicitly passed\n conflictedArguments.push(argumentName);\n }\n }\n\n if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return; // OK\n\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.MutuallyExclusiveConflict,\n context: { kind, name, conflictedOptions, conflictedArguments },\n });\n}\n"],
5
+ "mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,0CAA0C;AAoB5C,SAAS,qBAAqB,EAAE,MAAM,kBAAkB,SAAS,KAAK,GAA4B;AACvG,QAAM,eAAe,iBAAiB;AACtC,MAAI,CAAC,gBAAgB,aAAa,WAAW,EAAG;AAGhD,MAAI,CAAC,mCAAmC,MAAM,OAAO,EAAG;AAExD,QAAM,oBAA8B,CAAC;AACrC,QAAM,sBAAgC,CAAC;AAEvC,MAAI,QAAQ,SAAS;AACnB,eAAW,CAAC,YAAY,aAAa,KAAK,OAAO,QAAQ,QAAQ,OAAO,GAAG;AACzE,UAAI,eAAe,KAAM;AACzB,UAAI,CAAC,aAAa,SAAS,UAAU,EAAG;AACxC,UAAI,cAAc,WAAW,UAAW;AACxC,wBAAkB,KAAK,UAAU;AAAA,IACnC;AAAA,EACF;AAEA,MAAI,QAAQ,WAAW;AACrB,eAAW,CAAC,cAAc,eAAe,KAAK,OAAO,QAAQ,QAAQ,SAAS,GAAG;AAC/E,UAAI,iBAAiB,KAAM;AAC3B,UAAI,CAAC,aAAa,SAAS,YAAY,EAAG;AAC1C,UAAI,gBAAgB,WAAW,UAAW;AAC1C,0BAAoB,KAAK,YAAY;AAAA,IACvC;AAAA,EACF;AAEA,MAAI,kBAAkB,WAAW,KAAK,oBAAoB,WAAW,EAAG;AAExE,QAAM,IAAI,SAAS;AAAA,IACjB,OAAO,WAAW;AAAA,IAClB,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,MAAM,MAAM,mBAAmB,oBAAoB;AAAA,EAChE,CAAC;AACH;",
6
+ "names": []
7
+ }
@@ -1,2 +1,39 @@
1
- import{isOptionOrArgumentExplicitlyPassed}from"./explicitly-passed.mjs";function validateExclusive({name:e,optionOrArgument:t,context:n,type:s}){if(!t.exclusive)return;if(!isOptionOrArgumentExplicitlyPassed(e,n))return;const i=t.requires??[],o=[],r=[];if(n.options)for(const[t,s]of Object.entries(n.options))t!==e&&(i.includes(t)||"default"!==s.source&&o.push(t));if(n.arguments)for(const[t,s]of Object.entries(n.arguments))t!==e&&(i.includes(t)||"default"!==s.source&&r.push(t));if(0===o.length&&0===r.length)return;const u=[];if(o.length>0){const e=o.map(e=>`"${e}"`).join(", "),t=o.length>1?"s":"";u.push(`option${t} ${e}`)}if(r.length>0){const e=r.map(e=>`"${e}"`).join(", "),t=r.length>1?"s":"";u.push(`argument${t} ${e}`)}const c=u.join(" and ");throw new Error(`${s} "${e}" cannot be used with the ${c} because they are mutually exclusive.`)}export{validateExclusive};
2
- //# sourceMappingURL=exclusive.mjs.map
1
+ // src/parse/validation/validators/exclusive.ts
2
+ import { CliError } from "../../../cli-error/cli-error.mjs";
3
+ import { ErrorCause } from "../../../cli-error/error-cause.mjs";
4
+ import { ValidationErrorCode } from "../../../cli-error/error-code/validation-error-code.mjs";
5
+ import { isOptionOrArgumentExplicitlyPassed } from "./explicitly-passed.mjs";
6
+ function validateExclusive({ name, optionOrArgument, context, kind }) {
7
+ const exclusive = optionOrArgument.exclusive;
8
+ if (!exclusive) return;
9
+ if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;
10
+ const requires = optionOrArgument.requires ?? [];
11
+ const conflictedOptions = [];
12
+ const conflictedArguments = [];
13
+ if (context.options) {
14
+ for (const [optionName, optionContext] of Object.entries(context.options)) {
15
+ if (optionName === name) continue;
16
+ if (requires.includes(optionName)) continue;
17
+ if (optionContext.source === "default") continue;
18
+ conflictedOptions.push(optionName);
19
+ }
20
+ }
21
+ if (context.arguments) {
22
+ for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {
23
+ if (argumentName === name) continue;
24
+ if (requires.includes(argumentName)) continue;
25
+ if (argumentContext.source === "default") continue;
26
+ conflictedArguments.push(argumentName);
27
+ }
28
+ }
29
+ if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return;
30
+ throw new CliError({
31
+ cause: ErrorCause.Validation,
32
+ code: ValidationErrorCode.MutuallyExclusiveConflict,
33
+ context: { kind, name, conflictedOptions, conflictedArguments }
34
+ });
35
+ }
36
+ export {
37
+ validateExclusive
38
+ };
39
+ //# sourceMappingURL=exclusive.mjs.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["isOptionOrArgumentExplicitlyPassed","validateExclusive","name","optionOrArgument","context","type","exclusive","requires","mutuallyExclusiveOptions","mutuallyExclusiveArguments","options","optionName","optionContext","Object","entries","includes","source","push","arguments","argumentName","argumentContext","length","parts","formatted","map","o","join","s","a","joinedParts","Error"],"sources":["../../../../../src/parse/validation/validators/exclusive.ts"],"sourcesContent":["import { isOptionOrArgumentExplicitlyPassed } from \"./explicitly-passed.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Argument, Option } from \"../../../types/definitions-types.ts\";\n\ninterface ValidateExclusiveOptions {\n /** The option or argument name to check its `requires` */\n name: string;\n\n /** The option or argument to check */\n optionOrArgument: Option | Argument;\n\n /** The parsed context */\n context: ContextWide;\n\n /** What we're checking */\n type: \"option\" | \"argument\";\n}\n\n/** @throws {Error} */\nexport function validateExclusive({ name, optionOrArgument, context, type }: ValidateExclusiveOptions) {\n const exclusive = optionOrArgument.exclusive;\n if (!exclusive) return;\n\n // Check if the options/argument is passed\n if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;\n\n const requires = optionOrArgument.requires ?? [];\n\n const mutuallyExclusiveOptions: string[] = [];\n const mutuallyExclusiveArguments: string[] = [];\n\n if (context.options) {\n for (const [optionName, optionContext] of Object.entries(context.options)) {\n if (optionName === name) continue; // don't check self\n if (requires.includes(optionName)) continue; // allow required options\n if (optionContext.source === \"default\") continue; // not explicitly passed\n mutuallyExclusiveOptions.push(optionName);\n }\n }\n\n if (context.arguments) {\n for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {\n if (argumentName === name) continue; // don't check self\n if (requires.includes(argumentName)) continue; // allow required arguments\n if (argumentContext.source === \"default\") continue; // not explicitly passed\n mutuallyExclusiveArguments.push(argumentName);\n }\n }\n\n if (mutuallyExclusiveOptions.length === 0 && mutuallyExclusiveArguments.length === 0) return;\n\n const parts: string[] = [];\n\n if (mutuallyExclusiveOptions.length > 0) {\n const formatted = mutuallyExclusiveOptions.map(o => `\"${o}\"`).join(\", \");\n const s = mutuallyExclusiveOptions.length > 1 ? \"s\" : \"\";\n parts.push(`option${s} ${formatted}`);\n }\n\n if (mutuallyExclusiveArguments.length > 0) {\n const formatted = mutuallyExclusiveArguments.map(a => `\"${a}\"`).join(\", \");\n const s = mutuallyExclusiveArguments.length > 1 ? \"s\" : \"\";\n parts.push(`argument${s} ${formatted}`);\n }\n\n const joinedParts = parts.join(\" and \");\n\n throw new Error(`${type} \"${name}\" cannot be used with the ${joinedParts} because they are mutually exclusive.`);\n}\n"],"mappings":"OAASA,uCAA0C,0BAoB5C,SAASC,mBAAkBC,KAAEA,EAAAC,iBAAMA,EAAAC,QAAkBA,EAAAC,KAASA,IAEnE,IADkBF,EAAiBG,UACnB,OAGhB,IAAKN,mCAAmCE,EAAME,GAAU,OAExD,MAAMG,EAAWJ,EAAiBI,UAAY,GAExCC,EAAqC,GACrCC,EAAuC,GAE7C,GAAIL,EAAQM,QACV,UAAYC,EAAYC,KAAkBC,OAAOC,QAAQV,EAAQM,SAC3DC,IAAeT,IACfK,EAASQ,SAASJ,IACO,YAAzBC,EAAcI,QAClBR,EAAyBS,KAAKN,IAIlC,GAAIP,EAAQc,UACV,UAAYC,EAAcC,KAAoBP,OAAOC,QAAQV,EAAQc,WAC/DC,IAAiBjB,IACjBK,EAASQ,SAASI,IACS,YAA3BC,EAAgBJ,QACpBP,EAA2BQ,KAAKE,IAIpC,GAAwC,IAApCX,EAAyBa,QAAsD,IAAtCZ,EAA2BY,OAAc,OAEtF,MAAMC,EAAkB,GAExB,GAAId,EAAyBa,OAAS,EAAG,CACvC,MAAME,EAAYf,EAAyBgB,IAAIC,GAAK,IAAIA,MAAMC,KAAK,MAC7DC,EAAInB,EAAyBa,OAAS,EAAI,IAAM,GACtDC,EAAML,KAAK,SAASU,KAAKJ,IAC3B,CAEA,GAAId,EAA2BY,OAAS,EAAG,CACzC,MAAME,EAAYd,EAA2Be,IAAII,GAAK,IAAIA,MAAMF,KAAK,MAC/DC,EAAIlB,EAA2BY,OAAS,EAAI,IAAM,GACxDC,EAAML,KAAK,WAAWU,KAAKJ,IAC7B,CAEA,MAAMM,EAAcP,EAAMI,KAAK,SAE/B,MAAM,IAAII,MAAM,GAAGzB,MAASH,8BAAiC2B,yCAC/D,Q","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/parse/validation/validators/exclusive.ts"],
4
+ "sourcesContent": ["import { CliError } from \"../../../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../../../cli-error/error-cause.ts\";\nimport { ValidationErrorCode } from \"../../../cli-error/error-code/validation-error-code.ts\";\nimport { isOptionOrArgumentExplicitlyPassed } from \"./explicitly-passed.ts\";\n\nimport type { ContextWide } from \"../../../types/context-types.ts\";\nimport type { Argument, Option } from \"../../../types/definitions-types.ts\";\n\ninterface ValidateExclusiveOptions {\n /** The option or argument name to check its `requires` */\n name: string;\n\n /** The option or argument to check */\n optionOrArgument: Option | Argument;\n\n /** The parsed context */\n context: ContextWide;\n\n /** What we're checking */\n kind: \"option\" | \"argument\";\n}\n\n/** @throws {CliError} */\nexport function validateExclusive({ name, optionOrArgument, context, kind }: ValidateExclusiveOptions) {\n const exclusive = optionOrArgument.exclusive;\n if (!exclusive) return;\n\n // Check if the options/argument is passed\n if (!isOptionOrArgumentExplicitlyPassed(name, context)) return;\n\n const requires = optionOrArgument.requires ?? [];\n\n const conflictedOptions: string[] = [];\n const conflictedArguments: string[] = [];\n\n if (context.options) {\n for (const [optionName, optionContext] of Object.entries(context.options)) {\n if (optionName === name) continue; // don't check self\n if (requires.includes(optionName)) continue; // allow required options\n if (optionContext.source === \"default\") continue; // not explicitly passed\n conflictedOptions.push(optionName);\n }\n }\n\n if (context.arguments) {\n for (const [argumentName, argumentContext] of Object.entries(context.arguments)) {\n if (argumentName === name) continue; // don't check self\n if (requires.includes(argumentName)) continue; // allow required arguments\n if (argumentContext.source === \"default\") continue; // not explicitly passed\n conflictedArguments.push(argumentName);\n }\n }\n\n if (conflictedOptions.length === 0 && conflictedArguments.length === 0) return;\n\n throw new CliError({\n cause: ErrorCause.Validation,\n code: ValidationErrorCode.MutuallyExclusiveConflict,\n context: { kind, name, conflictedOptions, conflictedArguments },\n });\n}\n"],
5
+ "mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,0CAA0C;AAoB5C,SAAS,kBAAkB,EAAE,MAAM,kBAAkB,SAAS,KAAK,GAA6B;AACrG,QAAM,YAAY,iBAAiB;AACnC,MAAI,CAAC,UAAW;AAGhB,MAAI,CAAC,mCAAmC,MAAM,OAAO,EAAG;AAExD,QAAM,WAAW,iBAAiB,YAAY,CAAC;AAE/C,QAAM,oBAA8B,CAAC;AACrC,QAAM,sBAAgC,CAAC;AAEvC,MAAI,QAAQ,SAAS;AACnB,eAAW,CAAC,YAAY,aAAa,KAAK,OAAO,QAAQ,QAAQ,OAAO,GAAG;AACzE,UAAI,eAAe,KAAM;AACzB,UAAI,SAAS,SAAS,UAAU,EAAG;AACnC,UAAI,cAAc,WAAW,UAAW;AACxC,wBAAkB,KAAK,UAAU;AAAA,IACnC;AAAA,EACF;AAEA,MAAI,QAAQ,WAAW;AACrB,eAAW,CAAC,cAAc,eAAe,KAAK,OAAO,QAAQ,QAAQ,SAAS,GAAG;AAC/E,UAAI,iBAAiB,KAAM;AAC3B,UAAI,SAAS,SAAS,YAAY,EAAG;AACrC,UAAI,gBAAgB,WAAW,UAAW;AAC1C,0BAAoB,KAAK,YAAY;AAAA,IACvC;AAAA,EACF;AAEA,MAAI,kBAAkB,WAAW,KAAK,oBAAoB,WAAW,EAAG;AAExE,QAAM,IAAI,SAAS;AAAA,IACjB,OAAO,WAAW;AAAA,IAClB,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,MAAM,MAAM,mBAAmB,oBAAoB;AAAA,EAChE,CAAC;AACH;",
6
+ "names": []
7
+ }