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,17 @@
1
+ import type { Command } from "../command.js";
2
+ /** Generates bash completions script. */
3
+ export declare class BashCompletionsGenerator {
4
+ protected cmd: Command;
5
+ /** Generates bash completions script for given command. */
6
+ static generate(cmd: Command): string;
7
+ private constructor();
8
+ /** Generates bash completions code. */
9
+ private generate;
10
+ /** Generates bash completions method for given command and child commands. */
11
+ private generateCompletions;
12
+ private generateCommandCompletions;
13
+ private getFlags;
14
+ private generateOptionArguments;
15
+ private generateCommandCompletionsCommand;
16
+ private generateOptionCompletionsCommand;
17
+ }
@@ -0,0 +1,201 @@
1
+ import { FileType } from "../types/file.js";
2
+ /** Generates bash completions script. */
3
+ export class BashCompletionsGenerator {
4
+ /** Generates bash completions script for given command. */
5
+ static generate(cmd) {
6
+ return new BashCompletionsGenerator(cmd).generate();
7
+ }
8
+ constructor(cmd) {
9
+ Object.defineProperty(this, "cmd", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: cmd
14
+ });
15
+ }
16
+ /** Generates bash completions code. */
17
+ generate() {
18
+ const path = this.cmd.getPath();
19
+ const version = this.cmd.getVersion()
20
+ ? ` v${this.cmd.getVersion()}`
21
+ : "";
22
+ return `#!/usr/bin/env bash
23
+ # bash completion support for ${path}${version}
24
+
25
+ _${replaceSpecialChars(path)}() {
26
+ local word cur prev listFiles
27
+ local -a opts
28
+ COMPREPLY=()
29
+ cur="\${COMP_WORDS[COMP_CWORD]}"
30
+ prev="\${COMP_WORDS[COMP_CWORD-1]}"
31
+ cmd="_"
32
+ opts=()
33
+ listFiles=0
34
+
35
+ _${replaceSpecialChars(this.cmd.getName())}_complete() {
36
+ local action="$1"; shift
37
+ mapfile -t values < <( ${this.cmd.getName()} completions complete "\${action}" "\${@}" )
38
+ for i in "\${values[@]}"; do
39
+ opts+=("$i")
40
+ done
41
+ }
42
+
43
+ _${replaceSpecialChars(this.cmd.getName())}_expand() {
44
+ [ "$cur" != "\${cur%\\\\}" ] && cur="$cur\\\\"
45
+
46
+ # expand ~username type directory specifications
47
+ if [[ "$cur" == \\~*/* ]]; then
48
+ # shellcheck disable=SC2086
49
+ eval cur=$cur
50
+
51
+ elif [[ "$cur" == \\~* ]]; then
52
+ cur=\${cur#\\~}
53
+ # shellcheck disable=SC2086,SC2207
54
+ COMPREPLY=( $( compgen -P '~' -u $cur ) )
55
+ return \${#COMPREPLY[@]}
56
+ fi
57
+ }
58
+
59
+ # shellcheck disable=SC2120
60
+ _${replaceSpecialChars(this.cmd.getName())}_file_dir() {
61
+ listFiles=1
62
+ local IFS=$'\\t\\n' xspec #glob
63
+ _${replaceSpecialChars(this.cmd.getName())}_expand || return 0
64
+
65
+ if [ "\${1:-}" = -d ]; then
66
+ # shellcheck disable=SC2206,SC2207,SC2086
67
+ COMPREPLY=( \${COMPREPLY[@]:-} $( compgen -d -- $cur ) )
68
+ #eval "$glob" # restore glob setting.
69
+ return 0
70
+ fi
71
+
72
+ xspec=\${1:+"!*.$1"} # set only if glob passed in as $1
73
+ # shellcheck disable=SC2206,SC2207
74
+ COMPREPLY=( \${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) \
75
+ $( compgen -d -- "$cur" ) )
76
+ }
77
+
78
+ ${this.generateCompletions(this.cmd).trim()}
79
+
80
+ for word in "\${COMP_WORDS[@]}"; do
81
+ case "\${word}" in
82
+ -*) ;;
83
+ *)
84
+ cmd_tmp="\${cmd}_\${word//[^[:alnum:]]/_}"
85
+ if type "\${cmd_tmp}" &>/dev/null; then
86
+ cmd="\${cmd_tmp}"
87
+ fi
88
+ esac
89
+ done
90
+
91
+ \${cmd}
92
+
93
+ if [[ listFiles -eq 1 ]]; then
94
+ return 0
95
+ fi
96
+
97
+ if [[ \${#opts[@]} -eq 0 ]]; then
98
+ # shellcheck disable=SC2207
99
+ COMPREPLY=($(compgen -f "\${cur}"))
100
+ return 0
101
+ fi
102
+
103
+ local values
104
+ values="$( printf "\\n%s" "\${opts[@]}" )"
105
+ local IFS=$'\\n'
106
+ # shellcheck disable=SC2207
107
+ local result=($(compgen -W "\${values[@]}" -- "\${cur}"))
108
+ if [[ \${#result[@]} -eq 0 ]]; then
109
+ # shellcheck disable=SC2207
110
+ COMPREPLY=($(compgen -f "\${cur}"))
111
+ else
112
+ # shellcheck disable=SC2207
113
+ COMPREPLY=($(printf '%q\\n' "\${result[@]}"))
114
+ fi
115
+
116
+ return 0
117
+ }
118
+
119
+ complete -F _${replaceSpecialChars(path)} -o bashdefault -o default ${path}`;
120
+ }
121
+ /** Generates bash completions method for given command and child commands. */
122
+ generateCompletions(command, path = "", index = 1) {
123
+ path = (path ? path + " " : "") + command.getName();
124
+ const commandCompletions = this.generateCommandCompletions(command, path, index);
125
+ const childCommandCompletions = command.getCommands(false)
126
+ .filter((subCommand) => subCommand !== command)
127
+ .map((subCommand) => this.generateCompletions(subCommand, path, index + 1))
128
+ .join("");
129
+ return `${commandCompletions}
130
+
131
+ ${childCommandCompletions}`;
132
+ }
133
+ generateCommandCompletions(command, path, index) {
134
+ const flags = this.getFlags(command);
135
+ const childCommandNames = command.getCommands(false)
136
+ .map((childCommand) => childCommand.getName());
137
+ const completionsPath = ~path.indexOf(" ")
138
+ ? " " + path.split(" ").slice(1).join(" ")
139
+ : "";
140
+ const optionArguments = this.generateOptionArguments(command, completionsPath);
141
+ const completionsCmd = this.generateCommandCompletionsCommand(command, completionsPath);
142
+ return ` __${replaceSpecialChars(path)}() {
143
+ opts=(${[...flags, ...childCommandNames].join(" ")})
144
+ ${completionsCmd}
145
+ if [[ \${cur} == -* || \${COMP_CWORD} -eq ${index} ]] ; then
146
+ return 0
147
+ fi
148
+ ${optionArguments}
149
+ }`;
150
+ }
151
+ getFlags(command) {
152
+ return command.getOptions(false)
153
+ .map((option) => option.flags)
154
+ .flat();
155
+ }
156
+ generateOptionArguments(command, completionsPath) {
157
+ let opts = "";
158
+ const options = command.getOptions(false);
159
+ if (options.length) {
160
+ opts += 'case "${prev}" in';
161
+ for (const option of options) {
162
+ const flags = option.flags
163
+ .map((flag) => flag.trim())
164
+ .join("|");
165
+ const completionsCmd = this.generateOptionCompletionsCommand(command, option.args, completionsPath, { standalone: option.standalone });
166
+ opts += `\n ${flags}) ${completionsCmd} ;;`;
167
+ }
168
+ opts += "\n esac";
169
+ }
170
+ return opts;
171
+ }
172
+ generateCommandCompletionsCommand(command, path) {
173
+ const args = command.getArguments();
174
+ if (args.length) {
175
+ const type = command.getType(args[0].type);
176
+ if (type && type.handler instanceof FileType) {
177
+ return `_${replaceSpecialChars(this.cmd.getName())}_file_dir`;
178
+ }
179
+ // @TODO: add support for multiple arguments
180
+ return `_${replaceSpecialChars(this.cmd.getName())}_complete ${args[0].action}${path}`;
181
+ }
182
+ return "";
183
+ }
184
+ generateOptionCompletionsCommand(command, args, path, opts) {
185
+ if (args.length) {
186
+ const type = command.getType(args[0].type);
187
+ if (type && type.handler instanceof FileType) {
188
+ return `opts=(); _${replaceSpecialChars(this.cmd.getName())}_file_dir`;
189
+ }
190
+ // @TODO: add support for multiple arguments
191
+ return `opts=(); _${replaceSpecialChars(this.cmd.getName())}_complete ${args[0].action}${path}`;
192
+ }
193
+ if (opts?.standalone) {
194
+ return "opts=()";
195
+ }
196
+ return "";
197
+ }
198
+ }
199
+ function replaceSpecialChars(str) {
200
+ return str.replace(/[^a-zA-Z0-9]/g, "_");
201
+ }
@@ -0,0 +1,14 @@
1
+ import type { Command } from "../command.js";
2
+ /** Fish completions generator. */
3
+ export declare class FishCompletionsGenerator {
4
+ protected cmd: Command;
5
+ /** Generates fish completions script for given command. */
6
+ static generate(cmd: Command): string;
7
+ private constructor();
8
+ /** Generates fish completions script. */
9
+ private generate;
10
+ private generateCompletions;
11
+ private completeOption;
12
+ private complete;
13
+ private getCompletionCommand;
14
+ }
@@ -0,0 +1,141 @@
1
+ import { getDescription } from "../_utils.js";
2
+ import { FileType } from "../types/file.js";
3
+ /** Fish completions generator. */
4
+ export class FishCompletionsGenerator {
5
+ /** Generates fish completions script for given command. */
6
+ static generate(cmd) {
7
+ return new FishCompletionsGenerator(cmd).generate();
8
+ }
9
+ constructor(cmd) {
10
+ Object.defineProperty(this, "cmd", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: cmd
15
+ });
16
+ }
17
+ /** Generates fish completions script. */
18
+ generate() {
19
+ const path = this.cmd.getPath();
20
+ const version = this.cmd.getVersion()
21
+ ? ` v${this.cmd.getVersion()}`
22
+ : "";
23
+ return `#!/usr/bin/env fish
24
+ # fish completion support for ${path}${version}
25
+
26
+ function __fish_${replaceSpecialChars(this.cmd.getName())}_using_command
27
+ set -l cmds ${getCommandFnNames(this.cmd).join(" ")}
28
+ set -l words (commandline -opc)
29
+ set -l cmd "_"
30
+ for word in $words
31
+ switch $word
32
+ case '-*'
33
+ continue
34
+ case '*'
35
+ set word (string replace -r -a '\\W' '_' $word)
36
+ set -l cmd_tmp $cmd"_$word"
37
+ if contains $cmd_tmp $cmds
38
+ set cmd $cmd_tmp
39
+ end
40
+ end
41
+ end
42
+ if test "$cmd" = "$argv[1]"
43
+ return 0
44
+ end
45
+ return 1
46
+ end
47
+
48
+ ${this.generateCompletions(this.cmd).trim()}`;
49
+ }
50
+ generateCompletions(command) {
51
+ const parent = command.getParent();
52
+ let result = ``;
53
+ if (parent) {
54
+ // command
55
+ result += "\n" + this.complete(parent, {
56
+ description: command.getShortDescription(),
57
+ arguments: command.getName(),
58
+ });
59
+ }
60
+ // arguments
61
+ const commandArgs = command.getArguments();
62
+ if (commandArgs.length) {
63
+ result += "\n" + this.complete(command, {
64
+ arguments: commandArgs.length
65
+ ? this.getCompletionCommand(command, commandArgs[0])
66
+ : undefined,
67
+ });
68
+ }
69
+ // options
70
+ for (const option of command.getOptions(false)) {
71
+ result += "\n" + this.completeOption(command, option);
72
+ }
73
+ for (const subCommand of command.getCommands(false)) {
74
+ result += this.generateCompletions(subCommand);
75
+ }
76
+ return result;
77
+ }
78
+ completeOption(command, option) {
79
+ const shortOption = option.flags
80
+ .find((flag) => flag.length === 2)
81
+ ?.replace(/^(-)+/, "");
82
+ const longOption = option.flags
83
+ .find((flag) => flag.length > 2)
84
+ ?.replace(/^(-)+/, "");
85
+ return this.complete(command, {
86
+ description: getDescription(option.description),
87
+ shortOption: shortOption,
88
+ longOption: longOption,
89
+ // required: option.requiredValue,
90
+ required: true,
91
+ standalone: option.standalone,
92
+ arguments: option.args.length
93
+ ? this.getCompletionCommand(command, option.args[0])
94
+ : undefined,
95
+ });
96
+ }
97
+ complete(command, options) {
98
+ const cmd = ["complete"];
99
+ cmd.push("-c", this.cmd.getName());
100
+ cmd.push("-n", `'__fish_${replaceSpecialChars(this.cmd.getName())}_using_command __${replaceSpecialChars(command.getPath())}'`);
101
+ options.shortOption && cmd.push("-s", options.shortOption);
102
+ options.longOption && cmd.push("-l", options.longOption);
103
+ options.standalone && cmd.push("-x");
104
+ cmd.push("-k");
105
+ cmd.push("-f");
106
+ if (options.arguments) {
107
+ options.required && cmd.push("-r");
108
+ cmd.push("-a", options.arguments);
109
+ }
110
+ if (options.description) {
111
+ const description = getDescription(options.description, true)
112
+ // escape single quotes
113
+ .replace(/'/g, "\\'");
114
+ cmd.push("-d", `'${description}'`);
115
+ }
116
+ return cmd.join(" ");
117
+ }
118
+ getCompletionCommand(cmd, arg) {
119
+ const type = cmd.getType(arg.type);
120
+ if (type && type.handler instanceof FileType) {
121
+ return `'(__fish_complete_path)'`;
122
+ }
123
+ return `'(${this.cmd.getName()} completions complete ${arg.action + " " + getCompletionsPath(cmd)})'`;
124
+ }
125
+ }
126
+ function getCommandFnNames(cmd, cmds = []) {
127
+ cmds.push(`__${replaceSpecialChars(cmd.getPath())}`);
128
+ cmd.getCommands(false).forEach((command) => {
129
+ getCommandFnNames(command, cmds);
130
+ });
131
+ return cmds;
132
+ }
133
+ function getCompletionsPath(command) {
134
+ return command.getPath()
135
+ .split(" ")
136
+ .slice(1)
137
+ .join(" ");
138
+ }
139
+ function replaceSpecialChars(str) {
140
+ return str.replace(/[^a-zA-Z0-9]/g, "_");
141
+ }
@@ -0,0 +1,21 @@
1
+ import type { Command } from "../command.js";
2
+ /** Generates zsh completions script. */
3
+ export declare class ZshCompletionsGenerator {
4
+ protected cmd: Command;
5
+ private actions;
6
+ /** Generates zsh completions script for given command. */
7
+ static generate(cmd: Command): string;
8
+ private constructor();
9
+ /** Generates zsh completions code. */
10
+ private generate;
11
+ /** Generates zsh completions method for given command and child commands. */
12
+ private generateCompletions;
13
+ private generateCommandCompletions;
14
+ private generateSubCommandCompletions;
15
+ private generateArgumentCompletions;
16
+ private generateOptions;
17
+ private generateOption;
18
+ private getFileCompletions;
19
+ private addAction;
20
+ private generateActions;
21
+ }
@@ -0,0 +1,285 @@
1
+ import { getDescription } from "../_utils.js";
2
+ import { FileType } from "../types/file.js";
3
+ /** Generates zsh completions script. */
4
+ export class ZshCompletionsGenerator {
5
+ /** Generates zsh completions script for given command. */
6
+ static generate(cmd) {
7
+ return new ZshCompletionsGenerator(cmd).generate();
8
+ }
9
+ constructor(cmd) {
10
+ Object.defineProperty(this, "cmd", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: cmd
15
+ });
16
+ Object.defineProperty(this, "actions", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: new Map()
21
+ });
22
+ }
23
+ /** Generates zsh completions code. */
24
+ generate() {
25
+ const path = this.cmd.getPath();
26
+ const name = this.cmd.getName();
27
+ const version = this.cmd.getVersion()
28
+ ? ` v${this.cmd.getVersion()}`
29
+ : "";
30
+ return `#!/usr/bin/env zsh
31
+ # zsh completion support for ${path}${version}
32
+
33
+ autoload -U is-at-least
34
+
35
+ # shellcheck disable=SC2154
36
+ (( $+functions[__${replaceSpecialChars(name)}_complete] )) ||
37
+ function __${replaceSpecialChars(name)}_complete {
38
+ local name="$1"; shift
39
+ local action="$1"; shift
40
+ integer ret=1
41
+ local -a values
42
+ local expl lines
43
+ _tags "$name"
44
+ while _tags; do
45
+ if _requested "$name"; then
46
+ # shellcheck disable=SC2034
47
+ lines="$(${name} completions complete "\${action}" "\${@}")"
48
+ values=("\${(ps:\\n:)lines}")
49
+ if (( \${#values[@]} )); then
50
+ while _next_label "$name" expl "$action"; do
51
+ compadd -S '' "\${expl[@]}" "\${values[@]}"
52
+ done
53
+ fi
54
+ fi
55
+ done
56
+ }
57
+
58
+ ${this.generateCompletions(this.cmd).trim()}
59
+
60
+ # _${replaceSpecialChars(path)} "\${@}"
61
+
62
+ compdef _${replaceSpecialChars(path)} ${path}`;
63
+ }
64
+ /** Generates zsh completions method for given command and child commands. */
65
+ generateCompletions(command, path = "") {
66
+ if (!command.hasCommands(false) && !command.hasOptions(false) &&
67
+ !command.hasArguments()) {
68
+ return "";
69
+ }
70
+ path = (path ? path + " " : "") + command.getName();
71
+ return `# shellcheck disable=SC2154
72
+ (( $+functions[_${replaceSpecialChars(path)}] )) ||
73
+ function _${replaceSpecialChars(path)}() {` +
74
+ (!command.getParent()
75
+ ? `
76
+ local state`
77
+ : "") +
78
+ this.generateCommandCompletions(command, path) +
79
+ this.generateSubCommandCompletions(command, path) +
80
+ this.generateArgumentCompletions(command, path) +
81
+ this.generateActions(command) +
82
+ `\n}\n\n` +
83
+ command.getCommands(false)
84
+ .filter((subCommand) => subCommand !== command)
85
+ .map((subCommand) => this.generateCompletions(subCommand, path))
86
+ .join("");
87
+ }
88
+ generateCommandCompletions(command, path) {
89
+ const commands = command.getCommands(false);
90
+ let completions = commands
91
+ .map((subCommand) => `'${subCommand.getName()}:${subCommand.getShortDescription()
92
+ // escape single quotes
93
+ .replace(/'/g, "'\"'\"'")}'`)
94
+ .join("\n ");
95
+ if (completions) {
96
+ completions = `
97
+ local -a commands
98
+ # shellcheck disable=SC2034
99
+ commands=(
100
+ ${completions}
101
+ )
102
+ _describe 'command' commands`;
103
+ }
104
+ // only complete first argument, rest arguments are completed with _arguments.
105
+ if (command.hasArguments()) {
106
+ const completionsPath = path.split(" ").slice(1).join(" ");
107
+ const arg = command.getArguments()[0];
108
+ const action = this.addAction(arg, completionsPath);
109
+ if (action && command.getCompletion(arg.action)) {
110
+ completions += `\n __${replaceSpecialChars(this.cmd.getName())}_complete ${action.arg.name} ${action.arg.action} ${action.cmd}`;
111
+ }
112
+ }
113
+ if (completions) {
114
+ completions = `\n\n function _commands() {${completions}\n }`;
115
+ }
116
+ return completions;
117
+ }
118
+ generateSubCommandCompletions(command, path) {
119
+ if (command.hasCommands(false)) {
120
+ const actions = command
121
+ .getCommands(false)
122
+ .map((command) => `${command.getName()}) _${replaceSpecialChars(path + " " + command.getName())} ;;`)
123
+ .join("\n ");
124
+ return `\n
125
+ function _command_args() {
126
+ case "\${words[1]}" in\n ${actions}\n esac
127
+ }`;
128
+ }
129
+ return "";
130
+ }
131
+ generateArgumentCompletions(command, path) {
132
+ /* clear actions from previously parsed command. */
133
+ this.actions.clear();
134
+ const options = this.generateOptions(command, path);
135
+ let argIndex = 0;
136
+ // @TODO: add stop early option: -A "-*"
137
+ // http://zsh.sourceforge.net/Doc/Release/Completion-System.html
138
+ let argsCommand = "\n\n _arguments -w -s -S -C";
139
+ if (command.hasOptions()) {
140
+ argsCommand += ` \\\n ${options.join(" \\\n ")}`;
141
+ }
142
+ if (command.hasCommands(false) || (command.getArguments()
143
+ .filter((arg) => command.getCompletion(arg.action)).length)) {
144
+ argsCommand += ` \\\n '${++argIndex}:command:_commands'`;
145
+ }
146
+ if (command.hasArguments() || command.hasCommands(false)) {
147
+ const args = [];
148
+ // first argument is completed together with commands.
149
+ for (const arg of command.getArguments().slice(1)) {
150
+ const type = command.getType(arg.type);
151
+ if (type && type.handler instanceof FileType) {
152
+ const fileCompletions = this.getFileCompletions(type);
153
+ if (arg.variadic) {
154
+ argIndex++;
155
+ for (let i = 0; i < 5; i++) {
156
+ args.push(`${argIndex + i}${arg.optionalValue ? "::" : ":"}${arg.name}:${fileCompletions}`);
157
+ }
158
+ }
159
+ else {
160
+ args.push(`${++argIndex}${arg.optionalValue ? "::" : ":"}${arg.name}:${fileCompletions}`);
161
+ }
162
+ }
163
+ else {
164
+ const completionsPath = path.split(" ").slice(1).join(" ");
165
+ const action = this.addAction(arg, completionsPath);
166
+ args.push(`${++argIndex}${arg.optionalValue ? "::" : ":"}${arg.name}:->${action.name}`);
167
+ }
168
+ }
169
+ argsCommand += args.map((arg) => `\\\n '${arg}'`).join("");
170
+ if (command.hasCommands(false)) {
171
+ argsCommand += ` \\\n '*::sub command:->command_args'`;
172
+ }
173
+ }
174
+ return argsCommand;
175
+ }
176
+ generateOptions(command, path) {
177
+ const options = [];
178
+ const cmdArgs = path.split(" ");
179
+ const _baseName = cmdArgs.shift();
180
+ const completionsPath = cmdArgs.join(" ");
181
+ const excludedFlags = command.getOptions(false)
182
+ .map((option) => option.standalone ? option.flags : false)
183
+ .flat()
184
+ .filter((flag) => typeof flag === "string");
185
+ for (const option of command.getOptions(false)) {
186
+ options.push(this.generateOption(command, option, completionsPath, excludedFlags));
187
+ }
188
+ return options;
189
+ }
190
+ generateOption(command, option, completionsPath, excludedOptions) {
191
+ let args = "";
192
+ for (const arg of option.args) {
193
+ const type = command.getType(arg.type);
194
+ const optionalValue = arg.optionalValue ? "::" : ":";
195
+ if (type && type.handler instanceof FileType) {
196
+ const fileCompletions = this.getFileCompletions(type);
197
+ args += `${optionalValue}${arg.name}:${fileCompletions}`;
198
+ }
199
+ else {
200
+ const action = this.addAction(arg, completionsPath);
201
+ args += `${optionalValue}${arg.name}:->${action.name}`;
202
+ }
203
+ }
204
+ const description = getDescription(option.description, true)
205
+ // escape brackets and quotes
206
+ .replace(/\[/g, "\\[")
207
+ .replace(/]/g, "\\]")
208
+ .replace(/"/g, '\\"')
209
+ .replace(/'/g, "'\"'\"'");
210
+ const collect = option.collect ? "*" : "";
211
+ const equalsSign = option.equalsSign ? "=" : "";
212
+ const flags = option.flags.map((flag) => `${flag}${equalsSign}`);
213
+ let result = "";
214
+ if (option.standalone) {
215
+ result += "'(- *)'";
216
+ }
217
+ else {
218
+ const excludedFlags = [...excludedOptions];
219
+ if (option.conflicts?.length) {
220
+ excludedFlags.push(...option.conflicts.map((opt) => "--" + opt.replace(/^--/, "")));
221
+ }
222
+ if (!option.collect) {
223
+ excludedFlags.push(...option.flags);
224
+ }
225
+ if (excludedFlags.length) {
226
+ result += `'(${excludedFlags.join(" ")})'`;
227
+ }
228
+ }
229
+ if (collect || flags.length > 1) {
230
+ result += `{${collect}${flags.join(",")}}`;
231
+ }
232
+ else {
233
+ result += `${flags.join(",")}`;
234
+ }
235
+ return `${result}'[${description}]${args}'`;
236
+ }
237
+ getFileCompletions(type) {
238
+ if (!(type.handler instanceof FileType)) {
239
+ return "";
240
+ }
241
+ return "_files";
242
+ // const fileOpts = type.handler.getOptions();
243
+ // let fileCompletions = "_files";
244
+ // if (fileOpts.dirsOnly) {
245
+ // fileCompletions += " -/";
246
+ // }
247
+ // if (fileOpts.pattern) {
248
+ // fileCompletions += ' -g "' + fileOpts.pattern + '"';
249
+ // }
250
+ // if (fileOpts.ignore) {
251
+ // fileCompletions += " -F " + fileOpts.ignore;
252
+ // }
253
+ // return fileCompletions;
254
+ }
255
+ addAction(arg, cmd) {
256
+ const action = `${arg.name}-${arg.action}`;
257
+ if (!this.actions.has(action)) {
258
+ this.actions.set(action, {
259
+ arg: arg,
260
+ label: `${arg.name}: ${arg.action}`,
261
+ name: action,
262
+ cmd,
263
+ });
264
+ }
265
+ return this.actions.get(action);
266
+ }
267
+ generateActions(command) {
268
+ let actions = [];
269
+ if (this.actions.size) {
270
+ actions = Array
271
+ .from(this.actions)
272
+ .map(([name, action]) => `${name}) __${replaceSpecialChars(this.cmd.getName())}_complete ${action.arg.name} ${action.arg.action} ${action.cmd} ;;`);
273
+ }
274
+ if (command.hasCommands(false)) {
275
+ actions.unshift(`command_args) _command_args ;;`);
276
+ }
277
+ if (actions.length) {
278
+ return `\n\n case "$state" in\n ${actions.join("\n ")}\n esac`;
279
+ }
280
+ return "";
281
+ }
282
+ }
283
+ function replaceSpecialChars(str) {
284
+ return str.replace(/[^a-zA-Z0-9]/g, "_");
285
+ }
@@ -0,0 +1,6 @@
1
+ import { Command } from "../command.js";
2
+ /** Generates bash completions script. */
3
+ export declare class BashCompletionsCommand extends Command {
4
+ #private;
5
+ constructor(cmd?: Command);
6
+ }