zod-args-parser 2.0.0-beta.0 → 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 (475) 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/{typescript → types}/types/io-types.d.ts +1 -1
  277. package/lib/types/types/types.d.ts +146 -0
  278. package/lib/types/types/types.d.ts.map +1 -0
  279. package/lib/{typescript → types}/types/utilities-types.d.ts +0 -2
  280. package/lib/{typescript → types}/types/utilities-types.d.ts.map +1 -1
  281. package/lib/types/utilities/parse-argv.d.ts +3 -0
  282. package/lib/types/utilities/parse-argv.d.ts.map +1 -0
  283. package/lib/types/utilities/schema-utilities.d.ts +15 -0
  284. package/lib/types/utilities/schema-utilities.d.ts.map +1 -0
  285. package/lib/{typescript → types/utilities}/utilities.d.ts +12 -15
  286. package/lib/types/utilities/utilities.d.ts.map +1 -0
  287. package/package.json +7 -7
  288. package/src/autocomplete-scripts/bash-autocomplete-script.ts +14 -12
  289. package/src/autocomplete-scripts/powershell-autocomplete-script.ts +67 -33
  290. package/src/autocomplete-scripts/zsh-autocomplete-script.ts +39 -31
  291. package/src/cli-error/cli-error.ts +44 -0
  292. package/src/cli-error/error-cause.ts +10 -0
  293. package/src/cli-error/error-code/definition-error-code.ts +21 -0
  294. package/src/cli-error/error-code/internal-error-code.ts +8 -0
  295. package/src/cli-error/error-code/parse-error-code.ts +16 -0
  296. package/src/cli-error/error-code/validation-error-code.ts +15 -0
  297. package/src/cli-error/error-message/definition-error-message.ts +144 -0
  298. package/src/cli-error/error-message/internal-error-message.ts +19 -0
  299. package/src/cli-error/error-message/parse-error-message.ts +76 -0
  300. package/src/cli-error/error-message/validation-error-message.ts +104 -0
  301. package/src/coerce/coerce-methods.ts +194 -39
  302. package/src/coerce/string-to-array.ts +2 -2
  303. package/src/coerce/string-to-primitive.ts +72 -13
  304. package/src/coerce/string-to-set.ts +2 -2
  305. package/src/definitions/define-arguments.ts +1 -1
  306. package/src/definitions/define-cli.ts +65 -30
  307. package/src/definitions/define-options.ts +1 -1
  308. package/src/definitions/define-subcommand.ts +47 -17
  309. package/src/definitions/validate-cli-definition.ts +287 -172
  310. package/src/help-message/format-arguments.ts +1 -1
  311. package/src/help-message/format-options.ts +1 -1
  312. package/src/help-message/format-subcommands.ts +1 -1
  313. package/src/help-message/generate-for-cli.ts +1 -1
  314. package/src/help-message/terminal-markdown.ts +3 -4
  315. package/src/index.ts +16 -0
  316. package/src/markdown/generate-markdown.ts +5 -4
  317. package/src/metadata/arguments-metadata.ts +2 -1
  318. package/src/metadata/options-metadata.ts +2 -1
  319. package/src/parse/context/cli-context-builder.ts +166 -39
  320. package/src/parse/context/object-context-builder.ts +37 -11
  321. package/src/parse/parser-utilities.ts +24 -10
  322. package/src/parse/safe-parse.ts +3 -6
  323. package/src/parse/validation/validate-context.ts +1 -1
  324. package/src/parse/validation/validators/arguments.ts +42 -14
  325. package/src/parse/validation/validators/conflict.ts +11 -20
  326. package/src/parse/validation/validators/exclusive.ts +16 -25
  327. package/src/parse/validation/validators/options.ts +40 -12
  328. package/src/parse/validation/validators/requires.ts +11 -20
  329. package/src/types/definitions-types.ts +36 -8
  330. package/src/types/error-types.ts +326 -0
  331. package/src/types/io-types.ts +1 -1
  332. package/src/types/types.ts +100 -7
  333. package/src/types/utilities-types.ts +0 -10
  334. package/src/utilities/parse-argv.ts +79 -0
  335. package/src/utilities/schema-utilities.ts +72 -0
  336. package/src/{utilities.ts → utilities/utilities.ts} +25 -138
  337. package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs +0 -2
  338. package/lib/cjs/autocomplete-scripts/bash-autocomplete-script.cjs.map +0 -1
  339. package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs +0 -2
  340. package/lib/cjs/autocomplete-scripts/powershell-autocomplete-script.cjs.map +0 -1
  341. package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs +0 -42
  342. package/lib/cjs/autocomplete-scripts/zsh-autocomplete-script.cjs.map +0 -1
  343. package/lib/cjs/coerce/coerce-methods.cjs +0 -2
  344. package/lib/cjs/coerce/coerce-methods.cjs.map +0 -1
  345. package/lib/cjs/coerce/string-to-array.cjs +0 -2
  346. package/lib/cjs/coerce/string-to-array.cjs.map +0 -1
  347. package/lib/cjs/coerce/string-to-primitive.cjs +0 -2
  348. package/lib/cjs/coerce/string-to-primitive.cjs.map +0 -1
  349. package/lib/cjs/coerce/string-to-set.cjs +0 -2
  350. package/lib/cjs/coerce/string-to-set.cjs.map +0 -1
  351. package/lib/cjs/definitions/define-arguments.cjs +0 -2
  352. package/lib/cjs/definitions/define-arguments.cjs.map +0 -1
  353. package/lib/cjs/definitions/define-cli.cjs +0 -2
  354. package/lib/cjs/definitions/define-cli.cjs.map +0 -1
  355. package/lib/cjs/definitions/define-options.cjs +0 -2
  356. package/lib/cjs/definitions/define-options.cjs.map +0 -1
  357. package/lib/cjs/definitions/define-subcommand.cjs +0 -2
  358. package/lib/cjs/definitions/define-subcommand.cjs.map +0 -1
  359. package/lib/cjs/definitions/validate-cli-definition.cjs +0 -2
  360. package/lib/cjs/definitions/validate-cli-definition.cjs.map +0 -1
  361. package/lib/cjs/help-message/format-arguments.cjs +0 -2
  362. package/lib/cjs/help-message/format-arguments.cjs.map +0 -1
  363. package/lib/cjs/help-message/format-options.cjs +0 -2
  364. package/lib/cjs/help-message/format-options.cjs.map +0 -1
  365. package/lib/cjs/help-message/format-subcommands.cjs +0 -2
  366. package/lib/cjs/help-message/format-subcommands.cjs.map +0 -1
  367. package/lib/cjs/help-message/generate-for-cli.cjs +0 -2
  368. package/lib/cjs/help-message/generate-for-cli.cjs.map +0 -1
  369. package/lib/cjs/help-message/generate-for-subcommand.cjs +0 -2
  370. package/lib/cjs/help-message/generate-for-subcommand.cjs.map +0 -1
  371. package/lib/cjs/help-message/print-help.cjs +0 -2
  372. package/lib/cjs/help-message/print-help.cjs.map +0 -1
  373. package/lib/cjs/help-message/set-defaults.cjs +0 -2
  374. package/lib/cjs/help-message/set-defaults.cjs.map +0 -1
  375. package/lib/cjs/help-message/styles.cjs +0 -2
  376. package/lib/cjs/help-message/styles.cjs.map +0 -1
  377. package/lib/cjs/help-message/terminal-markdown.cjs +0 -2
  378. package/lib/cjs/help-message/terminal-markdown.cjs.map +0 -1
  379. package/lib/cjs/index.cjs +0 -2
  380. package/lib/cjs/index.cjs.map +0 -1
  381. package/lib/cjs/markdown/generate-markdown.cjs +0 -2
  382. package/lib/cjs/markdown/generate-markdown.cjs.map +0 -1
  383. package/lib/cjs/metadata/arguments-metadata.cjs +0 -2
  384. package/lib/cjs/metadata/arguments-metadata.cjs.map +0 -1
  385. package/lib/cjs/metadata/cli-metadata.cjs +0 -2
  386. package/lib/cjs/metadata/cli-metadata.cjs.map +0 -1
  387. package/lib/cjs/metadata/options-metadata.cjs +0 -2
  388. package/lib/cjs/metadata/options-metadata.cjs.map +0 -1
  389. package/lib/cjs/metadata/subcommands-metadata.cjs +0 -2
  390. package/lib/cjs/metadata/subcommands-metadata.cjs.map +0 -1
  391. package/lib/cjs/parse/context/cli-context-builder.cjs +0 -2
  392. package/lib/cjs/parse/context/cli-context-builder.cjs.map +0 -1
  393. package/lib/cjs/parse/context/object-context-builder.cjs +0 -2
  394. package/lib/cjs/parse/context/object-context-builder.cjs.map +0 -1
  395. package/lib/cjs/parse/parser-utilities.cjs +0 -2
  396. package/lib/cjs/parse/parser-utilities.cjs.map +0 -1
  397. package/lib/cjs/parse/safe-parse.cjs +0 -2
  398. package/lib/cjs/parse/safe-parse.cjs.map +0 -1
  399. package/lib/cjs/parse/validation/validate-context.cjs +0 -2
  400. package/lib/cjs/parse/validation/validate-context.cjs.map +0 -1
  401. package/lib/cjs/parse/validation/validators/arguments.cjs +0 -2
  402. package/lib/cjs/parse/validation/validators/arguments.cjs.map +0 -1
  403. package/lib/cjs/parse/validation/validators/conflict.cjs +0 -2
  404. package/lib/cjs/parse/validation/validators/conflict.cjs.map +0 -1
  405. package/lib/cjs/parse/validation/validators/exclusive.cjs +0 -2
  406. package/lib/cjs/parse/validation/validators/exclusive.cjs.map +0 -1
  407. package/lib/cjs/parse/validation/validators/explicitly-passed.cjs +0 -2
  408. package/lib/cjs/parse/validation/validators/explicitly-passed.cjs.map +0 -1
  409. package/lib/cjs/parse/validation/validators/options.cjs +0 -2
  410. package/lib/cjs/parse/validation/validators/options.cjs.map +0 -1
  411. package/lib/cjs/parse/validation/validators/requires.cjs +0 -2
  412. package/lib/cjs/parse/validation/validators/requires.cjs.map +0 -1
  413. package/lib/cjs/utilities.cjs +0 -2
  414. package/lib/cjs/utilities.cjs.map +0 -1
  415. package/lib/esm/utilities.js +0 -2
  416. package/lib/esm/utilities.js.map +0 -1
  417. package/lib/mjs/utilities.mjs +0 -2
  418. package/lib/mjs/utilities.mjs.map +0 -1
  419. package/lib/typescript/autocomplete-scripts/powershell-autocomplete-script.d.ts +0 -14
  420. package/lib/typescript/autocomplete-scripts/zsh-autocomplete-script.d.ts +0 -11
  421. package/lib/typescript/coerce/coerce-methods.d.ts +0 -20
  422. package/lib/typescript/coerce/coerce-methods.d.ts.map +0 -1
  423. package/lib/typescript/coerce/string-to-array.d.ts.map +0 -1
  424. package/lib/typescript/coerce/string-to-primitive.d.ts +0 -5
  425. package/lib/typescript/coerce/string-to-primitive.d.ts.map +0 -1
  426. package/lib/typescript/definitions/define-cli.d.ts.map +0 -1
  427. package/lib/typescript/definitions/define-subcommand.d.ts.map +0 -1
  428. package/lib/typescript/definitions/validate-cli-definition.d.ts.map +0 -1
  429. package/lib/typescript/parse/context/object-context-builder.d.ts.map +0 -1
  430. package/lib/typescript/types/definitions-types.d.ts.map +0 -1
  431. package/lib/typescript/types/types.d.ts +0 -61
  432. package/lib/typescript/types/types.d.ts.map +0 -1
  433. package/lib/typescript/utilities.d.ts.map +0 -1
  434. /package/lib/{typescript → types}/autocomplete-scripts/bash-autocomplete-script.d.ts +0 -0
  435. /package/lib/{typescript → types}/definitions/define-arguments.d.ts +0 -0
  436. /package/lib/{typescript → types}/definitions/define-arguments.d.ts.map +0 -0
  437. /package/lib/{typescript → types}/definitions/define-options.d.ts +0 -0
  438. /package/lib/{typescript → types}/definitions/define-options.d.ts.map +0 -0
  439. /package/lib/{typescript → types}/help-message/format-arguments.d.ts +0 -0
  440. /package/lib/{typescript → types}/help-message/format-arguments.d.ts.map +0 -0
  441. /package/lib/{typescript → types}/help-message/format-options.d.ts +0 -0
  442. /package/lib/{typescript → types}/help-message/format-options.d.ts.map +0 -0
  443. /package/lib/{typescript → types}/help-message/format-subcommands.d.ts +0 -0
  444. /package/lib/{typescript → types}/help-message/format-subcommands.d.ts.map +0 -0
  445. /package/lib/{typescript → types}/help-message/generate-for-cli.d.ts +0 -0
  446. /package/lib/{typescript → types}/help-message/generate-for-cli.d.ts.map +0 -0
  447. /package/lib/{typescript → types}/help-message/generate-for-subcommand.d.ts +0 -0
  448. /package/lib/{typescript → types}/help-message/generate-for-subcommand.d.ts.map +0 -0
  449. /package/lib/{typescript → types}/help-message/print-help.d.ts +0 -0
  450. /package/lib/{typescript → types}/help-message/print-help.d.ts.map +0 -0
  451. /package/lib/{typescript → types}/help-message/set-defaults.d.ts +0 -0
  452. /package/lib/{typescript → types}/help-message/set-defaults.d.ts.map +0 -0
  453. /package/lib/{typescript → types}/help-message/styles.d.ts +0 -0
  454. /package/lib/{typescript → types}/help-message/styles.d.ts.map +0 -0
  455. /package/lib/{typescript → types}/help-message/terminal-markdown.d.ts +0 -0
  456. /package/lib/{typescript → types}/markdown/generate-markdown.d.ts +0 -0
  457. /package/lib/{typescript → types}/markdown/generate-markdown.d.ts.map +0 -0
  458. /package/lib/{typescript → types}/metadata/arguments-metadata.d.ts +0 -0
  459. /package/lib/{typescript → types}/metadata/cli-metadata.d.ts +0 -0
  460. /package/lib/{typescript → types}/metadata/cli-metadata.d.ts.map +0 -0
  461. /package/lib/{typescript → types}/metadata/options-metadata.d.ts +0 -0
  462. /package/lib/{typescript → types}/metadata/subcommands-metadata.d.ts +0 -0
  463. /package/lib/{typescript → types}/metadata/subcommands-metadata.d.ts.map +0 -0
  464. /package/lib/{typescript → types}/parse/safe-parse.d.ts +0 -0
  465. /package/lib/{typescript → types}/parse/validation/validators/explicitly-passed.d.ts +0 -0
  466. /package/lib/{typescript → types}/parse/validation/validators/explicitly-passed.d.ts.map +0 -0
  467. /package/lib/{typescript → types}/types/context-types.d.ts +0 -0
  468. /package/lib/{typescript → types}/types/context-types.d.ts.map +0 -0
  469. /package/lib/{typescript → types}/types/help-message-types.d.ts +0 -0
  470. /package/lib/{typescript → types}/types/help-message-types.d.ts.map +0 -0
  471. /package/lib/{typescript → types}/types/io-types.d.ts.map +0 -0
  472. /package/lib/{typescript → types}/types/metadata-types.d.ts +0 -0
  473. /package/lib/{typescript → types}/types/metadata-types.d.ts.map +0 -0
  474. /package/lib/{typescript → types}/types/schema-types.d.ts +0 -0
  475. /package/lib/{typescript → types}/types/schema-types.d.ts.map +0 -0
@@ -1,2 +1,89 @@
1
- import{generateCliHelpMessage}from"../help-message/generate-for-cli.js";import{generateSubcommandHelpMessage}from"../help-message/generate-for-subcommand.js";import{buildObjectContext}from"../parse/context/object-context-builder.js";import{safeParse,safeParseAsync}from"../parse/safe-parse.js";import{validate}from"../parse/validation/validate-context.js";import{prepareDefinitionTypes}from"../utilities.js";function defineCLI(e){const n=e;if(prepareDefinitionTypes(n.options),prepareDefinitionTypes(n.arguments),n.subcommands)for(const e of Object.values(n.subcommands))prepareDefinitionTypes(e.options),prepareDefinitionTypes(e.arguments);const s={generateCliHelpMessage:e=>generateCliHelpMessage(n,e),generateSubcommandHelpMessage(e,s){const o=n.subcommands?.find(n=>n.name===e);if(!o)throw new Error(`Subcommand ${e} not found`);return generateSubcommandHelpMessage(o,s,n.cliName)}};if(Object.assign(n,s),n.subcommands)for(const e of n.subcommands)Object.assign(e,s);return Object.assign(n,{execute:e=>{if(e??(e={}),!n._onExecute)throw new Error("Action is not defined");const s=buildObjectContext(e,n),o=validate(s,n);if(n._onExecute)for(const e of n._onExecute)e(o)},onExecute:e=>(n._onExecute??(n._onExecute=[]),n._onExecute.push(e),()=>{const s=n._onExecute?.indexOf(e);!s||s<0||n._onExecute?.splice(s,1)}),run:e=>safeParse(e,n),runAsync:e=>safeParseAsync(e,n)})}export{defineCLI};
2
- //# sourceMappingURL=define-cli.js.map
1
+ // src/definitions/define-cli.ts
2
+ import { CliError } from "../cli-error/cli-error.js";
3
+ import { ErrorCause } from "../cli-error/error-cause.js";
4
+ import { DefinitionErrorCode } from "../cli-error/error-code/definition-error-code.js";
5
+ import { generateCliHelpMessage } from "../help-message/generate-for-cli.js";
6
+ import { generateSubcommandHelpMessage } from "../help-message/generate-for-subcommand.js";
7
+ import { buildObjectContext } from "../parse/context/object-context-builder.js";
8
+ import { safeParse, safeParseAsync } from "../parse/safe-parse.js";
9
+ import { validate } from "../parse/validation/validate-context.js";
10
+ import { prepareDefinitionTypes } from "../utilities/schema-utilities.js";
11
+ function defineCLI(input) {
12
+ const cliDefinition = input;
13
+ prepareDefinitionTypes(cliDefinition.options);
14
+ prepareDefinitionTypes(cliDefinition.arguments);
15
+ if (cliDefinition.subcommands) {
16
+ for (const subcommand of Object.values(cliDefinition.subcommands)) {
17
+ prepareDefinitionTypes(subcommand.options);
18
+ prepareDefinitionTypes(subcommand.arguments);
19
+ }
20
+ }
21
+ const onExecute = (handler) => {
22
+ cliDefinition._onExecute ??= [];
23
+ cliDefinition._onExecute.push(handler);
24
+ return () => {
25
+ const handlerIndex = cliDefinition._onExecute?.indexOf(handler);
26
+ if (!handlerIndex || handlerIndex < 0) return;
27
+ cliDefinition._onExecute?.splice(handlerIndex, 1);
28
+ };
29
+ };
30
+ const execute = (inputValues) => {
31
+ inputValues ??= {};
32
+ const handlers = cliDefinition._onExecute;
33
+ if (!handlers) {
34
+ throw new CliError({
35
+ cause: ErrorCause.Definition,
36
+ code: DefinitionErrorCode.MissingOnExecute,
37
+ context: { commandKind: "command", commandName: cliDefinition.cliName }
38
+ });
39
+ }
40
+ const context = buildObjectContext(inputValues, cliDefinition);
41
+ const validateResult = validate(context, cliDefinition);
42
+ for (const handler of handlers) {
43
+ void handler(validateResult);
44
+ }
45
+ };
46
+ const executeAsync = async (inputValues) => {
47
+ inputValues ??= {};
48
+ const handlers = cliDefinition._onExecute;
49
+ if (!handlers) {
50
+ throw new CliError({
51
+ cause: ErrorCause.Definition,
52
+ code: DefinitionErrorCode.MissingOnExecute,
53
+ context: { commandKind: "command", commandName: cliDefinition.cliName }
54
+ });
55
+ }
56
+ const context = buildObjectContext(inputValues, cliDefinition);
57
+ const validateResult = validate(context, cliDefinition);
58
+ await Promise.all(handlers.map(async (handler) => await handler(validateResult)));
59
+ };
60
+ const generateHelpMethods = {
61
+ generateCliHelpMessage(options) {
62
+ return generateCliHelpMessage(cliDefinition, options);
63
+ },
64
+ generateSubcommandHelpMessage(subcommandName, options) {
65
+ const foundSubcommand = cliDefinition.subcommands?.find((s) => s.name === subcommandName);
66
+ if (!foundSubcommand) {
67
+ throw new CliError({
68
+ cause: ErrorCause.Definition,
69
+ code: DefinitionErrorCode.SubcommandHelpNotFound,
70
+ context: { cliName: cliDefinition.cliName, subcommandName }
71
+ });
72
+ }
73
+ return generateSubcommandHelpMessage(foundSubcommand, options, cliDefinition.cliName);
74
+ }
75
+ };
76
+ Object.assign(cliDefinition, generateHelpMethods);
77
+ if (cliDefinition.subcommands) {
78
+ for (const subcommandSchema of cliDefinition.subcommands) {
79
+ Object.assign(subcommandSchema, generateHelpMethods);
80
+ }
81
+ }
82
+ const run = (stringOrArgv) => safeParse(stringOrArgv, cliDefinition);
83
+ const runAsync = (stringOrArgv) => safeParseAsync(stringOrArgv, cliDefinition);
84
+ return Object.assign(cliDefinition, { onExecute, execute, executeAsync, run, runAsync });
85
+ }
86
+ export {
87
+ defineCLI
88
+ };
89
+ //# sourceMappingURL=define-cli.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["generateCliHelpMessage","generateSubcommandHelpMessage","buildObjectContext","safeParse","safeParseAsync","validate","prepareDefinitionTypes","defineCLI","input","cliSchema","options","arguments","subcommands","subcommand","Object","values","generateHelpMethods","subcommandName","foundSubcommand","find","s","name","Error","cliName","assign","subcommandSchema","execute","inputValues","_onExecute","context","validateResult","handler","onExecute","push","handlerIndex","indexOf","splice","run","stringOrArgv","runAsync"],"sources":["../../../src/definitions/define-cli.ts"],"sourcesContent":["import { generateCliHelpMessage } from \"../help-message/generate-for-cli.ts\";\nimport { generateSubcommandHelpMessage } from \"../help-message/generate-for-subcommand.ts\";\nimport { buildObjectContext } from \"../parse/context/object-context-builder.ts\";\nimport { safeParse, safeParseAsync } from \"../parse/safe-parse.ts\";\nimport { validate } from \"../parse/validation/validate-context.ts\";\nimport { prepareDefinitionTypes } from \"../utilities.ts\";\n\nimport type { Argument, Cli, Option, Subcommand } from \"../types/definitions-types.ts\";\nimport type { PrintHelpOptions } from \"../types/help-message-types.ts\";\nimport type { AttachedMethods, AttachedMethodsWide, ValidateMethods } from \"../types/types.ts\";\nimport type { Prettify } from \"../types/utilities-types.ts\";\n\ntype OptionsInput<T> =\n T extends Record<string, Option> ? { [OptionName in keyof T]: Option<T[OptionName][\"schema\"]> } : T;\n\ntype ArgumentsInput<T> =\n T extends Record<string, Argument> ? { [ArgumentName in keyof T]: Argument<T[ArgumentName][\"schema\"]> } : T;\n\ntype SubcommandsInput<T extends readonly [Subcommand, ...Subcommand[]]> = {\n [SubcommandIndex in keyof T]: {\n [K in keyof T[SubcommandIndex]]: T[SubcommandIndex][K] extends Record<string, Option>\n ? OptionsInput<T[SubcommandIndex][K]>\n : T[SubcommandIndex][K] extends Record<string, Argument>\n ? ArgumentsInput<T[SubcommandIndex][K]>\n : T[SubcommandIndex][K];\n } & Subcommand;\n};\n\n// This will prevent extra keys and enable jsdoc on hover\ntype CliInput<T extends Cli> = {\n [K in keyof T]: K extends keyof Cli\n ? T[K] extends readonly [Subcommand, ...Subcommand[]]\n ? SubcommandsInput<T[K]>\n : K extends \"options\"\n ? OptionsInput<T[K]>\n : K extends \"arguments\"\n ? ArgumentsInput<T[K]>\n : T[K]\n : never;\n};\n\nexport function defineCLI<T extends Cli>(input: CliInput<T> & Cli) {\n const cliSchema = input as Prettify<T & AttachedMethods<T> & ValidateMethods<T>>;\n\n prepareDefinitionTypes(cliSchema.options);\n prepareDefinitionTypes(cliSchema.arguments);\n\n if (cliSchema.subcommands) {\n for (const subcommand of Object.values(cliSchema.subcommands)) {\n prepareDefinitionTypes(subcommand.options);\n prepareDefinitionTypes(subcommand.arguments);\n }\n }\n\n const onExecute = (handler: (Cli[\"_onExecute\"] & {})[number]) => {\n cliSchema._onExecute ??= [];\n cliSchema._onExecute.push(handler);\n\n return () => {\n const handlerIndex = cliSchema._onExecute?.indexOf(handler);\n if (!handlerIndex || handlerIndex < 0) return;\n cliSchema._onExecute?.splice(handlerIndex, 1);\n };\n };\n\n const execute: AttachedMethodsWide[\"execute\"] = inputValues => {\n inputValues ??= {};\n if (!cliSchema._onExecute) throw new Error(\"Action is not defined\");\n const context = buildObjectContext(inputValues, cliSchema);\n const validateResult = validate(context, cliSchema);\n\n if (cliSchema._onExecute) {\n for (const handler of cliSchema._onExecute) {\n handler(validateResult);\n }\n }\n };\n\n // Add print methods for CLI schema and its subcommands\n const generateHelpMethods: Pick<AttachedMethodsWide, \"generateCliHelpMessage\" | \"generateSubcommandHelpMessage\"> = {\n generateCliHelpMessage(options?: PrintHelpOptions) {\n return generateCliHelpMessage(cliSchema, options);\n },\n generateSubcommandHelpMessage(subcommandName: string, options?: PrintHelpOptions) {\n const foundSubcommand = cliSchema.subcommands?.find(s => s.name === subcommandName);\n if (!foundSubcommand) throw new Error(`Subcommand ${subcommandName} not found`);\n return generateSubcommandHelpMessage(foundSubcommand, options, cliSchema.cliName);\n },\n };\n\n Object.assign(cliSchema, generateHelpMethods);\n\n if (cliSchema.subcommands) {\n for (const subcommandSchema of cliSchema.subcommands) {\n Object.assign(subcommandSchema, generateHelpMethods);\n }\n }\n\n return Object.assign(cliSchema, {\n execute,\n onExecute,\n run: (stringOrArgv: string | string[]) => safeParse(stringOrArgv, cliSchema),\n runAsync: (stringOrArgv: string | string[]) => safeParseAsync(stringOrArgv, cliSchema),\n });\n}\n"],"mappings":"OAASA,2BAA8B,6CAC9BC,kCAAqC,oDACrCC,uBAA0B,oDAC1BC,UAAWC,mBAAsB,gCACjCC,aAAgB,iDAChBC,2BAA8B,kBAoChC,SAASC,UAAyBC,GACvC,MAAMC,EAAYD,EAKlB,GAHAF,uBAAuBG,EAAUC,SACjCJ,uBAAuBG,EAAUE,WAE7BF,EAAUG,YACZ,UAAWC,KAAcC,OAAOC,OAAON,EAAUG,aAC/CN,uBAAuBO,EAAWH,SAClCJ,uBAAuBO,EAAWF,WAItC,MAyBMK,EAA6G,CACjHhB,uBAAuBU,GACdV,uBAAuBS,EAAWC,GAE3C,6BAAAT,CAA8BgB,EAAwBP,GACpD,MAAMQ,EAAkBT,EAAUG,aAAaO,KAAKC,GAAKA,EAAEC,OAASJ,GACpE,IAAKC,EAAiB,MAAM,IAAII,MAAM,cAAcL,eACpD,OAAOhB,8BAA8BiB,EAAiBR,EAASD,EAAUc,QAC3E,GAKF,GAFAT,OAAOU,OAAOf,EAAWO,GAErBP,EAAUG,YACZ,UAAWa,KAAoBhB,EAAUG,YACvCE,OAAOU,OAAOC,EAAkBT,GAIpC,OAAOF,OAAOU,OAAOf,EAAW,CAC9BiB,QAlC8CC,IAE9C,GADAA,MAAgB,CAAC,IACZlB,EAAUmB,WAAY,MAAM,IAAIN,MAAM,yBAC3C,MAAMO,EAAU3B,mBAAmByB,EAAalB,GAC1CqB,EAAiBzB,SAASwB,EAASpB,GAEzC,GAAIA,EAAUmB,WACZ,UAAWG,KAAWtB,EAAUmB,WAC9BG,EAAQD,IA2BZE,UA9CiBD,IACjBtB,EAAUmB,aAAVnB,EAAUmB,WAAe,IACzBnB,EAAUmB,WAAWK,KAAKF,GAEnB,KACL,MAAMG,EAAezB,EAAUmB,YAAYO,QAAQJ,IAC9CG,GAAgBA,EAAe,GACpCzB,EAAUmB,YAAYQ,OAAOF,EAAc,KAwC7CG,IAAMC,GAAoCnC,UAAUmC,EAAc7B,GAClE8B,SAAWD,GAAoClC,eAAekC,EAAc7B,IAEhF,Q","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/definitions/define-cli.ts"],
4
+ "sourcesContent": ["import { CliError } from \"../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../cli-error/error-cause.ts\";\nimport { DefinitionErrorCode } from \"../cli-error/error-code/definition-error-code.ts\";\nimport { generateCliHelpMessage } from \"../help-message/generate-for-cli.ts\";\nimport { generateSubcommandHelpMessage } from \"../help-message/generate-for-subcommand.ts\";\nimport { buildObjectContext } from \"../parse/context/object-context-builder.ts\";\nimport { safeParse, safeParseAsync } from \"../parse/safe-parse.ts\";\nimport { validate } from \"../parse/validation/validate-context.ts\";\nimport { prepareDefinitionTypes } from \"../utilities/schema-utilities.ts\";\n\nimport type { Argument, Cli, Option, Subcommand } from \"../types/definitions-types.ts\";\nimport type { PrintHelpOptions } from \"../types/help-message-types.ts\";\nimport type { AttachedMethods, AttachedMethodsWide, ValidateMethods } from \"../types/types.ts\";\nimport type { Prettify } from \"../types/utilities-types.ts\";\n\ntype OptionsInput<T> =\n T extends Record<string, Option> ? { [OptionName in keyof T]: Option<T[OptionName][\"schema\"]> } : T;\n\ntype ArgumentsInput<T> =\n T extends Record<string, Argument> ? { [ArgumentName in keyof T]: Argument<T[ArgumentName][\"schema\"]> } : T;\n\ntype SubcommandsInput<T extends readonly [Subcommand, ...Subcommand[]]> = {\n [SubcommandIndex in keyof T]: {\n [K in keyof T[SubcommandIndex]]: T[SubcommandIndex][K] extends Record<string, Option>\n ? OptionsInput<T[SubcommandIndex][K]>\n : T[SubcommandIndex][K] extends Record<string, Argument>\n ? ArgumentsInput<T[SubcommandIndex][K]>\n : T[SubcommandIndex][K];\n } & Subcommand;\n};\n\n// This will prevent extra keys and enable jsdoc on hover\ntype CliInput<T extends Cli> = {\n [K in keyof T]: K extends keyof Cli\n ? T[K] extends readonly [Subcommand, ...Subcommand[]]\n ? SubcommandsInput<T[K]>\n : K extends \"options\"\n ? OptionsInput<T[K]>\n : K extends \"arguments\"\n ? ArgumentsInput<T[K]>\n : T[K]\n : never;\n};\n\nexport function defineCLI<T extends Cli>(input: CliInput<T> & Cli) {\n const cliDefinition = input as T;\n\n prepareDefinitionTypes(cliDefinition.options);\n prepareDefinitionTypes(cliDefinition.arguments);\n\n if (cliDefinition.subcommands) {\n for (const subcommand of Object.values(cliDefinition.subcommands)) {\n prepareDefinitionTypes(subcommand.options);\n prepareDefinitionTypes(subcommand.arguments);\n }\n }\n\n const onExecute = (handler: (Cli[\"_onExecute\"] & {})[number]) => {\n cliDefinition._onExecute ??= [];\n cliDefinition._onExecute.push(handler);\n\n return () => {\n const handlerIndex = cliDefinition._onExecute?.indexOf(handler);\n if (!handlerIndex || handlerIndex < 0) return;\n cliDefinition._onExecute?.splice(handlerIndex, 1);\n };\n };\n\n const execute: AttachedMethodsWide[\"execute\"] = inputValues => {\n inputValues ??= {};\n\n const handlers = cliDefinition._onExecute;\n if (!handlers) {\n throw new CliError({\n cause: ErrorCause.Definition,\n code: DefinitionErrorCode.MissingOnExecute,\n context: { commandKind: \"command\", commandName: cliDefinition.cliName },\n });\n }\n\n const context = buildObjectContext(inputValues, cliDefinition);\n const validateResult = validate(context, cliDefinition);\n\n for (const handler of handlers) {\n void handler(validateResult);\n }\n };\n\n const executeAsync: AttachedMethodsWide[\"executeAsync\"] = async inputValues => {\n inputValues ??= {};\n\n const handlers = cliDefinition._onExecute;\n\n if (!handlers) {\n throw new CliError({\n cause: ErrorCause.Definition,\n code: DefinitionErrorCode.MissingOnExecute,\n context: { commandKind: \"command\", commandName: cliDefinition.cliName },\n });\n }\n\n const context = buildObjectContext(inputValues, cliDefinition);\n const validateResult = validate(context, cliDefinition);\n\n await Promise.all(handlers.map(async handler => await handler(validateResult)));\n };\n\n // Add print methods for CLI schema and its subcommands\n const generateHelpMethods: Pick<AttachedMethodsWide, \"generateCliHelpMessage\" | \"generateSubcommandHelpMessage\"> = {\n generateCliHelpMessage(options?: PrintHelpOptions) {\n return generateCliHelpMessage(cliDefinition, options);\n },\n generateSubcommandHelpMessage(subcommandName: string, options?: PrintHelpOptions) {\n const foundSubcommand = cliDefinition.subcommands?.find(s => s.name === subcommandName);\n if (!foundSubcommand) {\n throw new CliError({\n cause: ErrorCause.Definition,\n code: DefinitionErrorCode.SubcommandHelpNotFound,\n context: { cliName: cliDefinition.cliName, subcommandName },\n });\n }\n return generateSubcommandHelpMessage(foundSubcommand, options, cliDefinition.cliName);\n },\n };\n\n Object.assign(cliDefinition, generateHelpMethods);\n\n if (cliDefinition.subcommands) {\n for (const subcommandSchema of cliDefinition.subcommands) {\n Object.assign(subcommandSchema, generateHelpMethods);\n }\n }\n\n const run = (stringOrArgv: string | string[]) => safeParse(stringOrArgv, cliDefinition);\n const runAsync = (stringOrArgv: string | string[]) => safeParseAsync(stringOrArgv, cliDefinition);\n\n return Object.assign(cliDefinition, { onExecute, execute, executeAsync, run, runAsync }) as Prettify<\n T & AttachedMethods<T> & ValidateMethods<T>\n >;\n}\n"],
5
+ "mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,qCAAqC;AAC9C,SAAS,0BAA0B;AACnC,SAAS,WAAW,sBAAsB;AAC1C,SAAS,gBAAgB;AACzB,SAAS,8BAA8B;AAoChC,SAAS,UAAyB,OAA0B;AACjE,QAAM,gBAAgB;AAEtB,yBAAuB,cAAc,OAAO;AAC5C,yBAAuB,cAAc,SAAS;AAE9C,MAAI,cAAc,aAAa;AAC7B,eAAW,cAAc,OAAO,OAAO,cAAc,WAAW,GAAG;AACjE,6BAAuB,WAAW,OAAO;AACzC,6BAAuB,WAAW,SAAS;AAAA,IAC7C;AAAA,EACF;AAEA,QAAM,YAAY,CAAC,YAA8C;AAC/D,kBAAc,eAAe,CAAC;AAC9B,kBAAc,WAAW,KAAK,OAAO;AAErC,WAAO,MAAM;AACX,YAAM,eAAe,cAAc,YAAY,QAAQ,OAAO;AAC9D,UAAI,CAAC,gBAAgB,eAAe,EAAG;AACvC,oBAAc,YAAY,OAAO,cAAc,CAAC;AAAA,IAClD;AAAA,EACF;AAEA,QAAM,UAA0C,iBAAe;AAC7D,oBAAgB,CAAC;AAEjB,UAAM,WAAW,cAAc;AAC/B,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS,EAAE,aAAa,WAAW,aAAa,cAAc,QAAQ;AAAA,MACxE,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,mBAAmB,aAAa,aAAa;AAC7D,UAAM,iBAAiB,SAAS,SAAS,aAAa;AAEtD,eAAW,WAAW,UAAU;AAC9B,WAAK,QAAQ,cAAc;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,eAAoD,OAAM,gBAAe;AAC7E,oBAAgB,CAAC;AAEjB,UAAM,WAAW,cAAc;AAE/B,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS,EAAE,aAAa,WAAW,aAAa,cAAc,QAAQ;AAAA,MACxE,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,mBAAmB,aAAa,aAAa;AAC7D,UAAM,iBAAiB,SAAS,SAAS,aAAa;AAEtD,UAAM,QAAQ,IAAI,SAAS,IAAI,OAAM,YAAW,MAAM,QAAQ,cAAc,CAAC,CAAC;AAAA,EAChF;AAGA,QAAM,sBAA6G;AAAA,IACjH,uBAAuB,SAA4B;AACjD,aAAO,uBAAuB,eAAe,OAAO;AAAA,IACtD;AAAA,IACA,8BAA8B,gBAAwB,SAA4B;AAChF,YAAM,kBAAkB,cAAc,aAAa,KAAK,OAAK,EAAE,SAAS,cAAc;AACtF,UAAI,CAAC,iBAAiB;AACpB,cAAM,IAAI,SAAS;AAAA,UACjB,OAAO,WAAW;AAAA,UAClB,MAAM,oBAAoB;AAAA,UAC1B,SAAS,EAAE,SAAS,cAAc,SAAS,eAAe;AAAA,QAC5D,CAAC;AAAA,MACH;AACA,aAAO,8BAA8B,iBAAiB,SAAS,cAAc,OAAO;AAAA,IACtF;AAAA,EACF;AAEA,SAAO,OAAO,eAAe,mBAAmB;AAEhD,MAAI,cAAc,aAAa;AAC7B,eAAW,oBAAoB,cAAc,aAAa;AACxD,aAAO,OAAO,kBAAkB,mBAAmB;AAAA,IACrD;AAAA,EACF;AAEA,QAAM,MAAM,CAAC,iBAAoC,UAAU,cAAc,aAAa;AACtF,QAAM,WAAW,CAAC,iBAAoC,eAAe,cAAc,aAAa;AAEhG,SAAO,OAAO,OAAO,eAAe,EAAE,WAAW,SAAS,cAAc,KAAK,SAAS,CAAC;AAGzF;",
6
+ "names": []
7
+ }
@@ -1,2 +1,10 @@
1
- import{prepareDefinitionTypes}from"../utilities.js";function defineOptions(e){return prepareDefinitionTypes(e),e}export{defineOptions};
2
- //# sourceMappingURL=define-options.js.map
1
+ // src/definitions/define-options.ts
2
+ import { prepareDefinitionTypes } from "../utilities/schema-utilities.js";
3
+ function defineOptions(options) {
4
+ prepareDefinitionTypes(options);
5
+ return options;
6
+ }
7
+ export {
8
+ defineOptions
9
+ };
10
+ //# sourceMappingURL=define-options.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["prepareDefinitionTypes","defineOptions","options"],"sources":["../../../src/definitions/define-options.ts"],"sourcesContent":["import { prepareDefinitionTypes } from \"../utilities.ts\";\n\nimport type { Option } from \"../types/definitions-types.ts\";\n\nexport function defineOptions<T extends Record<string, Option>>(options: {\n [K in keyof T]: T[K] & Option<T[K][\"schema\"]>;\n}): {\n [K in keyof T]: Option<T[K][\"schema\"]>;\n} {\n prepareDefinitionTypes(options);\n return options;\n}\n"],"mappings":"OAASA,2BAA8B,kBAIhC,SAASC,cAAgDC,GAM9D,OADAF,uBAAuBE,GAChBA,CACT,Q","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/definitions/define-options.ts"],
4
+ "sourcesContent": ["import { prepareDefinitionTypes } from \"../utilities/schema-utilities.ts\";\n\nimport type { Option } from \"../types/definitions-types.ts\";\n\nexport function defineOptions<T extends Record<string, Option>>(options: {\n [K in keyof T]: T[K] & Option<T[K][\"schema\"]>;\n}): {\n [K in keyof T]: Option<T[K][\"schema\"]>;\n} {\n prepareDefinitionTypes(options);\n return options;\n}\n"],
5
+ "mappings": ";AAAA,SAAS,8BAA8B;AAIhC,SAAS,cAAgD,SAI9D;AACA,yBAAuB,OAAO;AAC9B,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,2 +1,56 @@
1
- import{buildObjectContext}from"../parse/context/object-context-builder.js";import{validate}from"../parse/validation/validate-context.js";import{prepareDefinitionTypes}from"../utilities.js";function defineSubcommand(e){const t=e;prepareDefinitionTypes(t.options),prepareDefinitionTypes(t.arguments);return Object.assign(t,{onExecute:e=>(t._onExecute??(t._onExecute=[]),t._onExecute.push(e),()=>{const o=t._onExecute?.indexOf(e);!o||o<0||t._onExecute?.splice(o,1)}),execute:e=>{if(e??(e={}),!t._onExecute)throw new Error("Action is not defined");const o=buildObjectContext(e,t),n=validate(o,t);if(t._onExecute)for(const e of t._onExecute)e(n)}})}export{defineSubcommand};
2
- //# sourceMappingURL=define-subcommand.js.map
1
+ // src/definitions/define-subcommand.ts
2
+ import { CliError } from "../cli-error/cli-error.js";
3
+ import { ErrorCause } from "../cli-error/error-cause.js";
4
+ import { DefinitionErrorCode } from "../cli-error/error-code/definition-error-code.js";
5
+ import { buildObjectContext } from "../parse/context/object-context-builder.js";
6
+ import { validate } from "../parse/validation/validate-context.js";
7
+ import { prepareDefinitionTypes } from "../utilities/schema-utilities.js";
8
+ function defineSubcommand(input) {
9
+ const subcommandDefinition = input;
10
+ prepareDefinitionTypes(subcommandDefinition.options);
11
+ prepareDefinitionTypes(subcommandDefinition.arguments);
12
+ const onExecute = (handler) => {
13
+ subcommandDefinition._onExecute ??= [];
14
+ subcommandDefinition._onExecute.push(handler);
15
+ return () => {
16
+ const handlerIndex = subcommandDefinition._onExecute?.indexOf(handler);
17
+ if (!handlerIndex || handlerIndex < 0) return;
18
+ subcommandDefinition._onExecute?.splice(handlerIndex, 1);
19
+ };
20
+ };
21
+ const execute = (inputValues) => {
22
+ inputValues ??= {};
23
+ const handlers = subcommandDefinition._onExecute;
24
+ if (!handlers) {
25
+ throw new CliError({
26
+ cause: ErrorCause.Definition,
27
+ code: DefinitionErrorCode.MissingOnExecute,
28
+ context: { commandKind: "subcommand", commandName: subcommandDefinition.name }
29
+ });
30
+ }
31
+ const context = buildObjectContext(inputValues, subcommandDefinition);
32
+ const validateResult = validate(context, subcommandDefinition);
33
+ for (const handler of handlers) {
34
+ void handler(validateResult);
35
+ }
36
+ };
37
+ const executeAsync = async (inputValues) => {
38
+ inputValues ??= {};
39
+ const handlers = subcommandDefinition._onExecute;
40
+ if (!handlers) {
41
+ throw new CliError({
42
+ cause: ErrorCause.Definition,
43
+ code: DefinitionErrorCode.MissingOnExecute,
44
+ context: { commandKind: "subcommand", commandName: subcommandDefinition.name }
45
+ });
46
+ }
47
+ const context = buildObjectContext(inputValues, subcommandDefinition);
48
+ const validateResult = validate(context, subcommandDefinition);
49
+ await Promise.all(handlers.map(async (handler) => await handler(validateResult)));
50
+ };
51
+ return Object.assign(subcommandDefinition, { onExecute, execute, executeAsync });
52
+ }
53
+ export {
54
+ defineSubcommand
55
+ };
56
+ //# sourceMappingURL=define-subcommand.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["buildObjectContext","validate","prepareDefinitionTypes","defineSubcommand","input","subcommandSchema","options","arguments","Object","assign","onExecute","handler","_onExecute","push","handlerIndex","indexOf","splice","execute","inputValues","Error","context","validateResult"],"sources":["../../../src/definitions/define-subcommand.ts"],"sourcesContent":["import { buildObjectContext } from \"../parse/context/object-context-builder.ts\";\nimport { validate } from \"../parse/validation/validate-context.ts\";\nimport { prepareDefinitionTypes } from \"../utilities.ts\";\n\nimport type { Argument, Option, Subcommand } from \"../types/definitions-types.ts\";\nimport type { AttachedMethods, AttachedMethodsWide } from \"../types/types.ts\";\nimport type { Prettify } from \"../types/utilities-types.ts\";\n\ntype OptionsInput<T> =\n T extends Record<string, Option> ? { [OptionName in keyof T]: Option<T[OptionName][\"schema\"]> } : T;\n\ntype ArgumentsInput<T> =\n T extends Record<string, Argument> ? { [ArgumentName in keyof T]: Argument<T[ArgumentName][\"schema\"]> } : T;\n\n// This will prevent extra keys and enable jsdoc on hover\ntype SubcommandInput<T extends Subcommand> = {\n [K in keyof T]: K extends keyof Subcommand\n ? K extends \"options\"\n ? OptionsInput<T[K]>\n : K extends \"arguments\"\n ? ArgumentsInput<T[K]>\n : T[K]\n : never;\n};\n\nexport function defineSubcommand<T extends Subcommand>(input: SubcommandInput<T> & Subcommand) {\n const subcommandSchema = input as Prettify<T & AttachedMethods<T>>;\n\n prepareDefinitionTypes(subcommandSchema.options);\n prepareDefinitionTypes(subcommandSchema.arguments);\n\n const onExecute = (handler: (Subcommand[\"_onExecute\"] & {})[number]) => {\n subcommandSchema._onExecute ??= [];\n subcommandSchema._onExecute.push(handler);\n\n return () => {\n const handlerIndex = subcommandSchema._onExecute?.indexOf(handler);\n if (!handlerIndex || handlerIndex < 0) return;\n subcommandSchema._onExecute?.splice(handlerIndex, 1);\n };\n };\n\n const execute: AttachedMethodsWide[\"execute\"] = inputValues => {\n inputValues ??= {};\n if (!subcommandSchema._onExecute) throw new Error(\"Action is not defined\");\n const context = buildObjectContext(inputValues, subcommandSchema);\n const validateResult = validate(context, subcommandSchema);\n\n if (subcommandSchema._onExecute) {\n for (const handler of subcommandSchema._onExecute) {\n handler(validateResult);\n }\n }\n };\n\n return Object.assign(subcommandSchema, { onExecute, execute });\n}\n"],"mappings":"OAASA,uBAA0B,oDAC1BC,aAAgB,iDAChBC,2BAA8B,kBAuBhC,SAASC,iBAAuCC,GACrD,MAAMC,EAAmBD,EAEzBF,uBAAuBG,EAAiBC,SACxCJ,uBAAuBG,EAAiBE,WA0BxC,OAAOC,OAAOC,OAAOJ,EAAkB,CAAEK,UAxBtBC,IACjBN,EAAiBO,aAAjBP,EAAiBO,WAAe,IAChCP,EAAiBO,WAAWC,KAAKF,GAE1B,KACL,MAAMG,EAAeT,EAAiBO,YAAYG,QAAQJ,IACrDG,GAAgBA,EAAe,GACpCT,EAAiBO,YAAYI,OAAOF,EAAc,KAiBFG,QAbJC,IAE9C,GADAA,MAAgB,CAAC,IACZb,EAAiBO,WAAY,MAAM,IAAIO,MAAM,yBAClD,MAAMC,EAAUpB,mBAAmBkB,EAAab,GAC1CgB,EAAiBpB,SAASmB,EAASf,GAEzC,GAAIA,EAAiBO,WACnB,UAAWD,KAAWN,EAAiBO,WACrCD,EAAQU,KAMhB,Q","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/definitions/define-subcommand.ts"],
4
+ "sourcesContent": ["import { CliError } from \"../cli-error/cli-error.ts\";\nimport { ErrorCause } from \"../cli-error/error-cause.ts\";\nimport { DefinitionErrorCode } from \"../cli-error/error-code/definition-error-code.ts\";\nimport { buildObjectContext } from \"../parse/context/object-context-builder.ts\";\nimport { validate } from \"../parse/validation/validate-context.ts\";\nimport { prepareDefinitionTypes } from \"../utilities/schema-utilities.ts\";\n\nimport type { Argument, Option, Subcommand } from \"../types/definitions-types.ts\";\nimport type { AttachedMethods, AttachedMethodsWide } from \"../types/types.ts\";\nimport type { Prettify } from \"../types/utilities-types.ts\";\n\ntype OptionsInput<T> =\n T extends Record<string, Option> ? { [OptionName in keyof T]: Option<T[OptionName][\"schema\"]> } : T;\n\ntype ArgumentsInput<T> =\n T extends Record<string, Argument> ? { [ArgumentName in keyof T]: Argument<T[ArgumentName][\"schema\"]> } : T;\n\n// This will prevent extra keys and enable jsdoc on hover\ntype SubcommandInput<T extends Subcommand> = {\n [K in keyof T]: K extends keyof Subcommand\n ? K extends \"options\"\n ? OptionsInput<T[K]>\n : K extends \"arguments\"\n ? ArgumentsInput<T[K]>\n : T[K]\n : never;\n};\n\nexport function defineSubcommand<T extends Subcommand>(input: SubcommandInput<T> & Subcommand) {\n const subcommandDefinition = input as T;\n\n prepareDefinitionTypes(subcommandDefinition.options);\n prepareDefinitionTypes(subcommandDefinition.arguments);\n\n const onExecute = (handler: (Subcommand[\"_onExecute\"] & {})[number]) => {\n subcommandDefinition._onExecute ??= [];\n subcommandDefinition._onExecute.push(handler);\n\n return () => {\n const handlerIndex = subcommandDefinition._onExecute?.indexOf(handler);\n if (!handlerIndex || handlerIndex < 0) return;\n subcommandDefinition._onExecute?.splice(handlerIndex, 1);\n };\n };\n\n const execute: AttachedMethodsWide[\"execute\"] = inputValues => {\n inputValues ??= {};\n\n const handlers = subcommandDefinition._onExecute;\n\n if (!handlers) {\n throw new CliError({\n cause: ErrorCause.Definition,\n code: DefinitionErrorCode.MissingOnExecute,\n context: { commandKind: \"subcommand\", commandName: subcommandDefinition.name },\n });\n }\n\n const context = buildObjectContext(inputValues, subcommandDefinition);\n const validateResult = validate(context, subcommandDefinition);\n\n for (const handler of handlers) {\n void handler(validateResult);\n }\n };\n\n const executeAsync: AttachedMethodsWide[\"executeAsync\"] = async inputValues => {\n inputValues ??= {};\n\n const handlers = subcommandDefinition._onExecute;\n\n if (!handlers) {\n throw new CliError({\n cause: ErrorCause.Definition,\n code: DefinitionErrorCode.MissingOnExecute,\n context: { commandKind: \"subcommand\", commandName: subcommandDefinition.name },\n });\n }\n\n const context = buildObjectContext(inputValues, subcommandDefinition);\n const validateResult = validate(context, subcommandDefinition);\n\n await Promise.all(handlers.map(async handler => await handler(validateResult)));\n };\n\n return Object.assign(subcommandDefinition, { onExecute, execute, executeAsync }) as Prettify<T & AttachedMethods<T>>;\n}\n"],
5
+ "mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,gBAAgB;AACzB,SAAS,8BAA8B;AAuBhC,SAAS,iBAAuC,OAAwC;AAC7F,QAAM,uBAAuB;AAE7B,yBAAuB,qBAAqB,OAAO;AACnD,yBAAuB,qBAAqB,SAAS;AAErD,QAAM,YAAY,CAAC,YAAqD;AACtE,yBAAqB,eAAe,CAAC;AACrC,yBAAqB,WAAW,KAAK,OAAO;AAE5C,WAAO,MAAM;AACX,YAAM,eAAe,qBAAqB,YAAY,QAAQ,OAAO;AACrE,UAAI,CAAC,gBAAgB,eAAe,EAAG;AACvC,2BAAqB,YAAY,OAAO,cAAc,CAAC;AAAA,IACzD;AAAA,EACF;AAEA,QAAM,UAA0C,iBAAe;AAC7D,oBAAgB,CAAC;AAEjB,UAAM,WAAW,qBAAqB;AAEtC,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS,EAAE,aAAa,cAAc,aAAa,qBAAqB,KAAK;AAAA,MAC/E,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,mBAAmB,aAAa,oBAAoB;AACpE,UAAM,iBAAiB,SAAS,SAAS,oBAAoB;AAE7D,eAAW,WAAW,UAAU;AAC9B,WAAK,QAAQ,cAAc;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,eAAoD,OAAM,gBAAe;AAC7E,oBAAgB,CAAC;AAEjB,UAAM,WAAW,qBAAqB;AAEtC,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,SAAS;AAAA,QACjB,OAAO,WAAW;AAAA,QAClB,MAAM,oBAAoB;AAAA,QAC1B,SAAS,EAAE,aAAa,cAAc,aAAa,qBAAqB,KAAK;AAAA,MAC/E,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,mBAAmB,aAAa,oBAAoB;AACpE,UAAM,iBAAiB,SAAS,SAAS,oBAAoB;AAE7D,UAAM,QAAQ,IAAI,SAAS,IAAI,OAAM,YAAW,MAAM,QAAQ,cAAc,CAAC,CAAC;AAAA,EAChF;AAEA,SAAO,OAAO,OAAO,sBAAsB,EAAE,WAAW,SAAS,aAAa,CAAC;AACjF;",
6
+ "names": []
7
+ }
@@ -1,2 +1,360 @@
1
- import{transformOptionToArgument}from"../parse/parser-utilities.js";import{findDuplicateStrings}from"../utilities.js";function validateCliDefinition(t){if(!t.cliName)throw new Error('invalid cli definition: "cliName" property is required.');validateOptions(t),validateArguments(t);const i=t.subcommands;if(!i)return;if(0===i.length)throw new Error(`invalid cli definition "${t.cliName}": "subcommands" property is optional but cannot be empty.`);const n=i.map(t=>t.name);if(n.some(t=>!t))throw new Error('invalid subcommand definition: subcommand\'s "name" property is required.');const e=findDuplicateStrings(n).map(t=>`"${t}"`);if(e.length>0)throw new Error(`invalid cli definition "${t.cliName}" has duplicated subcommands: ${e.join(", ")}.`);for(const t of i){if(t.aliases){const e=findDuplicateStrings(t.aliases).map(t=>`"${t}"`);if(e.length>0)throw new Error(`subcommand "${t.name}" has duplicated aliases: ${e.join(", ")}.`);for(const e of t.aliases){if(""===e)throw new Error(`subcommand "${t.name}" has an empty string alias.`);if(n.includes(e))throw new Error(`subcommand "${t.name}" alias "${e}" conflicts with another subcommand name.`);const o=i.filter(i=>i.name!==t.name&&i.aliases?.includes(e));if(o.length>0)throw new Error(`subcommand "${t.name}" alias "${e}" conflicts with another subcommand alias: "${o[0].name}".`)}}validateOptions(t),validateArguments(t)}}function validateOptions(t){if(!t.options)return;const i="cliName"in t,n=i?t.cliName:t.name,e=t=>new Error(`invalid ${i?"cli":"subcommand"} definition "${n}": ${t}`),o=Object.entries(t.options);if(0===o.length)throw e('"options" property is optional but cannot be empty.');for(const[i,n]of o){if(!n.schema)throw e(`the option "${i}" missing a required property: "schema".`);if(!n._preparedType)throw e(`internal error: missing prepared type for option "${i}".`);if(isNegatedOptionName(i))throw e(`the option "${i}" is a negated option name.`);if(t.arguments&&i in t.arguments)throw e(`the option "${i}" name conflicts with an argument name.`);if(n.aliases){const r=findDuplicateStrings(n.aliases);if(r.length>0)throw e(`the option "${i}" has duplicated aliases: ${r.join(", ")}.`);for(const r of n.aliases){if(""===r)throw e(`the option "${i}" has an empty string alias.`);if(isNegatedOptionName(r))throw e(`the alias "${r}" of the option "${i}" is a negated option name.`);if(t.options[r])throw e(`the alias "${r}" of the option "${i}" conflicts with another option name.`);if(t.arguments&&r in t.arguments)throw e(`the alias "${r}" of the option "${i}" conflicts with an argument name.`);const n=o.find(([t,n])=>t!==i&&n.aliases?.includes(r));if(n)throw e(`the alias "${r}" of the option "${i}" conflicts with another alias name of the option "${n[0]}".`)}}if(n.requires){if(n.requires.includes(i))throw e(`the option "${i}" cannot require itself.`);const o=findDuplicateStrings(n.requires).map(t=>`"${t}"`);if(o.length>0)throw e(`the option "${i}" has duplicate requires: ${o.join(", ")}.`);for(const o of n.requires){if(!(o in t.options||o in(t.arguments??[])))throw e(`the option "${i}" requires "${o}", but it does not exist.`)}}if(n.conflictWith){if(n.conflictWith.includes(i))throw e(`the option "${i}" cannot conflict itself.`);const o=findDuplicateStrings(n.conflictWith).map(t=>`"${t}"`);if(o.length>0)throw e(`the option "${i}" has duplicate conflicts: ${o.join(", ")}.`);for(const o of n.conflictWith){if(!(o in t.options||o in(t.arguments??[])))throw e(`the option "${i}" conflict with "${o}", but it does not exist.`)}}if(n.requires&&n.conflictWith){const t=new Set(n.requires),o=new Set(n.conflictWith),r=t.intersection(o),a=Array.from(r).map(t=>`"${t}"`);if(a.length>0){const t=a.length>1?"s":"";throw e(`the option "${i}" cannot require and conflict with the same name${t}: ${a.join(", ")}.`)}}}}function validateArguments(t){if(!t.arguments)return;const i="cliName"in t,n=i?t.cliName:t.name,e=t=>new Error(`invalid ${i?"cli":"subcommand"} definition "${n}": ${t}`);if(t.arguments){const i=Object.entries(t.arguments);if(0===i.length)throw e('"arguments" property is optional but cannot be empty.');for(const[n,[o,r]]of i.entries()){if(/^\d+$/.test(o))throw e(`the argument "${o}" name cannot be a number.`);if(!r._preparedType)throw e(`internal error: missing prepared type for argument "${o}".`);if(!r.schema)throw e(`the argument "${o}" missing a required property: "schema".`);if(t.options&&o in t.options)throw e(`the argument "${o}" name conflicts with an option name.`);if(r._preparedType.optional){if(t.allowPositionals)throw e(`the argument "${o}" cannot be optional when "allowPositionals" is enabled.`);if(n!==i.length-1)throw e(`the argument "${o}" cannot be optional unless it is the last argument.`);if(r.requires){if(r.requires.includes(o))throw e(`the argument "${o}" cannot require itself.`);const i=findDuplicateStrings(r.requires).map(t=>`"${t}"`);if(i.length>0)throw e(`the argument "${o}" has duplicate requires: ${i.join(", ")}.`);for(const i of r.requires){if(!(i in(t.options??{})||i in t.arguments))throw e(`the argument "${o}" requires "${i}", but it does not exist.`)}}if(r.conflictWith){if(r.conflictWith.includes(o))throw e(`the argument "${o}" cannot conflict itself.`);const i=findDuplicateStrings(r.conflictWith).map(t=>`"${t}"`);if(i.length>0)throw e(`the argument "${o}" has duplicate conflicts: ${i.join(", ")}.`);for(const i of r.conflictWith){if(!(i in(t.options??{})||i in t.arguments))throw e(`the argument "${o}" conflict with "${i}", but it does not exist.`)}}if(r.requires&&r.conflictWith){const t=new Set(r.requires),i=new Set(r.conflictWith),n=t.intersection(i),a=Array.from(n).map(t=>`"${t}"`);if(a.length>0){throw e(`the argument "${o}" cannot require and conflict with the same name${a.length>1?"s":""}: ${a.join(", ")}.`)}}}}}}function isNegatedOptionName(t){return transformOptionToArgument(t).startsWith("--no-")}export{validateCliDefinition};
2
- //# sourceMappingURL=validate-cli-definition.js.map
1
+ // src/definitions/validate-cli-definition.ts
2
+ import { CliError } from "../cli-error/cli-error.js";
3
+ import { ErrorCause } from "../cli-error/error-cause.js";
4
+ import { DefinitionErrorCode } from "../cli-error/error-code/definition-error-code.js";
5
+ import { InternalErrorCode } from "../cli-error/error-code/internal-error-code.js";
6
+ import { transformOptionToArgument } from "../parse/parser-utilities.js";
7
+ function validateCliDefinition(cliDefinition) {
8
+ if (!cliDefinition.cliName) {
9
+ throw new CliError({
10
+ cause: ErrorCause.Definition,
11
+ code: DefinitionErrorCode.MissingDefinitionName,
12
+ context: { commandKind: "command" }
13
+ });
14
+ }
15
+ validateOptions(cliDefinition);
16
+ validateArguments(cliDefinition);
17
+ const subcommands = cliDefinition.subcommands;
18
+ if (!subcommands) return;
19
+ if (subcommands.length === 0) {
20
+ throw new CliError({
21
+ cause: ErrorCause.Definition,
22
+ code: DefinitionErrorCode.EmptyDefinitionGroup,
23
+ context: { commandKind: "command", commandName: cliDefinition.cliName, kind: "subcommands" }
24
+ });
25
+ }
26
+ const commandsNames = new Set(subcommands.map((c) => c.name));
27
+ const visitedSubcommandNames = /* @__PURE__ */ new Set();
28
+ for (const subcommand of subcommands) {
29
+ if (!subcommand.name) {
30
+ throw new CliError({
31
+ cause: ErrorCause.Definition,
32
+ code: DefinitionErrorCode.MissingDefinitionName,
33
+ context: { commandKind: "subcommand" }
34
+ });
35
+ }
36
+ if (visitedSubcommandNames.has(subcommand.name)) {
37
+ throw new CliError({
38
+ cause: ErrorCause.Definition,
39
+ code: DefinitionErrorCode.DuplicateDefinitionName,
40
+ context: {
41
+ commandKind: "command",
42
+ commandName: cliDefinition.cliName,
43
+ kind: "subcommand",
44
+ name: subcommand.name,
45
+ foundInKind: "subcommand"
46
+ }
47
+ });
48
+ }
49
+ visitedSubcommandNames.add(subcommand.name);
50
+ if (subcommand.aliases) {
51
+ for (const alias of subcommand.aliases) {
52
+ if (alias === "") {
53
+ throw new CliError({
54
+ cause: ErrorCause.Definition,
55
+ code: DefinitionErrorCode.EmptyStringAliasName,
56
+ context: { commandKind: "subcommand", commandName: subcommand.name }
57
+ });
58
+ }
59
+ if (commandsNames.has(alias)) {
60
+ throw new CliError({
61
+ cause: ErrorCause.Definition,
62
+ code: DefinitionErrorCode.DuplicateDefinitionName,
63
+ context: {
64
+ commandKind: "command",
65
+ commandName: cliDefinition.cliName,
66
+ kind: "subcommand",
67
+ name: subcommand.name,
68
+ foundInKind: "subcommand",
69
+ duplicatedAlias: alias
70
+ }
71
+ });
72
+ }
73
+ const aliasConflicts = subcommands.filter((c) => c.name !== subcommand.name && c.aliases?.includes(alias));
74
+ if (aliasConflicts.length > 0) {
75
+ throw new CliError({
76
+ cause: ErrorCause.Definition,
77
+ code: DefinitionErrorCode.DuplicateDefinitionName,
78
+ context: {
79
+ commandKind: "command",
80
+ commandName: cliDefinition.cliName,
81
+ kind: "subcommand",
82
+ name: subcommand.name,
83
+ foundInKind: "subcommand",
84
+ duplicatedAlias: alias,
85
+ foundInName: aliasConflicts[0].name
86
+ }
87
+ });
88
+ }
89
+ }
90
+ }
91
+ validateOptions(subcommand);
92
+ validateArguments(subcommand);
93
+ }
94
+ }
95
+ function validateOptions(commandDefinition) {
96
+ if (!commandDefinition.options) return;
97
+ const isCli = "cliName" in commandDefinition;
98
+ const commandName = isCli ? commandDefinition.cliName : commandDefinition.name;
99
+ const commandKind = isCli ? "command" : "subcommand";
100
+ const optionsDefinitionEntries = Object.entries(commandDefinition.options);
101
+ if (optionsDefinitionEntries.length === 0) {
102
+ throw new CliError({
103
+ cause: ErrorCause.Definition,
104
+ code: DefinitionErrorCode.EmptyDefinitionGroup,
105
+ context: { commandKind, commandName, kind: "option" }
106
+ });
107
+ }
108
+ for (const [name, option] of optionsDefinitionEntries) {
109
+ if (!option.schema) {
110
+ throw new CliError({
111
+ cause: ErrorCause.Definition,
112
+ code: DefinitionErrorCode.MissingSchema,
113
+ context: { commandKind, commandName, kind: "option", name }
114
+ });
115
+ }
116
+ if (!option._preparedType) {
117
+ throw new CliError({
118
+ cause: ErrorCause.Internal,
119
+ code: InternalErrorCode.MissingPreparedTypes,
120
+ context: { commandKind, commandName, kind: "option", name }
121
+ });
122
+ }
123
+ if (isNegatedOptionName(name)) {
124
+ throw new CliError({
125
+ cause: ErrorCause.Definition,
126
+ code: DefinitionErrorCode.InvalidDefinitionOptionName,
127
+ context: { commandKind, commandName, optionName: name }
128
+ });
129
+ }
130
+ if (commandDefinition.arguments && name in commandDefinition.arguments) {
131
+ throw new CliError({
132
+ cause: ErrorCause.Definition,
133
+ code: DefinitionErrorCode.DuplicateDefinitionName,
134
+ context: { commandKind, commandName, kind: "option", name, foundInKind: "argument" }
135
+ });
136
+ }
137
+ if (option.aliases) {
138
+ for (const aliasName of option.aliases) {
139
+ if (aliasName === "") {
140
+ throw new CliError({
141
+ cause: ErrorCause.Definition,
142
+ code: DefinitionErrorCode.EmptyStringAliasName,
143
+ context: { commandKind, commandName, optionName: name }
144
+ });
145
+ }
146
+ if (isNegatedOptionName(aliasName)) {
147
+ throw new CliError({
148
+ cause: ErrorCause.Definition,
149
+ code: DefinitionErrorCode.InvalidDefinitionOptionName,
150
+ context: { commandKind, commandName, optionName: name, negatedAliasName: aliasName }
151
+ });
152
+ }
153
+ if (commandDefinition.options[aliasName]) {
154
+ throw new CliError({
155
+ cause: ErrorCause.Definition,
156
+ code: DefinitionErrorCode.DuplicateDefinitionName,
157
+ context: {
158
+ commandKind,
159
+ commandName,
160
+ kind: "option",
161
+ name,
162
+ duplicatedAlias: aliasName,
163
+ foundInKind: "option"
164
+ }
165
+ });
166
+ }
167
+ if (commandDefinition.arguments && aliasName in commandDefinition.arguments) {
168
+ throw new CliError({
169
+ cause: ErrorCause.Definition,
170
+ code: DefinitionErrorCode.DuplicateDefinitionName,
171
+ context: {
172
+ commandKind,
173
+ commandName,
174
+ kind: "option",
175
+ name,
176
+ duplicatedAlias: aliasName,
177
+ foundInKind: "argument"
178
+ }
179
+ });
180
+ }
181
+ const findConflict = optionsDefinitionEntries.find(([n, d]) => n !== name && d.aliases?.includes(aliasName));
182
+ if (findConflict) {
183
+ throw new CliError({
184
+ cause: ErrorCause.Definition,
185
+ code: DefinitionErrorCode.DuplicateDefinitionName,
186
+ context: {
187
+ commandKind,
188
+ commandName,
189
+ kind: "option",
190
+ name: aliasName,
191
+ foundInKind: "option",
192
+ foundInName: findConflict[0]
193
+ }
194
+ });
195
+ }
196
+ }
197
+ }
198
+ if (option.requires) {
199
+ if (option.requires.includes(name)) {
200
+ throw new CliError({
201
+ cause: ErrorCause.Definition,
202
+ code: DefinitionErrorCode.SelfRequire,
203
+ context: { commandKind, commandName, kind: "option", name }
204
+ });
205
+ }
206
+ for (const requiredName of option.requires) {
207
+ const exits = requiredName in commandDefinition.options || requiredName in (commandDefinition.arguments ?? []);
208
+ if (!exits) {
209
+ throw new CliError({
210
+ cause: ErrorCause.Definition,
211
+ code: DefinitionErrorCode.UnknownRequireName,
212
+ context: { commandKind, commandName, kind: "option", name, requiredName }
213
+ });
214
+ }
215
+ }
216
+ }
217
+ if (option.conflictWith) {
218
+ if (option.conflictWith.includes(name)) {
219
+ throw new CliError({
220
+ cause: ErrorCause.Definition,
221
+ code: DefinitionErrorCode.SelfConflict,
222
+ context: { commandKind, commandName, kind: "option", name }
223
+ });
224
+ }
225
+ for (const requiredName of option.conflictWith) {
226
+ const exits = requiredName in commandDefinition.options || requiredName in (commandDefinition.arguments ?? []);
227
+ if (!exits) {
228
+ throw new CliError({
229
+ cause: ErrorCause.Definition,
230
+ code: DefinitionErrorCode.UnknownConflictName,
231
+ context: { commandKind, commandName, kind: "option", name, requiredName }
232
+ });
233
+ }
234
+ }
235
+ }
236
+ if (option.requires && option.conflictWith) {
237
+ const requiresSet = new Set(option.requires);
238
+ const conflictsSet = new Set(option.conflictWith);
239
+ const intersection = requiresSet.intersection(conflictsSet);
240
+ const intersectedNames = Array.from(intersection).map((name2) => `"${name2}"`);
241
+ if (intersectedNames.length > 0) {
242
+ throw new CliError({
243
+ cause: ErrorCause.Definition,
244
+ code: DefinitionErrorCode.DefinitionRequiresConflictOverlap,
245
+ context: { commandKind, commandName, kind: "option", name, intersectedNames }
246
+ });
247
+ }
248
+ }
249
+ }
250
+ }
251
+ function validateArguments(commandDefinition) {
252
+ if (!commandDefinition.arguments) return;
253
+ const isCli = "cliName" in commandDefinition;
254
+ const commandName = isCli ? commandDefinition.cliName : commandDefinition.name;
255
+ const commandKind = isCli ? "command" : "subcommand";
256
+ const argumentsDefinitionEntries = Object.entries(commandDefinition.arguments);
257
+ if (argumentsDefinitionEntries.length === 0) {
258
+ throw new CliError({
259
+ cause: ErrorCause.Definition,
260
+ code: DefinitionErrorCode.EmptyDefinitionGroup,
261
+ context: { commandKind, commandName, kind: "argument" }
262
+ });
263
+ }
264
+ for (const [index, [name, argument]] of argumentsDefinitionEntries.entries()) {
265
+ if (/^\d+$/.test(name)) {
266
+ throw new CliError({
267
+ cause: ErrorCause.Definition,
268
+ code: DefinitionErrorCode.InvalidDefinitionArgumentName,
269
+ context: { commandKind, commandName, name }
270
+ });
271
+ }
272
+ if (!argument._preparedType) {
273
+ throw new CliError({
274
+ cause: ErrorCause.Internal,
275
+ code: InternalErrorCode.MissingPreparedTypes,
276
+ context: { commandKind, commandName, kind: "argument", name }
277
+ });
278
+ }
279
+ if (!argument.schema) {
280
+ throw new CliError({
281
+ cause: ErrorCause.Definition,
282
+ code: DefinitionErrorCode.MissingSchema,
283
+ context: { commandKind, commandName, kind: "argument", name }
284
+ });
285
+ }
286
+ if (!argument._preparedType.optional) continue;
287
+ if (commandDefinition.allowPositionals) {
288
+ throw new CliError({
289
+ cause: ErrorCause.Definition,
290
+ code: DefinitionErrorCode.InvalidOptionalArgumentDefinition,
291
+ context: { commandKind, commandName, name, allowPositionals: true }
292
+ });
293
+ }
294
+ if (index !== argumentsDefinitionEntries.length - 1) {
295
+ throw new CliError({
296
+ cause: ErrorCause.Definition,
297
+ code: DefinitionErrorCode.InvalidOptionalArgumentDefinition,
298
+ context: { commandKind, commandName, name, allowPositionals: false }
299
+ });
300
+ }
301
+ if (argument.requires) {
302
+ if (argument.requires.includes(name)) {
303
+ throw new CliError({
304
+ cause: ErrorCause.Definition,
305
+ code: DefinitionErrorCode.SelfRequire,
306
+ context: { commandKind, commandName, kind: "argument", name }
307
+ });
308
+ }
309
+ for (const requiredName of argument.requires) {
310
+ const exits = requiredName in (commandDefinition.options ?? {}) || requiredName in commandDefinition.arguments;
311
+ if (!exits) {
312
+ throw new CliError({
313
+ cause: ErrorCause.Definition,
314
+ code: DefinitionErrorCode.UnknownRequireName,
315
+ context: { commandKind, commandName, kind: "argument", name, requiredName }
316
+ });
317
+ }
318
+ }
319
+ }
320
+ if (argument.conflictWith) {
321
+ if (argument.conflictWith.includes(name)) {
322
+ throw new CliError({
323
+ cause: ErrorCause.Definition,
324
+ code: DefinitionErrorCode.SelfConflict,
325
+ context: { commandKind, commandName, kind: "argument", name }
326
+ });
327
+ }
328
+ for (const requiredName of argument.conflictWith) {
329
+ const exits = requiredName in (commandDefinition.options ?? {}) || requiredName in commandDefinition.arguments;
330
+ if (!exits) {
331
+ throw new CliError({
332
+ cause: ErrorCause.Definition,
333
+ code: DefinitionErrorCode.UnknownConflictName,
334
+ context: { commandKind, commandName, kind: "argument", name, requiredName }
335
+ });
336
+ }
337
+ }
338
+ }
339
+ if (argument.requires && argument.conflictWith) {
340
+ const requiresSet = new Set(argument.requires);
341
+ const conflictsSet = new Set(argument.conflictWith);
342
+ const intersection = requiresSet.intersection(conflictsSet);
343
+ const intersectedNames = Array.from(intersection).map((name2) => `"${name2}"`);
344
+ if (intersectedNames.length > 0) {
345
+ throw new CliError({
346
+ cause: ErrorCause.Definition,
347
+ code: DefinitionErrorCode.DefinitionRequiresConflictOverlap,
348
+ context: { commandKind, commandName, kind: "argument", name, intersectedNames }
349
+ });
350
+ }
351
+ }
352
+ }
353
+ }
354
+ function isNegatedOptionName(name) {
355
+ return transformOptionToArgument(name).startsWith("--no-");
356
+ }
357
+ export {
358
+ validateCliDefinition
359
+ };
360
+ //# sourceMappingURL=validate-cli-definition.js.map