-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path_goapp
594 lines (546 loc) · 26.1 KB
/
_goapp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
#compdef goapp
# -----------------------------------------------------------------------------
# The BSD-3-Clause License
#
# Copyright (c) 2016, Koichi Shiraishi
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of que nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
#
# Go is a tool for managing Go source code.
#
# Usage:
#
# goapp command [arguments]
#
# The commands are:
#
# serve starts a local development App Engine server
# deploy deploys your application to App Engine
# build compile packages and dependencies
# clean remove object files
# doc show documentation for package or symbol
# env print Go environment information
# fix run go tool fix on packages
# fmt run gofmt on package sources
# generate generate Go files by processing source
# get download and install packages and dependencies
# install compile and install packages and dependencies
# list list packages
# run compile and run Go program
# test test packages
# tool run specified go tool
# version print Go version
# vet run go tool vet on packages
#
# Use "goapp help [command]" for more information about a command.
#
# Additional help topics:
#
# c calling between Go and C
# buildmode description of build modes
# filetype file types
# gopath GOPATH environment variable
# environment environment variables
# importpath import path syntax
# packages description of package lists
# testflag description of testing flags
# testfunc description of testing functions
#
# Use "goapp help [topic]" for more information about that topic.
#
# -----------------------------------------------------------------------------
function _goapp() {
local context curcontext=$curcontext state line ret=1
declare -A opt_args
local -a commands
commands=(
'serve:starts a local development App Engine server'
'deploy:deploys your application to App Engine'
'build:compile packages and dependencies'
'clean:remove object files'
'doc:show documentation for package or symbol'
'env:print Go environment information'
'fix:run go tool fix on packages'
'fmt:run gofmt on package sources'
'generate:generate Go files by processing source'
'get:download and install packages and dependencies'
'install:compile and install packages and dependencies'
'list:list packages'
'run:compile and run Go program'
'test:test packages'
'tool:run specified go tool'
'version:print Go version'
'vet:run go tool vet on packages'
'help:get more information about a command'
)
__go_packages() {
local gopaths
declare -a gopaths
gopaths=("${(s/:/)$(go env GOPATH)}")
gopaths+=("$(go env GOROOT)")
for p in $gopaths; do
_alternative ':go packages:_path_files -W "$p/src" -/'
done
_alternative '*:go file:_files -g "*.go(-.)"'
}
__build_flags() {
_arguments \
'-a[force rebuilding of packages that are already up-to-date]' \
'-n[print the commands but do not run them]' \
'-p[number of builds that can be run in parallel]:number' \
'-race[enable data race detection]' \
'-v[print the names of packages as they are compiled]' \
'-work[print temporary work directory and keep it]' \
'-x[print the commands]' \
'-asmflags=[arguments for each go tool asm invocation]: :->asmflags' \
'-buildmode=[build mode to use]: :->buildmode' \
'-compiler[name of compiler to use]:name' \
'-gccgoflags[arguments for gccgo]:args' \
'-gcflags=[arguments to pass on each go tool compile invocation]: :->gcflags' \
'-installsuffix[suffix to add to package directory]:suffix' \
'-ldflags=[arguments to pass on each go tool link invocation]: :->ldflags' \
'-linkshared[link against shared libraries]' \
'-pkgdir[install and load all packages from dir]:dir' \
'-tags=[list of build tags to consider satisfied]:tags' \
'-toolexec[program to use to invoke toolchain programs]:args' \
'--debug[debug]'
case $state in
asmflags)
local -a __asm_flags
__asm_flags=(
'-D[predefined symbol with optional simple value -D=identifier=value; can be set multiple times]:value'
'-I[include directory; can be set multiple times]:value'
'-S[print assembly and machine code]'
'-debug[dump instructions as they are parsed]'
'-dynlink[support references to Go symbols defined in other shared libraries]'
'-e[no limit on number of errors reported]'
'-o[output file; default foo.o for /a/b/c/foo.s as first argument]:string'
'-shared[generate code that can be linked into a shared library]'
'-trimpath[remove prefix from recorded source file paths]:string'
)
_values \
'asmflags' \
${__asm_flags[@]}
;;
buildmode)
local -a __buildmode
__buildmode=(
'archive[Build the listed non-main packages into .a files]'
'c-archive[Build the listed main package, plus all packages it imports, into a C archive file]'
'c-shared[Build the listed main packages, plus all packages that they import, into C shared libraries]'
'default[Listed main packages are built into executables and listed non-main packages are built into .a files]'
'shared[Combine all the listed non-main packages into a single shared library that will be used when building with the -linkshared option]'
'exe[Build the listed main packages and everything they import into executables]'
'pie[Build the listed main packages and everything they import into position independent executables (PIE)]'
'plugin[Build the listed main packages, plus all packages that they import, into a Go plugin]'
)
_values \
'buildmode' \
${__buildmode[@]}
;;
gcflags)
local -a __gcflags
__gcflags=(
'-%[debug non-static initializers]'
'-+[compiling runtime]'
'-B[disable bounds checking]'
'-C[disable printing of columns in error messages]'
'-D[set relative path for local imports]:path:_files'
'-E[debug symbol export]'
'-I[add directory to import search path]:directory:_directories'
'-K[debug missing line numbers]'
'-N[disable optimizations]'
'-S[print assembly listing]'
'-V[print compiler version]'
'-W[debug parse tree after type checking]'
'-asmhdr[write assembly header to file]:file:_files'
'-bench[append benchmark times to file]:file:_files'
'-blockprofile[write block profile to file]:file:_files'
'-buildid[record id as the build id in the export metadata]:id'
'-c[concurrency during compilation, 1 means no concurrency (default 1)]:num concurrency'
'-complete[compiling complete package (no C or assembly)]'
'-cpuprofile[write cpu profile to file]:file:_files'
'-d[print debug information about items in list; try -d help]:list'
'-dolinkobj[generate linker-specific objects; if false, some invalid code may compile (default true)]'
'-dwarf[generate DWARF symbols (default true)]'
'-dynlink[support references to Go symbols defined in other shared libraries]'
'-e[no limit on number of errors reported]'
'-f[debug stack frames]'
'-goversion[required version of the runtime]:go version'
'-h[halt on error]'
'-i[debug line number stack]'
'-importcfg[read import configuration from file]:file:_files'
'-importmap[add definition of the form source=actual to import map]:definition'
'-installsuffix[set pkg directory suffix]:suffix'
'-j[debug runtime-initialized variables]'
'-l[disable inlining]'
'-linkobj[write linker-specific object to file]:file:_files'
'-live[debug liveness analysis]'
'-m[print optimization decisions]'
'-memprofile[write memory profile to file]:file:_files'
'-memprofilerate[set runtime.MemProfileRate to rate]:rate'
'-msan[build code compatible with C/C++ memory sanitizer]'
'-mutexprofile[write mutex profile to file]:file:_files'
'-nolocalimports[reject local (relative) imports]'
'-o[write output to file]:file:_files'
'-p[set expected package import path]:path:_files'
'-pack[write package file instead of object file]'
'-r[debug generated wrappers]'
'-race[enable race detector]'
'-s[warn about composite literals that can be simplified]'
'-shared[generate code that can be linked into a shared library]'
'-std[compiling standard library]'
'-traceprofile[write an execution trace to file]:file:_files'
'-trimpath[remove prefix from recorded source file paths]:prefix'
'-u[reject unsafe code]'
'-v[increase debug verbosity]'
'-w[debug type checking]'
'-wb[enable write barrier (default true)]'
)
_values \
'gcflags' \
${__gcflags[@]}
;;
ldflags)
local -a __ldflags
__ldflags=(
'-B[add an ELF NT_GNU_BUILD_ID note when using ELF]:note'
'-C[check Go calls to C code]'
'-D[set data segment address (default -1)]:address'
'-E[set entry symbol name]:entry'
'-H[set header type]:type'
'-I[use linker as ELF dynamic linker]:linker'
'-L[add specified directory to library path]:directory:_path_files -/'
'-R[set address rounding quantum (default -1)]:quantum'
'-T[set text segment address (default -1)]:address'
'-V[print version and exit]'
'-X[add string value definition of the form importpath.name=value]:definition'
'-a[disassemble output]'
'-buildid[record id as Go toolchain build id]:id'
'-buildmode[set build mode]:mode:(archive c-archive c-shared default shared exe pie)'
'-c[dump call graph]'
'-cpuprofile[write cpu profile to file]:file:_files'
'-d[disable dynamic executable]'
'-dumpdep[dump symbol dependency graph]'
'-extar[archive program for buildmode=c-archive]:string'
'-extld[use linker when linking in external mode]:linker'
'-extldflags[pass flags to external linker]:flags'
'-f[ignore version mismatch]'
'-g[disable go package data checks]'
'-h[halt on error]'
'-installsuffix[\[suffix\]: set package directory suffix]:suffix'
'-k[set field tracking symbol]:symbol'
'-libgcc[compiler support lib for internal linking; use "none" to disable]:string'
'-linkmode[set link mode (internal, external, auto)]:mode(internal external auto)'
'-linkshared[link against installed Go shared libraries]'
'-memprofile[write memory profile to file]:file:_files'
'-memprofilerate[set runtime.MemProfileRate to rate]:rate'
'-msan[enable MSan interface]'
'-n[dump symbol table]'
'-o[write output to file]:file:_files'
'-r[set the ELF dynamic linker search path to dir1:dir2:...]:path:_path_files'
'-race[enable race detector]'
'-s[disable symbol table]'
'-shared[generate shared object (implies -linkmode external)]'
'-tmpdir[use directory for temporary files]:directory:_path_files -/'
'-u[reject unsafe packages]'
'-v[print link trace]'
'-w[disable DWARF generation]'
)
_values \
'ldflags' \
${__ldflags[@]}
;;
esac
}
__test_build_flags=(
'-args[Pass the remainder of the command line to the test binary]'
'-c[Compile the test binary to pkg.test but do not run it]'
"-exec=[Run the test binary using 'xprog']:xprog"
'-i[Install packages that are dependencies of the test]'
'-o[Compile the test binary to the named file]:binary file name:_files'
)
# TODO(zchee): Support for regexp keyword
__test_binary_flags=(
"-bench[Run (sub)benchmarks matching a regular expression]:regexp of Benchmark functions:(.)"
'-benchmem[Print memory allocation statistics for benchmarks]'
'-count[Run each test and benchmark n times (default: 1)]:count'
'-cover[Enable coverage analysis]'
'-covermode[Set the mode for coverage analysis for the packages being tested (default: set)]:(set count atomic)'
'-coverpkg[Apply coverage analysis in each test to the given list of packages]: :__go_packages'
'-cpu[Specify a list of GOMAXPROCS values for which the tests or benchmarks should be executed]:(1 2 4)'
'-parallel=[Allow parallel execution of test functions that call t.Parallel]:number of parallel'
'-run[Run only those tests and examples matching the regular expression]:regexp of Tests or Examples'
'-short[Tell long-running tests to shorten their run time]'
'-timeout[If a test runs longer than arg time, panic (default: 10m)]:timeout (default: 10m)'
'-v[output log all tests as they are run and print all text from Log and Logf]'
)
__test_profile_flags=(
'-benchtime[Run enough iterations of each benchmark to take arg time]:bench time (specified as a time.Duration: e.g. 1h30s)'
'-blockprofile[Write a goroutine blocking profile to the specified file]:profile file path:_files'
'-blockprofilerate[Control the detail provided in goroutine blocking profiles by calling runtime.SetBlockProfileRate]:block profile rate'
'-coverprofile[Write a coverage profile to the file after all tests have passed]:coverage profile file path:_files'
'-cpuprofile[Write a CPU profile to the specified file before exiting]:cpu profile file path:_files'
'-memprofile[Write a memory profile to the file after all tests have passed]:memory profile file:_files'
'-memprofilerate[Enable more precise memory profiles by setting runtime.MemProfileRate]:memory profile rate'
'-mutexprofile[Enable more precise (and expensive) memory profiles]:mutex profile file:_files'
'-mutexprofilefraction[Sample 1 in n stack traces of goroutines holding a contended mutex]:mutex fraction'
'-outputdir[Place output files from profiling in the specified directory]:output directory:_path_files -/'
'-trace[Write an execution trace to the specified file before exiting]:output trace file path:_files'
)
_arguments \
"1: :{_describe 'command' commands}" \
'*:: :->args'
case $state in
args)
case $words[1] in
serve)
_arguments \
'-host[controls the host name to which application modules should bind (default localhost)]:host' \
'-port[controls the lowest port to which application modules should bind (default 8080)]:port' \
'-use_mtime_file_watcher[causes the development server to use mtime polling for detecting source code changes, as opposed to inotify watches]' \
'-admin_port[controls the port to which the admin server should bind (default 8000)]:admin port' \
'-clear_datastore[clears the local datastore on startup.]'
;;
deploy)
_arguments \
'-application[sets the application ID, overriding the application value from the app.yaml file.]:application ID'\
'-version[sets the major version, overriding the version value from the app.yaml file.]:version' \
'-oauth[causes authentication to be done using OAuth2, instead of interactive password auth.]' \
;;
build)
_arguments \
'-o[force build to write to named output file]:file:_files' \
'-i[installs the packages that are dependencies of the target]' \
'*: :__go_packages'
_alternative ':build flags:__build_flags'
;;
clean)
_arguments \
'-i[remove corresponding installed archive or binary]' \
'-r[apply clean recursively on all dependencies]' \
'*:go packages:__go_packages'
_alternative ':build flags:__build_flags'
;;
doc)
_arguments \
'-c[respect case when matching symbols]' \
'-cmd[treat a command (package main) like a regular package]' \
'-u[show docs for unexported and exported symbols and methods]' \
'*: :__go_packages'
;;
fix)
_arguments \
'*: :__go_packages'
;;
fmt)
_arguments \
'-n[prints commands that would be executed]' \
'-x[prints commands as they are executed]' \
'*: :__go_packages'
;;
generate)
_arguments \
'-run=[specifies a regular expression to select directives]:regex' \
'-x[print the commands]' \
'-n[print the commands but do not run them]' \
'-v[print the names of packages as they are compiled]' \
"*:args:{ _alternative ': :__go_packages' _files }"
;;
get)
_arguments \
'-d[instructs get to stop after downloading the packages]' \
'-f[force get -u not to verify that each package has been checked from vcs]' \
'-fix[run the fix tool on the downloaded packages]' \
'-insecure[permit fetching/resolving custom domains]' \
'-t[also download the packages required to build tests]' \
'-u[use the network to update the named packages]' \
'*: :__go_packages'
_alternative ':build flags:__build_flags'
;;
install)
_arguments \
'*: :__go_packages'
_alternative ':build flags:__build_flags'
;;
list)
_arguments \
'-e[changes the handling of erroneous packages]' \
'-f[specifies an alternate format for the list]:format' \
'-json[causes package data to be printed in JSON format]' \
"*:go file:{ _alternative ': :__go_packages' _files }"
_alternative ':build flags:__build_flags'
;;
run)
_arguments \
'-exec[invoke the binary using xprog]:xporg' \
'1:go run file:_files -g "*.go"'
_alternative ':build flags:__build_flags'
;;
test)
_arguments \
${__test_build_flags[@]} \
${__test_binary_flags[@]} \
${__test_profile_flags[@]} \
'*: :__go_packages'
_alternative ':build flags:__build_flags'
;;
tool)
local -a tools
tools=(
'asm:assembles the source file into an object file'
'cgo:enables the creation of Go packages that call C code'
'compile:compiles a single Go package comprising the files named on the command line'
'cover:analyzing the coverage profiles generated by go test -coverprofile'
'link:reads the Go archive or object for a package, and combines them into an executable binary'
)
_arguments \
'-n[print command that would be executed]' \
"1: :{_describe 'tool' tools}" \
'*:: :->args'
case $state in
args)
case $words[1] in
asm)
_arguments \
${__asm_flags[@]}
;;
cgo)
_arguments \
'-debug-define[print relevant #defines]' \
'-debug-gcc[print gcc invocations]' \
'-dynimport[if non-empty, print dynamic import data for that file]:output filename (string)' \
'-dynlinker[record dynamic linker information in -dynimport mode]' \
'-dynout[write -dynimport output to this file]:output filename (string)' \
'-dynpackage[set Go package for -dynimport output]:string' \
'-exportheader[where to write export header if any exported functions]:export header filename (string)' \
'-gccgo[generate files for use with gccgo]' \
'-gccgopkgpath[-fgo-pkgpath option used with gccgo]:-fgo-pkgpath (string)'\
'-gccgoprefix[-fgo-prefix option used with gccgo]:-fgo-prefix (string)' \
'-godefs[for bootstrap: write Go definitions for C file to standard output]' \
'-import_runtime_cgo[import runtime/cgo in generated code]' \
'-import_syscall[import syscall in generated code]' \
'-importpath[import path of package being built]:import path (string)' \
'-objdir[object directory]:directory path (string)' \
'-srcdir[source directory]:directory path (string)' \
'*:go file:_files -g "*.go(-.)"'
;;
compile)
_arguments \
${__gcflags[@]} \
'*:file:_path_files -g "*.go"'
;;
cover)
if (( CURRENT == 2 )); then
_arguments \
'-func=[output coverage profile information for each function]:string' \
'-html=[generate HTML representation of coverage profile]:file:_files' \
'-mode=[coverage mode]:mode:(set count atomic)'
fi
_arguments \
'-o[file for output]:file:_files' \
'-var=[name of coverage variable to generate]:coverage var name' \
'*:file:_path_files -g "*.go"'
;;
link)
_arguments \
'-B[add an ELF NT_GNU_BUILD_ID note when using ELF]:note' \
'-C[check Go calls to C code]' \
'-D[set data segment address (default -1)]:address' \
'-E[set entry symbol name]:entry' \
'-H[set header type]:type' \
'-I[use linker as ELF dynamic linker]:linker' \
'-L[add specified directory to library path]:directory' \
'-R[set address rounding quantum (default -1)]:quantum' \
'-T[set text segment address (default -1)]:address' \
'-V[print version and exit]' \
'-W[disassemble input]' \
'-X[add string value definition]:definition' \
'-a[disassemble output]' \
'-buildid[record id as Go toolchain build id]:id' \
'-buildmode[set build mode]:mode' \
'-c[dump call graph]' \
'-cpuprofile[write cpu profile to file]:file' \
'-d[disable dynamic executable]' \
'-extld[use linker when linking in external mode]:linker' \
'-extldflags[pass flags to external linker]:flags' \
'-f[ignore version mismatch]' \
'-g[disable go package data checks]' \
'-h[halt on error]' \
'-installsuffix[set package directory suffix]:suffix' \
'-k[set field tracking symbol]:symbol' \
'-linkmode[set link mode]:mode:(internal external auto)' \
'-linkshared[link against installed Go shared libraries]' \
'-memprofile[write memory profile to file]:file' \
'-memprofilerate[set runtime.MemProfileRate to rate]:rate' \
'-n[dump symbol table]' \
'-o[write output to file]:file' \
'-r[set the ELF dynamic linker search path to dir1:dir2:...]:path' \
'-race[enable race detector]' \
'-s[disable symbol table]' \
'-shared[generate shared object (implies -linkmode external)]' \
'-tmpdir[use directory for temporary files]:directory' \
'-u[reject unsafe packages]' \
'-v[print link trace]' \
'-w[disable DWARF generation]' \
'*:files:_files'
;;
esac
;;
esac
;;
vet)
_values \
'vet flags' \
'-n[print commands that would be executed]' \
'-x[prints commands as they are executed]' \
'*:build flags:__go_packages'
_alternative ':build flags:__build_flags'
;;
help)
local -a topics
topics=(
'c:calling between Go and C'
'buildmode:description of build modes'
'filetype:file types'
'gopath:GOPATH environment variable'
'environment:environment variables'
'importpath:import path syntax'
'packages:description of package lists'
'testflag:description of testing flags'
'testfunc:description of testing functions'
)
_arguments "1: :{_describe 'command' commands -- topics}"
;;
esac
;;
esac
}
_goapp "$*"
# vim:ft=zsh:et:sts=2:sw=2