6 gopaths=("${(s/:/)$(go env GOPATH)}")
7 gopaths+=("$(go env GOROOT)")
9 _path_files -W "$p/src" -/
14 local tmpl_path="${functions_source[$0]:h}/templates"
15 compadd $(godoc -templates "$tmpl_path" ${words[-2]} 2> /dev/null)
19 typeset -a commands build_flags
21 'build[compile packages and dependencies]'
22 'clean[remove object files]'
23 'doc[run godoc on package sources]'
24 'env[print Go environment information]'
25 'fix[run go tool fix on packages]'
26 'fmt[run gofmt on package sources]'
27 'generate[generate Go files by processing source]'
28 'get[download and install packages and dependencies]'
30 'install[compile and install packages and dependencies]'
32 'mod[modules maintenance]'
33 'run[compile and run Go program]'
35 'tool[run specified go tool]'
36 'version[print Go version]'
37 'vet[run go tool vet on packages]'
39 if (( CURRENT == 2 )); then
41 _values 'go tool commands' ${commands[@]}
45 '-a[force reinstallation of packages that are already up to date]'
46 '-n[print the commands but do not run them]'
47 '-p[number of parallel builds]:number'
48 '-race[enable data race detection]'
49 '-x[print the commands]'
50 '-work[print temporary directory name and keep it]'
51 '-ccflags[flags for 5c/6c/8c]:flags'
52 '-gcflags[flags for 5g/6g/8g]:flags'
53 '-ldflags[flags for 5l/6l/8l]:flags'
54 '-gccgoflags[flags for gccgo]:flags'
55 '-compiler[name of compiler to use]:name'
56 '-installsuffix[suffix to add to package directory]:suffix'
57 '-tags[list of build tags to consider satisfied]:tags'
63 "-c[symbol matching honors case (paths not affected)]" \
64 "-cmd[show symbols with package docs even if package is a command]" \
65 "-u[show unexported symbols as well as exported]" \
66 "2:importpaths:__go_packages" \
67 ":next identifiers:__go_identifiers"
71 "-i[remove the corresponding installed archive or binary (what 'go install' would create)]" \
72 "-n[print the remove commands it would execute, but not run them]" \
73 "-r[apply recursively to all the dependencies of the packages named by the import paths]" \
74 "-x[print remove commands as it executes them]" \
75 "*:importpaths:__go_packages"
78 _alternative ':importpaths:__go_packages' ':files:_path_files -g "*.go"'
81 _arguments -s -w : ${build_flags[@]} \
82 "-v[show package names]" \
83 '*:importpaths:__go_packages'
92 "-v[show package names]" \
93 "-o[output file]:file:_files" \
94 "*:args:{ _alternative ':importpaths:__go_packages' ':files:_path_files -g \"*.go\"' }"
99 "-c[do not run, compile the test binary]" \
100 "-i[do not run, install dependencies]" \
101 "-v[print test output]" \
102 "-x[print the commands]" \
103 "-short[use short mode]" \
104 "-parallel[number of parallel tests]:number" \
105 "-cpu[values of GOMAXPROCS to use]:number list" \
106 "-run[run tests and examples matching regexp]:regexp" \
107 "-bench[run benchmarks matching regexp]:regexp" \
108 "-benchmem[print memory allocation stats]" \
109 "-benchtime[run each benchmark until taking this long]:duration" \
110 "-blockprofile[write goroutine blocking profile to file]:file" \
111 "-blockprofilerate[set sampling rate of goroutine blocking profile]:number" \
112 "-timeout[kill test after that duration]:duration" \
113 "-cpuprofile[write CPU profile to file]:file:_files" \
114 "-memprofile[write heap profile to file]:file:_files" \
115 "-memprofilerate[set heap profiling rate]:number" \
116 "*:args:{ _alternative ':importpaths:__go_packages' ':files:_path_files -g \"*.go\"' }"
120 "-f[alternative format for the list]:format" \
121 "-json[print data in json format]" \
122 "-compiled[set CompiledGoFiles to the Go source files presented to the compiler]" \
123 "-deps[iterate over not just the named packages but also all their dependencies]" \
124 "-e[change the handling of erroneous packages]" \
125 "-export[set the Export field to the name of a file containing up-to-date export information for the given package]" \
126 "-find[identify the named packages but not resolve their dependencies]" \
127 "-test[report not only the named packages but also their test binaries]" \
128 "-m[list modules instead of packages]" \
129 "-u[adds information about available upgrades]" \
130 "-versions[set the Module's Versions field to a list of all known versions of that module]:number" \
131 "*:importpaths:__go_packages"
134 local -a mod_commands
136 'download[download modules to local cache]'
137 'edit[edit go.mod from tools or scripts]'
138 'graph[print module requirement graph]'
139 'init[initialize new module in current directory]'
140 'tidy[add missing and remove unused modules]'
141 'vendor[make vendored copy of dependencies]'
142 'verify[verify dependencies have expected content]'
143 'why[explain why packages or modules are needed]'
146 if (( CURRENT == 3 )); then
147 _values 'go mod commands' ${mod_commands[@]} "help[display help]"
153 _values 'go mod commands' ${mod_commands[@]}
157 "-json[print a sequence of JSON objects standard output]" \
162 "-fmt[reformat the go.mod file]" \
163 "-module[change the module's path]" \
164 "-replace[=old{@v}=new{@v} add a replacement of the given module path and version pair]:name" \
165 "-dropreplace[=old{@v}=new{@v} drop a replacement of the given module path and version pair]:name" \
166 "-go[={version} set the expected Go language version]:number" \
167 "-print[print the final go.mod in its text format]" \
168 "-json[print the final go.mod file in JSON format]" \
177 "-v[print information about removed modules]" \
182 "-v[print the names of vendored]" \
189 "-m[treats the arguments as a list of modules and finds a path to any package in each of the modules]" \
190 "-vendor[exclude tests of dependencies]" \
191 "*:importpaths:__go_packages"
196 _values "${commands[@]}" \
197 'environment[show Go environment variables available]' \
198 'gopath[GOPATH environment variable]' \
199 'packages[description of package lists]' \
200 'remote[remote import path syntax]' \
201 'testflag[description of testing flags]' \
202 'testfunc[description of testing functions]'
207 '*:file:_files -g "*.go"'
210 if (( CURRENT == 3 )); then
211 _values "go tool" $(go tool)
217 '-I[search for packages in DIR]:includes:_path_files -/' \
218 '-L[show full path in file:line prints]' \
219 '-S[print the assembly language]' \
220 '-V[print the compiler version]' \
221 '-e[no limit on number of errors printed]' \
222 '-h[panic on an error]' \
223 '-l[disable inlining]' \
224 '-m[print optimization decisions]' \
225 '-o[file specify output file]:file' \
226 '-p[assumed import path for this code]:importpath' \
227 '-u[disable package unsafe]' \
228 "*:file:_files -g '*.go'"
231 local O=${words[3]%l}
233 '-o[file specify output file]:file' \
234 '-L[search for packages in DIR]:includes:_path_files -/' \
235 "*:file:_files -g '*.[ao$O]'"
238 _values "dist tool" banner bootstrap clean env install version
241 # use files by default