ae7d0bcdb9d22a2de4150f2f00a5c0a26b857c48

Author
Andrey Skurlatov <a.skurlatov@gmail.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

golang: mod and list commands completion (#7665)

Also, add `gom` alias to `go mod`.

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/golang/golang.plugin.zsh b/plugins/golang/golang.plugin.zsh
  2index 8284ab83c593711e2e41403f84ecc6722dfe1dff..47b10988e9e1a8419fdee321d6ef6eef0971f8c2 100644
  3--- a/plugins/golang/golang.plugin.zsh
  4+++ b/plugins/golang/golang.plugin.zsh
  5@@ -28,6 +28,7 @@ __go_tool_complete() {
  6     'help[display help]'
  7     'install[compile and install packages and dependencies]'
  8     'list[list packages]'
  9+    'mod[modules maintenance]'
 10     'run[compile and run Go program]'
 11     'test[test packages]'
 12     'tool[run specified go tool]'
 13@@ -83,7 +84,7 @@ __go_tool_complete() {
 14       "-x[print remove commands as it executes them]" \
 15       "*:importpaths:__go_packages"
 16       ;;
 17-  fix|fmt|list|vet)
 18+  fix|fmt|vet)
 19       _alternative ':importpaths:__go_packages' ':files:_path_files -g "*.go"'
 20       ;;
 21   install)
 22@@ -124,6 +125,81 @@ __go_tool_complete() {
 23         "-memprofilerate[set heap profiling rate]:number" \
 24         "*:args:{ _alternative ':importpaths:__go_packages' ':files:_path_files -g \"*.go\"' }"
 25       ;;
 26+  list)
 27+      _arguments -s -w : \
 28+        "-f[alternative format for the list]:format" \
 29+        "-json[print data in json format]" \
 30+        "-compiled[set CompiledGoFiles to the Go source files presented to the compiler]" \
 31+        "-deps[iterate over not just the named packages but also all their dependencies]" \
 32+        "-e[change the handling of erroneous packages]" \
 33+        "-export[set the Export field to the name of a file containing up-to-date export information for the given package]" \
 34+        "-find[identify the named packages but not resolve their dependencies]" \
 35+        "-test[report not only the named packages but also their test binaries]" \
 36+        "-m[list modules instead of packages]" \
 37+        "-u[adds information about available upgrades]" \
 38+        "-versions[set the Module's Versions field to a list of all known versions of that module]:number" \
 39+        "*:importpaths:__go_packages"
 40+      ;;
 41+  mod)
 42+      typeset -a mod_commands
 43+      mod_commands+=(
 44+        'download[download modules to local cache]'
 45+        'edit[edit go.mod from tools or scripts]'
 46+        'graph[print module requirement graph]'
 47+        'init[initialize new module in current directory]'
 48+        'tidy[add missing and remove unused modules]'
 49+        'vendor[make vendored copy of dependencies]'
 50+        'verify[verify dependencies have expected content]'
 51+        'why[explain why packages or modules are needed]'
 52+      )
 53+      if (( CURRENT == 3 )); then
 54+          _values 'go mod commands' ${mod_commands[@]} "help[display help]"
 55+          return
 56+      fi
 57+      case ${words[3]} in
 58+      help)
 59+        _values 'go mod commands' ${mod_commands[@]}
 60+        ;;
 61+      download)
 62+        _arguments -s -w : \
 63+          "-json[print a sequence of JSON objects standard output]" \
 64+          "*:flags"
 65+        ;;
 66+      edit)
 67+        _arguments -s -w : \
 68+          "-fmt[reformat the go.mod file]" \
 69+          "-module[change the module's path]" \
 70+          "-replace[=old{@v}=new{@v} add a replacement of the given module path and version pair]:name" \
 71+          "-dropreplace[=old{@v}=new{@v} drop a replacement of the given module path and version pair]:name" \
 72+          "-go[={version} set the expected Go language version]:number" \
 73+          "-print[print the final go.mod in its text format]" \
 74+          "-json[print the final go.mod file in JSON format]" \
 75+          "*:flags"
 76+        ;;
 77+      graph)
 78+        ;;
 79+      init)   
 80+        ;;
 81+      tidy)
 82+        _arguments -s -w : \
 83+          "-v[print information about removed modules]" \
 84+          "*:flags"
 85+        ;;
 86+      vendor)
 87+        _arguments -s -w : \
 88+          "-v[print the names of vendored]" \
 89+          "*:flags"
 90+        ;;
 91+      verify)
 92+        ;;
 93+      why)
 94+        _arguments -s -w : \
 95+          "-m[treats the arguments as a list of modules and finds a path to any package in each of the modules]" \
 96+          "-vendor[exclude tests of dependencies]" \
 97+          "*:importpaths:__go_packages"
 98+        ;;
 99+      esac
100+      ;;
101   help)
102       _values "${commands[@]}" \
103         'environment[show Go environment variables available]' \
104@@ -189,6 +265,7 @@ alias gofa='go fmt ./...'