track-cli 3.0.0-rc

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 (224) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +3 -0
  3. package/esm/_dnt.polyfills.d.ts +6 -0
  4. package/esm/_dnt.polyfills.js +1 -0
  5. package/esm/_dnt.shims.d.ts +19 -0
  6. package/esm/_dnt.shims.js +78 -0
  7. package/esm/deps/deno.land/std@0.170.0/fmt/colors.d.ts +270 -0
  8. package/esm/deps/deno.land/std@0.170.0/fmt/colors.js +473 -0
  9. package/esm/deps/deno.land/std@0.195.0/_util/os.d.ts +4 -0
  10. package/esm/deps/deno.land/std@0.195.0/_util/os.js +18 -0
  11. package/esm/deps/deno.land/std@0.195.0/assert/assert.d.ts +2 -0
  12. package/esm/deps/deno.land/std@0.195.0/assert/assert.js +8 -0
  13. package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.d.ts +4 -0
  14. package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.js +12 -0
  15. package/esm/deps/deno.land/std@0.195.0/datetime/_common.d.ts +50 -0
  16. package/esm/deps/deno.land/std@0.195.0/datetime/_common.js +545 -0
  17. package/esm/deps/deno.land/std@0.195.0/datetime/constants.d.ts +55 -0
  18. package/esm/deps/deno.land/std@0.195.0/datetime/constants.js +57 -0
  19. package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.d.ts +26 -0
  20. package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.js +45 -0
  21. package/esm/deps/deno.land/std@0.195.0/datetime/difference.d.ts +38 -0
  22. package/esm/deps/deno.land/std@0.195.0/datetime/difference.js +93 -0
  23. package/esm/deps/deno.land/std@0.195.0/datetime/format.d.ts +22 -0
  24. package/esm/deps/deno.land/std@0.195.0/datetime/format.js +28 -0
  25. package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.d.ts +49 -0
  26. package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.js +60 -0
  27. package/esm/deps/deno.land/std@0.195.0/datetime/mod.d.ts +43 -0
  28. package/esm/deps/deno.land/std@0.195.0/datetime/mod.js +45 -0
  29. package/esm/deps/deno.land/std@0.195.0/datetime/parse.d.ts +21 -0
  30. package/esm/deps/deno.land/std@0.195.0/datetime/parse.js +29 -0
  31. package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.d.ts +17 -0
  32. package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.js +44 -0
  33. package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.d.ts +13 -0
  34. package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.js +38 -0
  35. package/esm/deps/deno.land/std@0.195.0/fmt/colors.d.ts +270 -0
  36. package/esm/deps/deno.land/std@0.195.0/fmt/colors.js +474 -0
  37. package/esm/deps/deno.land/std@0.195.0/fmt/duration.d.ts +15 -0
  38. package/esm/deps/deno.land/std@0.195.0/fmt/duration.js +96 -0
  39. package/esm/deps/deno.land/std@0.195.0/fs/_util.d.ts +35 -0
  40. package/esm/deps/deno.land/std@0.195.0/fs/_util.js +80 -0
  41. package/esm/deps/deno.land/std@0.195.0/fs/copy.d.ts +51 -0
  42. package/esm/deps/deno.land/std@0.195.0/fs/copy.js +244 -0
  43. package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.d.ts +31 -0
  44. package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.js +74 -0
  45. package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.d.ts +27 -0
  46. package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.js +55 -0
  47. package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.d.ts +33 -0
  48. package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.js +75 -0
  49. package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.d.ts +31 -0
  50. package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.js +43 -0
  51. package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.d.ts +17 -0
  52. package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.js +68 -0
  53. package/esm/deps/deno.land/std@0.195.0/fs/eol.d.ts +40 -0
  54. package/esm/deps/deno.land/std@0.195.0/fs/eol.js +53 -0
  55. package/esm/deps/deno.land/std@0.195.0/fs/exists.d.ts +102 -0
  56. package/esm/deps/deno.land/std@0.195.0/fs/exists.js +163 -0
  57. package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.d.ts +37 -0
  58. package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.js +216 -0
  59. package/esm/deps/deno.land/std@0.195.0/fs/mod.d.ts +16 -0
  60. package/esm/deps/deno.land/std@0.195.0/fs/mod.js +17 -0
  61. package/esm/deps/deno.land/std@0.195.0/fs/move.d.ts +29 -0
  62. package/esm/deps/deno.land/std@0.195.0/fs/move.js +88 -0
  63. package/esm/deps/deno.land/std@0.195.0/fs/walk.d.ts +40 -0
  64. package/esm/deps/deno.land/std@0.195.0/fs/walk.js +158 -0
  65. package/esm/deps/deno.land/std@0.195.0/path/_constants.d.ts +39 -0
  66. package/esm/deps/deno.land/std@0.195.0/path/_constants.js +46 -0
  67. package/esm/deps/deno.land/std@0.195.0/path/_interface.d.ts +26 -0
  68. package/esm/deps/deno.land/std@0.195.0/path/_interface.js +3 -0
  69. package/esm/deps/deno.land/std@0.195.0/path/_util.d.ts +11 -0
  70. package/esm/deps/deno.land/std@0.195.0/path/_util.js +161 -0
  71. package/esm/deps/deno.land/std@0.195.0/path/common.d.ts +13 -0
  72. package/esm/deps/deno.land/std@0.195.0/path/common.js +36 -0
  73. package/esm/deps/deno.land/std@0.195.0/path/glob.d.ts +83 -0
  74. package/esm/deps/deno.land/std@0.195.0/path/glob.js +361 -0
  75. package/esm/deps/deno.land/std@0.195.0/path/mod.d.ts +9 -0
  76. package/esm/deps/deno.land/std@0.195.0/path/mod.js +33 -0
  77. package/esm/deps/deno.land/std@0.195.0/path/posix.d.ts +86 -0
  78. package/esm/deps/deno.land/std@0.195.0/path/posix.js +442 -0
  79. package/esm/deps/deno.land/std@0.195.0/path/separator.d.ts +2 -0
  80. package/esm/deps/deno.land/std@0.195.0/path/separator.js +5 -0
  81. package/esm/deps/deno.land/std@0.195.0/path/win32.d.ts +91 -0
  82. package/esm/deps/deno.land/std@0.195.0/path/win32.js +909 -0
  83. package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.d.ts +1 -0
  84. package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.js +26 -0
  85. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.d.ts +76 -0
  86. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.js +154 -0
  87. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.d.ts +32 -0
  88. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.js +105 -0
  89. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.d.ts +831 -0
  90. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.js +1701 -0
  91. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.d.ts +17 -0
  92. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.js +201 -0
  93. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.d.ts +14 -0
  94. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.js +141 -0
  95. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.d.ts +21 -0
  96. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.js +285 -0
  97. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.d.ts +6 -0
  98. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.js +38 -0
  99. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.d.ts +8 -0
  100. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.js +32 -0
  101. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.d.ts +6 -0
  102. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.js +38 -0
  103. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.d.ts +6 -0
  104. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.js +46 -0
  105. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.d.ts +6 -0
  106. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.js +38 -0
  107. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.d.ts +45 -0
  108. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.js +2 -0
  109. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.d.ts +1 -0
  110. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.js +1 -0
  111. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.d.ts +27 -0
  112. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.js +323 -0
  113. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.d.ts +6 -0
  114. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.js +34 -0
  115. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.d.ts +18 -0
  116. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.js +17 -0
  117. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.d.ts +41 -0
  118. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.js +24 -0
  119. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.d.ts +9 -0
  120. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.js +20 -0
  121. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.d.ts +9 -0
  122. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.js +13 -0
  123. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.d.ts +9 -0
  124. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.js +27 -0
  125. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.d.ts +7 -0
  126. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.js +9 -0
  127. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.d.ts +10 -0
  128. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.js +29 -0
  129. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.d.ts +5 -0
  130. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.js +12 -0
  131. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.d.ts +7 -0
  132. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.js +9 -0
  133. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.d.ts +7 -0
  134. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.js +9 -0
  135. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.d.ts +7 -0
  136. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.js +9 -0
  137. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.d.ts +118 -0
  138. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.js +2 -0
  139. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.d.ts +5 -0
  140. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.js +5 -0
  141. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.d.ts +14 -0
  142. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.js +46 -0
  143. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.d.ts +26 -0
  144. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.js +118 -0
  145. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.d.ts +14 -0
  146. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.js +55 -0
  147. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.d.ts +27 -0
  148. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.js +102 -0
  149. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.d.ts +17 -0
  150. package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.js +75 -0
  151. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.d.ts +60 -0
  152. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.js +117 -0
  153. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.d.ts +18 -0
  154. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.js +106 -0
  155. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.d.ts +10 -0
  156. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.js +157 -0
  157. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.d.ts +24 -0
  158. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.js +9 -0
  159. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.d.ts +33 -0
  160. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.js +402 -0
  161. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.d.ts +3 -0
  162. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.js +11 -0
  163. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.d.ts +3 -0
  164. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.js +9 -0
  165. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.d.ts +3 -0
  166. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.js +9 -0
  167. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.d.ts +3 -0
  168. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.js +4 -0
  169. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.d.ts +59 -0
  170. package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.js +1 -0
  171. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.d.ts +20 -0
  172. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.js +18 -0
  173. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.d.ts +78 -0
  174. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.js +128 -0
  175. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.d.ts +1 -0
  176. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.js +1 -0
  177. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.d.ts +99 -0
  178. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.js +529 -0
  179. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.d.ts +49 -0
  180. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.js +74 -0
  181. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.d.ts +135 -0
  182. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.js +237 -0
  183. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.d.ts +13 -0
  184. package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.js +60 -0
  185. package/esm/package.json +3 -0
  186. package/esm/src/action/add.d.ts +1 -0
  187. package/esm/src/action/add.js +57 -0
  188. package/esm/src/action/clone.d.ts +6 -0
  189. package/esm/src/action/clone.js +108 -0
  190. package/esm/src/action/lang.d.ts +1 -0
  191. package/esm/src/action/lang.js +40 -0
  192. package/esm/src/action/pull.d.ts +1 -0
  193. package/esm/src/action/pull.js +22 -0
  194. package/esm/src/action/remove.d.ts +4 -0
  195. package/esm/src/action/remove.js +67 -0
  196. package/esm/src/action/reset.d.ts +1 -0
  197. package/esm/src/action/reset.js +21 -0
  198. package/esm/src/action/run.d.ts +4 -0
  199. package/esm/src/action/run.js +163 -0
  200. package/esm/src/action/status.d.ts +1 -0
  201. package/esm/src/action/status.js +5 -0
  202. package/esm/src/main.d.ts +2 -0
  203. package/esm/src/main.js +96 -0
  204. package/esm/src/meta.d.ts +3 -0
  205. package/esm/src/meta.js +51 -0
  206. package/esm/src/orca/client.d.ts +20 -0
  207. package/esm/src/orca/client.js +152 -0
  208. package/esm/src/orca/types.d.ts +54 -0
  209. package/esm/src/orca/types.js +12 -0
  210. package/esm/src/shared/config.d.ts +24 -0
  211. package/esm/src/shared/config.js +24 -0
  212. package/esm/src/shared/errors.d.ts +82 -0
  213. package/esm/src/shared/errors.js +228 -0
  214. package/esm/src/shared/file.d.ts +30 -0
  215. package/esm/src/shared/file.js +110 -0
  216. package/esm/src/shared/mod.d.ts +40 -0
  217. package/esm/src/shared/mod.js +383 -0
  218. package/esm/src/shared/types.d.ts +12 -0
  219. package/esm/src/shared/types.js +1 -0
  220. package/esm/src/track/client.d.ts +60 -0
  221. package/esm/src/track/client.js +268 -0
  222. package/esm/src/track/types.d.ts +210 -0
  223. package/esm/src/track/types.js +40 -0
  224. package/package.json +35 -0
@@ -0,0 +1,402 @@
1
+ import { getDefaultValue, getOption, matchWildCardOptions, paramCaseToCamelCase, } from "./_utils.js";
2
+ import { DuplicateOptionError, InvalidOptionError, InvalidOptionValueError, MissingOptionValueError, UnexpectedArgumentAfterVariadicArgumentError, UnexpectedOptionValueError, UnexpectedRequiredArgumentError, UnknownConflictingOptionError, UnknownOptionError, UnknownRequiredOptionError, UnknownTypeError, } from "./_errors.js";
3
+ import { OptionType } from "./deprecated.js";
4
+ import { boolean } from "./types/boolean.js";
5
+ import { number } from "./types/number.js";
6
+ import { string } from "./types/string.js";
7
+ import { validateFlags } from "./_validate_flags.js";
8
+ import { integer } from "./types/integer.js";
9
+ const DefaultTypes = {
10
+ string,
11
+ number,
12
+ integer,
13
+ boolean,
14
+ };
15
+ /**
16
+ * Parse command line arguments.
17
+ * @param argsOrCtx Command line arguments e.g: `Deno.args` or parse context.
18
+ * @param opts Parse options.
19
+ *
20
+ * ```
21
+ * // examples/flags/flags.ts -x 3 -y.z -n5 -abc --beep=boop foo bar baz --deno.land --deno.com -- --cliffy
22
+ * parseFlags(Deno.args);
23
+ * ```
24
+ *
25
+ * Output:
26
+ *
27
+ * ```
28
+ * {
29
+ * flags: {
30
+ * x: "3",
31
+ * y: { z: true },
32
+ * n: "5",
33
+ * a: true,
34
+ * b: true,
35
+ * c: true,
36
+ * beep: "boop",
37
+ * deno: { land: true, com: true }
38
+ * },
39
+ * literal: [ "--cliffy" ],
40
+ * unknown: [ "foo", "bar", "baz" ],
41
+ * stopEarly: false,
42
+ * stopOnUnknown: false
43
+ * }
44
+ * ```
45
+ */
46
+ export function parseFlags(argsOrCtx, opts = {}) {
47
+ let args;
48
+ let ctx;
49
+ if (Array.isArray(argsOrCtx)) {
50
+ ctx = {};
51
+ args = argsOrCtx;
52
+ }
53
+ else {
54
+ ctx = argsOrCtx;
55
+ args = argsOrCtx.unknown;
56
+ argsOrCtx.unknown = [];
57
+ }
58
+ args = args.slice();
59
+ ctx.flags ??= {};
60
+ ctx.literal ??= [];
61
+ ctx.unknown ??= [];
62
+ ctx.stopEarly = false;
63
+ ctx.stopOnUnknown = false;
64
+ opts.dotted ??= true;
65
+ validateOptions(opts);
66
+ const options = parseArgs(ctx, args, opts);
67
+ validateFlags(ctx, opts, options);
68
+ if (opts.dotted) {
69
+ parseDottedOptions(ctx);
70
+ }
71
+ return ctx;
72
+ }
73
+ function validateOptions(opts) {
74
+ opts.flags?.forEach((opt) => {
75
+ opt.depends?.forEach((flag) => {
76
+ if (!opts.flags || !getOption(opts.flags, flag)) {
77
+ throw new UnknownRequiredOptionError(flag, opts.flags ?? []);
78
+ }
79
+ });
80
+ opt.conflicts?.forEach((flag) => {
81
+ if (!opts.flags || !getOption(opts.flags, flag)) {
82
+ throw new UnknownConflictingOptionError(flag, opts.flags ?? []);
83
+ }
84
+ });
85
+ });
86
+ }
87
+ function parseArgs(ctx, args, opts) {
88
+ /** Option name mapping: propertyName -> option.name */
89
+ const optionsMap = new Map();
90
+ let inLiteral = false;
91
+ for (let argsIndex = 0; argsIndex < args.length; argsIndex++) {
92
+ let option;
93
+ let current = args[argsIndex];
94
+ let currentValue;
95
+ let negate = false;
96
+ // literal args after --
97
+ if (inLiteral) {
98
+ ctx.literal.push(current);
99
+ continue;
100
+ }
101
+ else if (current === "--") {
102
+ inLiteral = true;
103
+ continue;
104
+ }
105
+ else if (ctx.stopEarly || ctx.stopOnUnknown) {
106
+ ctx.unknown.push(current);
107
+ continue;
108
+ }
109
+ const isFlag = current.length > 1 && current[0] === "-";
110
+ if (!isFlag) {
111
+ if (opts.stopEarly) {
112
+ ctx.stopEarly = true;
113
+ }
114
+ ctx.unknown.push(current);
115
+ continue;
116
+ }
117
+ const isShort = current[1] !== "-";
118
+ const isLong = isShort ? false : current.length > 3 && current[2] !== "-";
119
+ if (!isShort && !isLong) {
120
+ throw new InvalidOptionError(current, opts.flags ?? []);
121
+ }
122
+ // normalize short flags: -abc => -a -b -c
123
+ if (isShort && current.length > 2 && current[2] !== ".") {
124
+ args.splice(argsIndex, 1, ...splitFlags(current));
125
+ current = args[argsIndex];
126
+ }
127
+ else if (isLong && current.startsWith("--no-")) {
128
+ negate = true;
129
+ }
130
+ // split value: --foo="bar=baz" => --foo bar=baz
131
+ const equalSignIndex = current.indexOf("=");
132
+ if (equalSignIndex !== -1) {
133
+ currentValue = current.slice(equalSignIndex + 1) || undefined;
134
+ current = current.slice(0, equalSignIndex);
135
+ }
136
+ if (opts.flags) {
137
+ option = getOption(opts.flags, current);
138
+ if (!option) {
139
+ const name = current.replace(/^-+/, "");
140
+ option = matchWildCardOptions(name, opts.flags);
141
+ if (!option) {
142
+ if (opts.stopOnUnknown) {
143
+ ctx.stopOnUnknown = true;
144
+ ctx.unknown.push(args[argsIndex]);
145
+ continue;
146
+ }
147
+ throw new UnknownOptionError(current, opts.flags);
148
+ }
149
+ }
150
+ }
151
+ else {
152
+ option = {
153
+ name: current.replace(/^-+/, ""),
154
+ optionalValue: true,
155
+ type: OptionType.STRING,
156
+ };
157
+ }
158
+ if (option.standalone) {
159
+ ctx.standalone = option;
160
+ }
161
+ const positiveName = negate
162
+ ? option.name.replace(/^no-?/, "")
163
+ : option.name;
164
+ const propName = paramCaseToCamelCase(positiveName);
165
+ if (typeof ctx.flags[propName] !== "undefined") {
166
+ if (!opts.flags?.length) {
167
+ option.collect = true;
168
+ }
169
+ else if (!option.collect) {
170
+ throw new DuplicateOptionError(current);
171
+ }
172
+ }
173
+ if (option.type && !option.args?.length) {
174
+ option.args = [{
175
+ type: option.type,
176
+ requiredValue: option.requiredValue,
177
+ optionalValue: option.optionalValue,
178
+ variadic: option.variadic,
179
+ list: option.list,
180
+ separator: option.separator,
181
+ }];
182
+ }
183
+ if (opts.flags?.length && !option.args?.length &&
184
+ typeof currentValue !== "undefined") {
185
+ throw new UnexpectedOptionValueError(option.name, currentValue);
186
+ }
187
+ let optionArgsIndex = 0;
188
+ let inOptionalArg = false;
189
+ const next = () => currentValue ?? args[argsIndex + 1];
190
+ const previous = ctx.flags[propName];
191
+ parseNext(option);
192
+ if (typeof ctx.flags[propName] === "undefined") {
193
+ if (option.args?.[optionArgsIndex]?.requiredValue) {
194
+ throw new MissingOptionValueError(option.name);
195
+ }
196
+ else if (typeof option.default !== "undefined") {
197
+ ctx.flags[propName] = getDefaultValue(option);
198
+ }
199
+ else {
200
+ ctx.flags[propName] = true;
201
+ }
202
+ }
203
+ if (option.value) {
204
+ ctx.flags[propName] = option.value(ctx.flags[propName], previous);
205
+ }
206
+ else if (option.collect) {
207
+ const value = typeof previous !== "undefined"
208
+ ? (Array.isArray(previous) ? previous : [previous])
209
+ : [];
210
+ value.push(ctx.flags[propName]);
211
+ ctx.flags[propName] = value;
212
+ }
213
+ optionsMap.set(propName, option);
214
+ opts.option?.(option, ctx.flags[propName]);
215
+ /** Parse next argument for current option. */
216
+ // deno-lint-ignore no-inner-declarations
217
+ function parseNext(option) {
218
+ if (negate) {
219
+ ctx.flags[propName] = false;
220
+ return;
221
+ }
222
+ else if (!option.args?.length) {
223
+ ctx.flags[propName] = undefined;
224
+ return;
225
+ }
226
+ const arg = option.args[optionArgsIndex];
227
+ if (!arg) {
228
+ const flag = next();
229
+ throw new UnknownOptionError(flag, opts.flags ?? []);
230
+ }
231
+ if (!arg.type) {
232
+ arg.type = OptionType.BOOLEAN;
233
+ }
234
+ if (option.args?.length && !option.type) {
235
+ // make all values required by default
236
+ if ((typeof arg.optionalValue === "undefined" ||
237
+ arg.optionalValue === false) &&
238
+ typeof arg.requiredValue === "undefined") {
239
+ arg.requiredValue = true;
240
+ }
241
+ }
242
+ else {
243
+ // make non boolean value required by default
244
+ if (arg.type !== OptionType.BOOLEAN &&
245
+ (typeof arg.optionalValue === "undefined" ||
246
+ arg.optionalValue === false) &&
247
+ typeof arg.requiredValue === "undefined") {
248
+ arg.requiredValue = true;
249
+ }
250
+ }
251
+ if (!arg.requiredValue) {
252
+ inOptionalArg = true;
253
+ }
254
+ else if (inOptionalArg) {
255
+ throw new UnexpectedRequiredArgumentError(option.name);
256
+ }
257
+ let result;
258
+ let increase = false;
259
+ if (arg.list && hasNext(arg)) {
260
+ const parsed = next()
261
+ .split(arg.separator || ",")
262
+ .map((nextValue) => {
263
+ const value = parseValue(option, arg, nextValue);
264
+ if (typeof value === "undefined") {
265
+ throw new InvalidOptionValueError(option.name, arg.type ?? "?", nextValue);
266
+ }
267
+ return value;
268
+ });
269
+ if (parsed?.length) {
270
+ result = parsed;
271
+ }
272
+ }
273
+ else {
274
+ if (hasNext(arg)) {
275
+ result = parseValue(option, arg, next());
276
+ }
277
+ else if (arg.optionalValue && arg.type === OptionType.BOOLEAN) {
278
+ result = true;
279
+ }
280
+ }
281
+ if (increase && typeof currentValue === "undefined") {
282
+ argsIndex++;
283
+ if (!arg.variadic) {
284
+ optionArgsIndex++;
285
+ }
286
+ else if (option.args[optionArgsIndex + 1]) {
287
+ throw new UnexpectedArgumentAfterVariadicArgumentError(next());
288
+ }
289
+ }
290
+ if (typeof result !== "undefined" &&
291
+ (option.args.length > 1 || arg.variadic)) {
292
+ if (!ctx.flags[propName]) {
293
+ ctx.flags[propName] = [];
294
+ }
295
+ ctx.flags[propName].push(result);
296
+ if (hasNext(arg)) {
297
+ parseNext(option);
298
+ }
299
+ }
300
+ else {
301
+ ctx.flags[propName] = result;
302
+ }
303
+ /** Check if current option should have an argument. */
304
+ function hasNext(arg) {
305
+ if (!option.args?.length) {
306
+ return false;
307
+ }
308
+ const nextValue = currentValue ?? args[argsIndex + 1];
309
+ if (!nextValue) {
310
+ return false;
311
+ }
312
+ if (option.args.length > 1 && optionArgsIndex >= option.args.length) {
313
+ return false;
314
+ }
315
+ if (arg.requiredValue) {
316
+ return true;
317
+ }
318
+ // require optional values to be called with an equal sign: foo=bar
319
+ if (option.equalsSign && arg.optionalValue && !arg.variadic &&
320
+ typeof currentValue === "undefined") {
321
+ return false;
322
+ }
323
+ if (arg.optionalValue || arg.variadic) {
324
+ return nextValue[0] !== "-" ||
325
+ typeof currentValue !== "undefined" ||
326
+ (arg.type === OptionType.NUMBER && !isNaN(Number(nextValue)));
327
+ }
328
+ return false;
329
+ }
330
+ /** Parse argument value. */
331
+ function parseValue(option, arg, value) {
332
+ const result = opts.parse
333
+ ? opts.parse({
334
+ label: "Option",
335
+ type: arg.type || OptionType.STRING,
336
+ name: `--${option.name}`,
337
+ value,
338
+ })
339
+ : parseDefaultType(option, arg, value);
340
+ if (typeof result !== "undefined") {
341
+ increase = true;
342
+ }
343
+ return result;
344
+ }
345
+ }
346
+ }
347
+ return optionsMap;
348
+ }
349
+ function parseDottedOptions(ctx) {
350
+ // convert dotted option keys into nested objects
351
+ ctx.flags = Object.keys(ctx.flags).reduce((result, key) => {
352
+ if (~key.indexOf(".")) {
353
+ key.split(".").reduce((
354
+ // deno-lint-ignore no-explicit-any
355
+ result, subKey, index, parts) => {
356
+ if (index === parts.length - 1) {
357
+ result[subKey] = ctx.flags[key];
358
+ }
359
+ else {
360
+ result[subKey] = result[subKey] ?? {};
361
+ }
362
+ return result[subKey];
363
+ }, result);
364
+ }
365
+ else {
366
+ result[key] = ctx.flags[key];
367
+ }
368
+ return result;
369
+ }, {});
370
+ }
371
+ function splitFlags(flag) {
372
+ flag = flag.slice(1);
373
+ const normalized = [];
374
+ const index = flag.indexOf("=");
375
+ const flags = (index !== -1 ? flag.slice(0, index) : flag).split("");
376
+ if (isNaN(Number(flag[flag.length - 1]))) {
377
+ flags.forEach((val) => normalized.push(`-${val}`));
378
+ }
379
+ else {
380
+ normalized.push(`-${flags.shift()}`);
381
+ if (flags.length) {
382
+ normalized.push(flags.join(""));
383
+ }
384
+ }
385
+ if (index !== -1) {
386
+ normalized[normalized.length - 1] += flag.slice(index);
387
+ }
388
+ return normalized;
389
+ }
390
+ function parseDefaultType(option, arg, value) {
391
+ const type = arg.type || OptionType.STRING;
392
+ const parseType = DefaultTypes[type];
393
+ if (!parseType) {
394
+ throw new UnknownTypeError(type, Object.keys(DefaultTypes));
395
+ }
396
+ return parseType({
397
+ label: "Option",
398
+ type,
399
+ name: `--${option.name}`,
400
+ value,
401
+ });
402
+ }
@@ -0,0 +1,3 @@
1
+ import type { TypeHandler } from "../types.js";
2
+ /** Boolean type handler. Excepts `true`, `false`, `1`, `0` */
3
+ export declare const boolean: TypeHandler<boolean>;
@@ -0,0 +1,11 @@
1
+ import { InvalidTypeError } from "../_errors.js";
2
+ /** Boolean type handler. Excepts `true`, `false`, `1`, `0` */
3
+ export const boolean = (type) => {
4
+ if (~["1", "true"].indexOf(type.value)) {
5
+ return true;
6
+ }
7
+ if (~["0", "false"].indexOf(type.value)) {
8
+ return false;
9
+ }
10
+ throw new InvalidTypeError(type, ["true", "false", "1", "0"]);
11
+ };
@@ -0,0 +1,3 @@
1
+ import type { TypeHandler } from "../types.js";
2
+ /** Integer type handler. Excepts any integer value. */
3
+ export declare const integer: TypeHandler<number>;
@@ -0,0 +1,9 @@
1
+ import { InvalidTypeError } from "../_errors.js";
2
+ /** Integer type handler. Excepts any integer value. */
3
+ export const integer = (type) => {
4
+ const value = Number(type.value);
5
+ if (Number.isInteger(value)) {
6
+ return value;
7
+ }
8
+ throw new InvalidTypeError(type);
9
+ };
@@ -0,0 +1,3 @@
1
+ import type { TypeHandler } from "../types.js";
2
+ /** Number type handler. Excepts any numeric value. */
3
+ export declare const number: TypeHandler<number>;
@@ -0,0 +1,9 @@
1
+ import { InvalidTypeError } from "../_errors.js";
2
+ /** Number type handler. Excepts any numeric value. */
3
+ export const number = (type) => {
4
+ const value = Number(type.value);
5
+ if (Number.isFinite(value)) {
6
+ return value;
7
+ }
8
+ throw new InvalidTypeError(type);
9
+ };
@@ -0,0 +1,3 @@
1
+ import type { TypeHandler } from "../types.js";
2
+ /** String type handler. Excepts any value. */
3
+ export declare const string: TypeHandler<string>;
@@ -0,0 +1,4 @@
1
+ /** String type handler. Excepts any value. */
2
+ export const string = ({ value }) => {
3
+ return value;
4
+ };
@@ -0,0 +1,59 @@
1
+ /** Parser options. */
2
+ export interface ParseFlagsOptions<TFlagOptions extends FlagOptions = FlagOptions> {
3
+ flags?: Array<TFlagOptions>;
4
+ parse?: TypeHandler<unknown>;
5
+ option?: (option: TFlagOptions, value?: unknown) => void;
6
+ stopEarly?: boolean;
7
+ stopOnUnknown?: boolean;
8
+ allowEmpty?: boolean;
9
+ ignoreDefaults?: Record<string, unknown>;
10
+ dotted?: boolean;
11
+ }
12
+ /** Flag options. */
13
+ export interface FlagOptions extends ArgumentOptions {
14
+ name: string;
15
+ args?: ArgumentOptions[];
16
+ aliases?: string[];
17
+ standalone?: boolean;
18
+ default?: DefaultValue;
19
+ required?: boolean;
20
+ depends?: string[];
21
+ conflicts?: string[];
22
+ value?: ValueHandler;
23
+ collect?: boolean;
24
+ equalsSign?: boolean;
25
+ }
26
+ /** Flag argument definition. */
27
+ export interface ArgumentOptions {
28
+ type?: ArgumentType | string;
29
+ optionalValue?: boolean;
30
+ requiredValue?: boolean;
31
+ variadic?: boolean;
32
+ list?: boolean;
33
+ separator?: string;
34
+ }
35
+ /** Available build-in argument types. */
36
+ export type ArgumentType = "string" | "boolean" | "number" | "integer";
37
+ /** Default flag value */
38
+ export type DefaultValue<TValue = unknown> = TValue | DefaultValueHandler<TValue>;
39
+ export type DefaultValueHandler<TValue = unknown> = () => TValue;
40
+ /** Value handler for custom value processing. */
41
+ export type ValueHandler<TValue = any, TReturn = TValue> = (val: TValue, previous?: TReturn) => TReturn;
42
+ /** Result of the parseFlags method. */
43
+ export interface ParseFlagsContext<TFlags extends Record<string, any> = Record<string, any>, TStandaloneOption extends FlagOptions = FlagOptions> {
44
+ flags: TFlags;
45
+ unknown: Array<string>;
46
+ literal: Array<string>;
47
+ standalone?: TStandaloneOption;
48
+ stopEarly: boolean;
49
+ stopOnUnknown: boolean;
50
+ }
51
+ /** Type details. */
52
+ export interface ArgumentValue {
53
+ label: string;
54
+ type: string;
55
+ name: string;
56
+ value: string;
57
+ }
58
+ /** Custom type handler/parser. */
59
+ export type TypeHandler<TReturn = unknown> = (arg: ArgumentValue) => TReturn;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ /** Border characters interface. */
2
+ export interface IBorder {
3
+ top: string;
4
+ topMid: string;
5
+ topLeft: string;
6
+ topRight: string;
7
+ bottom: string;
8
+ bottomMid: string;
9
+ bottomLeft: string;
10
+ bottomRight: string;
11
+ left: string;
12
+ leftMid: string;
13
+ mid: string;
14
+ midMid: string;
15
+ right: string;
16
+ rightMid: string;
17
+ middle: string;
18
+ }
19
+ /** Default border characters. */
20
+ export declare const border: IBorder;
@@ -0,0 +1,18 @@
1
+ /** Default border characters. */
2
+ export const border = {
3
+ top: "─",
4
+ topMid: "┬",
5
+ topLeft: "┌",
6
+ topRight: "┐",
7
+ bottom: "─",
8
+ bottomMid: "┴",
9
+ bottomLeft: "└",
10
+ bottomRight: "┘",
11
+ left: "│",
12
+ leftMid: "├",
13
+ mid: "─",
14
+ midMid: "┼",
15
+ right: "│",
16
+ rightMid: "┤",
17
+ middle: "│",
18
+ };
@@ -0,0 +1,78 @@
1
+ /** Cell type */
2
+ export type ICell = number | string | String | Cell;
3
+ export type Direction = "left" | "right" | "center";
4
+ /** Cell options. */
5
+ export interface ICellOptions {
6
+ border?: boolean;
7
+ colSpan?: number;
8
+ rowSpan?: number;
9
+ align?: Direction;
10
+ }
11
+ /** Cell representation. */
12
+ export declare class Cell {
13
+ private value;
14
+ protected options: ICellOptions;
15
+ /** Get cell length. */
16
+ get length(): number;
17
+ /**
18
+ * Create a new cell. If value is a cell, the value and all options of the cell
19
+ * will be copied to the new cell.
20
+ * @param value Cell or cell value.
21
+ */
22
+ static from(value: ICell): Cell;
23
+ /**
24
+ * Cell constructor.
25
+ * @param value Cell value.
26
+ */
27
+ constructor(value: ICell);
28
+ /** Get cell value. */
29
+ toString(): string;
30
+ /**
31
+ * Set cell value.
32
+ * @param value Cell or cell value.
33
+ */
34
+ setValue(value: ICell): this;
35
+ /**
36
+ * Clone cell with all options.
37
+ * @param value Cell or cell value.
38
+ */
39
+ clone(value?: ICell): Cell;
40
+ /**
41
+ * Setter:
42
+ */
43
+ /**
44
+ * Enable/disable cell border.
45
+ * @param enable Enable/disable cell border.
46
+ * @param override Override existing value.
47
+ */
48
+ border(enable: boolean, override?: boolean): this;
49
+ /**
50
+ * Set col span.
51
+ * @param span Number of cols to span.
52
+ * @param override Override existing value.
53
+ */
54
+ colSpan(span: number, override?: boolean): this;
55
+ /**
56
+ * Set row span.
57
+ * @param span Number of rows to span.
58
+ * @param override Override existing value.
59
+ */
60
+ rowSpan(span: number, override?: boolean): this;
61
+ /**
62
+ * Align cell content.
63
+ * @param direction Align direction.
64
+ * @param override Override existing value.
65
+ */
66
+ align(direction: Direction, override?: boolean): this;
67
+ /**
68
+ * Getter:
69
+ */
70
+ /** Check if cell has border. */
71
+ getBorder(): boolean;
72
+ /** Get col span. */
73
+ getColSpan(): number;
74
+ /** Get row span. */
75
+ getRowSpan(): number;
76
+ /** Get row span. */
77
+ getAlign(): Direction;
78
+ }