]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/golang/_golang
01b976b129d7018a3abfed55b9179ca77f7509d9
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / golang / _golang
1 #compdef go
2
3 __go_packages() {
4   local gopaths
5   declare -a gopaths
6   gopaths=("${(s/:/)$(go env GOPATH)}")
7   gopaths+=("$(go env GOROOT)")
8   for p in $gopaths; do
9     _path_files -W "$p/src" -/
10   done
11 }
12
13 __go_identifiers() {
14   local tmpl_path="${functions_source[$0]:h}/templates"
15   compadd $(godoc -templates "$tmpl_path" ${words[-2]} 2> /dev/null)
16 }
17
18 _go() {
19   typeset -a commands build_flags
20   commands+=(
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]'
29     'help[display help]'
30     'install[compile and install packages and dependencies]'
31     'list[list packages]'
32     'mod[modules maintenance]'
33     'run[compile and run Go program]'
34     'test[test packages]'
35     'tool[run specified go tool]'
36     'version[print Go version]'
37     'vet[run go tool vet on packages]'
38   )
39   if (( CURRENT == 2 )); then
40     # explain go commands
41     _values 'go tool commands' ${commands[@]}
42     return
43   fi
44   build_flags=(
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'
58   )
59
60   case ${words[2]} in
61   doc)
62     _arguments -s -w \
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"
68     ;;
69   clean)
70     _arguments -s -w \
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"
76     ;;
77   fix|fmt|vet)
78     _alternative ':importpaths:__go_packages' ':files:_path_files -g "*.go"'
79     ;;
80   install)
81     _arguments -s -w : ${build_flags[@]} \
82       "-v[show package names]" \
83       '*:importpaths:__go_packages'
84     ;;
85   get)
86     _arguments -s -w : \
87       ${build_flags[@]}
88     ;;
89   build)
90     _arguments -s -w : \
91       ${build_flags[@]} \
92       "-v[show package names]" \
93       "-o[output file]:file:_files" \
94       "*:args:{ _alternative ':importpaths:__go_packages' ':files:_path_files -g \"*.go\"' }"
95     ;;
96   test)
97     _arguments -s -w : \
98       ${build_flags[@]} \
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\"' }"
117     ;;
118   list)
119     _arguments -s -w : \
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"
132     ;;
133   mod)
134     local -a mod_commands
135     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]'
144     )
145
146     if (( CURRENT == 3 )); then
147       _values 'go mod commands' ${mod_commands[@]} "help[display help]"
148       return
149     fi
150
151     case ${words[3]} in
152     help)
153       _values 'go mod commands' ${mod_commands[@]}
154       ;;
155     download)
156       _arguments -s -w : \
157         "-json[print a sequence of JSON objects standard output]" \
158         "*:flags"
159       ;;
160     edit)
161       _arguments -s -w : \
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]" \
169         "*:flags"
170       ;;
171     graph)
172       ;;
173     init)
174       ;;
175     tidy)
176       _arguments -s -w : \
177         "-v[print information about removed modules]" \
178         "*:flags"
179       ;;
180     vendor)
181       _arguments -s -w : \
182         "-v[print the names of vendored]" \
183         "*:flags"
184       ;;
185     verify)
186       ;;
187     why)
188       _arguments -s -w : \
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"
192       ;;
193     esac
194     ;;
195   help)
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]'
203     ;;
204   run)
205     _arguments -s -w : \
206       ${build_flags[@]} \
207       '*:file:_files -g "*.go"'
208     ;;
209   tool)
210     if (( CURRENT == 3 )); then
211         _values "go tool" $(go tool)
212         return
213     fi
214     case ${words[3]} in
215     [568]g)
216         _arguments -s -w : \
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'"
229         ;;
230     [568]l)
231         local O=${words[3]%l}
232         _arguments -s -w : \
233             '-o[file specify output file]:file' \
234             '-L[search for packages in DIR]:includes:_path_files -/' \
235             "*:file:_files -g '*.[ao$O]'"
236         ;;
237     dist)
238         _values "dist tool" banner bootstrap clean env install version
239         ;;
240     *)
241         # use files by default
242         _files
243         ;;
244     esac
245     ;;
246   esac
247 }
248
249 _go "$@"