_volta 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. #compdef volta
  2. autoload -U is-at-least
  3. _volta() {
  4. typeset -A opt_args
  5. typeset -a _arguments_options
  6. local ret=1
  7. if is-at-least 5.2; then
  8. _arguments_options=(-s -S -C)
  9. else
  10. _arguments_options=(-s -C)
  11. fi
  12. local context curcontext="$curcontext" state line
  13. _arguments "${_arguments_options[@]}" \
  14. '--verbose[Enables verbose diagnostics]' \
  15. '(--verbose)--quiet[Prevents unnecessary output]' \
  16. '-v[Prints the current version of Volta]' \
  17. '--version[Prints the current version of Volta]' \
  18. '-h[Prints help information]' \
  19. '--help[Prints help information]' \
  20. ":: :_volta_commands" \
  21. "*::: :->Volta" \
  22. && ret=0
  23. case $state in
  24. (Volta)
  25. words=($line[1] "${words[@]}")
  26. (( CURRENT += 1 ))
  27. curcontext="${curcontext%:*:*}:volta-command-$line[1]:"
  28. case $line[1] in
  29. (fetch)
  30. _arguments "${_arguments_options[@]}" \
  31. '-h[Prints help information]' \
  32. '--help[Prints help information]' \
  33. '-V[Prints version information]' \
  34. '--version[Prints version information]' \
  35. '--verbose[Enables verbose diagnostics]' \
  36. '(--verbose)--quiet[Prevents unnecessary output]' \
  37. ':tool[@version] -- Tools to fetch, like `node`, `yarn@latest` or `your-package@^14.4.3`.:_files' \
  38. && ret=0
  39. ;;
  40. (install)
  41. _arguments "${_arguments_options[@]}" \
  42. '-h[Prints help information]' \
  43. '--help[Prints help information]' \
  44. '-V[Prints version information]' \
  45. '--version[Prints version information]' \
  46. '--verbose[Enables verbose diagnostics]' \
  47. '(--verbose)--quiet[Prevents unnecessary output]' \
  48. ':tool[@version] -- Tools to install, like `node`, `yarn@latest` or `your-package@^14.4.3`.:_files' \
  49. && ret=0
  50. ;;
  51. (uninstall)
  52. _arguments "${_arguments_options[@]}" \
  53. '-h[Prints help information]' \
  54. '--help[Prints help information]' \
  55. '-V[Prints version information]' \
  56. '--version[Prints version information]' \
  57. '--verbose[Enables verbose diagnostics]' \
  58. '(--verbose)--quiet[Prevents unnecessary output]' \
  59. ':tool -- The tool to uninstall, e.g. `node`, `npm`, `yarn`, or <package>:_files' \
  60. && ret=0
  61. ;;
  62. (pin)
  63. _arguments "${_arguments_options[@]}" \
  64. '-h[Prints help information]' \
  65. '--help[Prints help information]' \
  66. '-V[Prints version information]' \
  67. '--version[Prints version information]' \
  68. '--verbose[Enables verbose diagnostics]' \
  69. '(--verbose)--quiet[Prevents unnecessary output]' \
  70. ':tool[@version] -- Tools to pin, like `node@lts` or `yarn@^1.14`.:_files' \
  71. && ret=0
  72. ;;
  73. (ls)
  74. _arguments "${_arguments_options[@]}" \
  75. '--format=[Specify the output format]: :(human plain)' \
  76. '(-d --default)-c[Show the currently-active tool(s)]' \
  77. '(-d --default)--current[Show the currently-active tool(s)]' \
  78. '(-c --current)-d[Show your default tool(s).]' \
  79. '(-c --current)--default[Show your default tool(s).]' \
  80. '-h[Prints help information]' \
  81. '--help[Prints help information]' \
  82. '-V[Prints version information]' \
  83. '--version[Prints version information]' \
  84. '--verbose[Enables verbose diagnostics]' \
  85. '(--verbose)--quiet[Prevents unnecessary output]' \
  86. '::tool -- The tool to lookup - `all`, `node`, `yarn`, or the name of a package or binary.:_files' \
  87. && ret=0
  88. ;;
  89. (list)
  90. _arguments "${_arguments_options[@]}" \
  91. '--format=[Specify the output format]: :(human plain)' \
  92. '(-d --default)-c[Show the currently-active tool(s)]' \
  93. '(-d --default)--current[Show the currently-active tool(s)]' \
  94. '(-c --current)-d[Show your default tool(s).]' \
  95. '(-c --current)--default[Show your default tool(s).]' \
  96. '-h[Prints help information]' \
  97. '--help[Prints help information]' \
  98. '-V[Prints version information]' \
  99. '--version[Prints version information]' \
  100. '--verbose[Enables verbose diagnostics]' \
  101. '(--verbose)--quiet[Prevents unnecessary output]' \
  102. '::tool -- The tool to lookup - `all`, `node`, `yarn`, or the name of a package or binary.:_files' \
  103. && ret=0
  104. ;;
  105. (completions)
  106. _arguments "${_arguments_options[@]}" \
  107. '-o+[File to write generated completions to]' \
  108. '--output=[File to write generated completions to]' \
  109. '-f[Write over an existing file, if any.]' \
  110. '--force[Write over an existing file, if any.]' \
  111. '-h[Prints help information]' \
  112. '--help[Prints help information]' \
  113. '-V[Prints version information]' \
  114. '--version[Prints version information]' \
  115. '--verbose[Enables verbose diagnostics]' \
  116. '(--verbose)--quiet[Prevents unnecessary output]' \
  117. ':shell -- Shell to generate completions for:(zsh bash fish powershell elvish)' \
  118. && ret=0
  119. ;;
  120. (which)
  121. _arguments "${_arguments_options[@]}" \
  122. '-h[Prints help information]' \
  123. '--help[Prints help information]' \
  124. '-V[Prints version information]' \
  125. '--version[Prints version information]' \
  126. '--verbose[Enables verbose diagnostics]' \
  127. '(--verbose)--quiet[Prevents unnecessary output]' \
  128. ':binary -- The binary to find, e.g. `node` or `npm`:_files' \
  129. && ret=0
  130. ;;
  131. (use)
  132. _arguments "${_arguments_options[@]}" \
  133. '-h[Prints help information]' \
  134. '--help[Prints help information]' \
  135. '-V[Prints version information]' \
  136. '--version[Prints version information]' \
  137. '--verbose[Enables verbose diagnostics]' \
  138. '(--verbose)--quiet[Prevents unnecessary output]' \
  139. '::anything:_files' \
  140. && ret=0
  141. ;;
  142. (setup)
  143. _arguments "${_arguments_options[@]}" \
  144. '-h[Prints help information]' \
  145. '--help[Prints help information]' \
  146. '-V[Prints version information]' \
  147. '--version[Prints version information]' \
  148. '--verbose[Enables verbose diagnostics]' \
  149. '(--verbose)--quiet[Prevents unnecessary output]' \
  150. && ret=0
  151. ;;
  152. (run)
  153. _arguments "${_arguments_options[@]}" \
  154. '--node=[Set the custom Node version]' \
  155. '(--bundled-npm)--npm=[Set the custom npm version]' \
  156. '(--no-yarn)--yarn=[Set the custom Yarn version]' \
  157. '*--env=[Set an environment variable (can be used multiple times)]' \
  158. '(--npm)--bundled-npm[Forces npm to be the version bundled with Node]' \
  159. '(--yarn)--no-yarn[Disables Yarn]' \
  160. '-h[Prints help information]' \
  161. '--help[Prints help information]' \
  162. '-V[Prints version information]' \
  163. '--version[Prints version information]' \
  164. '--verbose[Enables verbose diagnostics]' \
  165. '(--verbose)--quiet[Prevents unnecessary output]' \
  166. ':command -- The command to run:_files' \
  167. '::args -- Arguments to pass to the command:_files' \
  168. && ret=0
  169. ;;
  170. (help)
  171. _arguments "${_arguments_options[@]}" \
  172. '-h[Prints help information]' \
  173. '--help[Prints help information]' \
  174. '-V[Prints version information]' \
  175. '--version[Prints version information]' \
  176. '--verbose[Enables verbose diagnostics]' \
  177. '(--verbose)--quiet[Prevents unnecessary output]' \
  178. && ret=0
  179. ;;
  180. esac
  181. ;;
  182. esac
  183. }
  184. (( $+functions[_volta_commands] )) ||
  185. _volta_commands() {
  186. local commands; commands=(
  187. "fetch:Fetches a tool to the local machine" \
  188. "install:Installs a tool in your toolchain" \
  189. "uninstall:Uninstalls a tool from your toolchain" \
  190. "pin:Pins your project's runtime or package manager" \
  191. "list:Displays the current toolchain" \
  192. "completions:Generates Volta completions" \
  193. "which:Locates the actual binary that will be called by Volta" \
  194. "use:" \
  195. "setup:Enables Volta for the current user / shell" \
  196. "run:Run a command with custom Node, npm, and/or Yarn versions" \
  197. "help:Prints this message or the help of the given subcommand(s)" \
  198. )
  199. _describe -t commands 'volta commands' commands "$@"
  200. }
  201. (( $+functions[_volta__completions_commands] )) ||
  202. _volta__completions_commands() {
  203. local commands; commands=(
  204. )
  205. _describe -t commands 'volta completions commands' commands "$@"
  206. }
  207. (( $+functions[_volta__fetch_commands] )) ||
  208. _volta__fetch_commands() {
  209. local commands; commands=(
  210. )
  211. _describe -t commands 'volta fetch commands' commands "$@"
  212. }
  213. (( $+functions[_volta__help_commands] )) ||
  214. _volta__help_commands() {
  215. local commands; commands=(
  216. )
  217. _describe -t commands 'volta help commands' commands "$@"
  218. }
  219. (( $+functions[_volta__install_commands] )) ||
  220. _volta__install_commands() {
  221. local commands; commands=(
  222. )
  223. _describe -t commands 'volta install commands' commands "$@"
  224. }
  225. (( $+functions[_volta__list_commands] )) ||
  226. _volta__list_commands() {
  227. local commands; commands=(
  228. )
  229. _describe -t commands 'volta list commands' commands "$@"
  230. }
  231. (( $+functions[_ls_commands] )) ||
  232. _ls_commands() {
  233. local commands; commands=(
  234. )
  235. _describe -t commands 'ls commands' commands "$@"
  236. }
  237. (( $+functions[_volta__ls_commands] )) ||
  238. _volta__ls_commands() {
  239. local commands; commands=(
  240. )
  241. _describe -t commands 'volta ls commands' commands "$@"
  242. }
  243. (( $+functions[_volta__pin_commands] )) ||
  244. _volta__pin_commands() {
  245. local commands; commands=(
  246. )
  247. _describe -t commands 'volta pin commands' commands "$@"
  248. }
  249. (( $+functions[_volta__run_commands] )) ||
  250. _volta__run_commands() {
  251. local commands; commands=(
  252. )
  253. _describe -t commands 'volta run commands' commands "$@"
  254. }
  255. (( $+functions[_volta__setup_commands] )) ||
  256. _volta__setup_commands() {
  257. local commands; commands=(
  258. )
  259. _describe -t commands 'volta setup commands' commands "$@"
  260. }
  261. (( $+functions[_volta__uninstall_commands] )) ||
  262. _volta__uninstall_commands() {
  263. local commands; commands=(
  264. )
  265. _describe -t commands 'volta uninstall commands' commands "$@"
  266. }
  267. (( $+functions[_volta__use_commands] )) ||
  268. _volta__use_commands() {
  269. local commands; commands=(
  270. )
  271. _describe -t commands 'volta use commands' commands "$@"
  272. }
  273. (( $+functions[_volta__which_commands] )) ||
  274. _volta__which_commands() {
  275. local commands; commands=(
  276. )
  277. _describe -t commands 'volta which commands' commands "$@"
  278. }
  279. _volta "$@"