df4508ad543236f754b3cd373d474b4af3638115

Author
Carlo Sala <carlosalag@protonmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(volta): add dynamic completion generation (#10515)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/volta/_volta b/plugins/volta/_volta
  2deleted file mode 100644
  3index 295b80362c8da956f50db47d4047b6084b2491e8..0000000000000000000000000000000000000000
  4--- a/plugins/volta/_volta
  5+++ /dev/null
  6@@ -1,298 +0,0 @@
  7-#compdef volta
  8-
  9-autoload -U is-at-least
 10-
 11-_volta() {
 12-    typeset -A opt_args
 13-    typeset -a _arguments_options
 14-    local ret=1
 15-
 16-    if is-at-least 5.2; then
 17-        _arguments_options=(-s -S -C)
 18-    else
 19-        _arguments_options=(-s -C)
 20-    fi
 21-
 22-    local context curcontext="$curcontext" state line
 23-    _arguments "${_arguments_options[@]}" \
 24-'--verbose[Enables verbose diagnostics]' \
 25-'(--verbose)--quiet[Prevents unnecessary output]' \
 26-'-v[Prints the current version of Volta]' \
 27-'--version[Prints the current version of Volta]' \
 28-'-h[Prints help information]' \
 29-'--help[Prints help information]' \
 30-":: :_volta_commands" \
 31-"*::: :->Volta" \
 32-&& ret=0
 33-    case $state in
 34-    (Volta)
 35-        words=($line[1] "${words[@]}")
 36-        (( CURRENT += 1 ))
 37-        curcontext="${curcontext%:*:*}:volta-command-$line[1]:"
 38-        case $line[1] in
 39-            (fetch)
 40-_arguments "${_arguments_options[@]}" \
 41-'-h[Prints help information]' \
 42-'--help[Prints help information]' \
 43-'-V[Prints version information]' \
 44-'--version[Prints version information]' \
 45-'--verbose[Enables verbose diagnostics]' \
 46-'(--verbose)--quiet[Prevents unnecessary output]' \
 47-':tool[@version] -- Tools to fetch, like `node`, `yarn@latest` or `your-package@^14.4.3`.:_files' \
 48-&& ret=0
 49-;;
 50-(install)
 51-_arguments "${_arguments_options[@]}" \
 52-'-h[Prints help information]' \
 53-'--help[Prints help information]' \
 54-'-V[Prints version information]' \
 55-'--version[Prints version information]' \
 56-'--verbose[Enables verbose diagnostics]' \
 57-'(--verbose)--quiet[Prevents unnecessary output]' \
 58-':tool[@version] -- Tools to install, like `node`, `yarn@latest` or `your-package@^14.4.3`.:_files' \
 59-&& ret=0
 60-;;
 61-(uninstall)
 62-_arguments "${_arguments_options[@]}" \
 63-'-h[Prints help information]' \
 64-'--help[Prints help information]' \
 65-'-V[Prints version information]' \
 66-'--version[Prints version information]' \
 67-'--verbose[Enables verbose diagnostics]' \
 68-'(--verbose)--quiet[Prevents unnecessary output]' \
 69-':tool -- The tool to uninstall, e.g. `node`, `npm`, `yarn`, or <package>:_files' \
 70-&& ret=0
 71-;;
 72-(pin)
 73-_arguments "${_arguments_options[@]}" \
 74-'-h[Prints help information]' \
 75-'--help[Prints help information]' \
 76-'-V[Prints version information]' \
 77-'--version[Prints version information]' \
 78-'--verbose[Enables verbose diagnostics]' \
 79-'(--verbose)--quiet[Prevents unnecessary output]' \
 80-':tool[@version] -- Tools to pin, like `node@lts` or `yarn@^1.14`.:_files' \
 81-&& ret=0
 82-;;
 83-(ls)
 84-_arguments "${_arguments_options[@]}" \
 85-'--format=[Specify the output format]: :(human plain)' \
 86-'(-d --default)-c[Show the currently-active tool(s)]' \
 87-'(-d --default)--current[Show the currently-active tool(s)]' \
 88-'(-c --current)-d[Show your default tool(s).]' \
 89-'(-c --current)--default[Show your default tool(s).]' \
 90-'-h[Prints help information]' \
 91-'--help[Prints help information]' \
 92-'-V[Prints version information]' \
 93-'--version[Prints version information]' \
 94-'--verbose[Enables verbose diagnostics]' \
 95-'(--verbose)--quiet[Prevents unnecessary output]' \
 96-'::tool -- The tool to lookup - `all`, `node`, `yarn`, or the name of a package or binary.:_files' \
 97-&& ret=0
 98-;;
 99-(list)
100-_arguments "${_arguments_options[@]}" \
101-'--format=[Specify the output format]: :(human plain)' \
102-'(-d --default)-c[Show the currently-active tool(s)]' \
103-'(-d --default)--current[Show the currently-active tool(s)]' \
104-'(-c --current)-d[Show your default tool(s).]' \
105-'(-c --current)--default[Show your default tool(s).]' \
106diff --git a/plugins/volta/volta.plugin.zsh b/plugins/volta/volta.plugin.zsh
107new file mode 100644
108index 0000000000000000000000000000000000000000..756dc84b3901abce45a2fcf80f53b5f8954f6cbe
109--- /dev/null
110+++ b/plugins/volta/volta.plugin.zsh
111@@ -0,0 +1,19 @@
112+# COMPLETION FUNCTION
113+if (( ! $+commands[volta] )); then
114+  return
115+fi
116+
117+# TODO: 2021-12-28: remove this bit of code as it exists in oh-my-zsh.sh
118+# Add completions folder in $ZSH_CACHE_DIR
119+command mkdir -p "$ZSH_CACHE_DIR/completions"
120+(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
121+
122+# If the completion file doesn't exist yet, we need to autoload it and
123+# bind it to `deno`. Otherwise, compinit will have already done that.
124+if [[ ! -f "$ZSH_CACHE_DIR/completions/_volta" ]]; then
125+  declare -A _comps
126+  autoload -Uz _volta
127+  _comps[volta]=_volta
128+fi
129+
130+volta completions zsh >| "$ZSH_CACHE_DIR/completions/_volta" &|