Don't use global variables

and fix indentations
This commit is contained in:
Shohei YOSHIDA 2024-07-29 12:12:52 +09:00
parent a50d486f6d
commit 499e5be22e
No known key found for this signature in database
GPG Key ID: C9A1BB11BB940CF2
1 changed files with 180 additions and 193 deletions

View File

@ -45,8 +45,7 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
__go_buildmodes() { __go_buildmodes() {
local -a buildmodes local -a buildmodes=(
buildmodes=(
'archive[non-main packages into .a files]' 'archive[non-main packages into .a files]'
'c-archive[main package, plus all packages it imports, into a C archive file]' 'c-archive[main package, plus all packages it imports, into a C archive file]'
'c-shared[main package, plus all packages it imports, into a C shared library]' 'c-shared[main package, plus all packages it imports, into a C shared library]'
@ -60,10 +59,8 @@ __go_buildmodes() {
_values 'mode' $buildmodes _values 'mode' $buildmodes
} }
__go_runtimedebug() { __go_runtimedebug() {
local -a vars local -a vars=(
vars=(
'allocfreetrace[profile allocations]:boolean:(1 0)' 'allocfreetrace[profile allocations]:boolean:(1 0)'
'clobberfree[clobber memory after free]:boolean:(1 0)' 'clobberfree[clobber memory after free]:boolean:(1 0)'
'cgocheck[check passing go pointers to non-go]: :((0\:"no checks" 1\:"check checks" 2\:"expensive checks"))' 'cgocheck[check passing go pointers to non-go]: :((0\:"no checks" 1\:"check checks" 2\:"expensive checks"))'
@ -173,7 +170,7 @@ __go_gcflags() {
'-trimpath=[remove prefix from recorded source file paths]:prefix' \ '-trimpath=[remove prefix from recorded source file paths]:prefix' \
'-v[increase debug verbosity]' \ '-v[increase debug verbosity]' \
'-w[debug type checking]' \ '-w[debug type checking]' \
'-wb[enable write barrier (default true)]' \ '-wb[enable write barrier (default true)]'
} }
__go_pgo() { __go_pgo() {
@ -182,8 +179,8 @@ __go_pgo() {
"file:file:_files" "file:file:_files"
} }
local -a commands build_flags local -a build_flags
commands=( local -a commands=(
'bug:start a bug report' 'bug:start a bug report'
'build:compile packages and dependencies' 'build:compile packages and dependencies'
'clean:remove object files and cached files' 'clean:remove object files and cached files'
@ -368,21 +365,20 @@ case $state in
'-trimpath[remove all file system paths from the resulting executable]' '-trimpath[remove all file system paths from the resulting executable]'
'-toolexec[program to use to invoke toolchain programs]:args' '-toolexec[program to use to invoke toolchain programs]:args'
) )
mod_flags=( local -a mod_flags=(
'-mod=[module download mode to use]:download mode:(readonly vendor mod)' '-mod=[module download mode to use]:download mode:(readonly vendor mod)'
'-modcacherw[leave newly-created directories in the module cache read-write]' '-modcacherw[leave newly-created directories in the module cache read-write]'
'-modfile=[read an alternate go.mod file]:modfile: _files -g "*.mod"' '-modfile=[read an alternate go.mod file]:modfile: _files -g "*.mod"'
) )
local -a edit_flags=(
edit_flags=( '-fmt[reformats the go.mod/work file without making other changes]'
'-fmt[reformats the go.mod/work file without making other changes]' \ '*-require=[add a requirement on the given module path and version]:require'
'*-require=[add a requirement on the given module path and version]:require' \ '*-droprequire=[drop a requirement on the given module path and version]:droprequire'
'*-droprequire=[drop a requirement on the given module path and version]:droprequire' \ '-go[sets the expected Go language version]:goversion'
'-go[sets the expected Go language version]:goversion' \ '*-replace=[add a replacement of the given module path and version]:replace'
'*-replace=[add a replacement of the given module path and version]:replace' \ '*-dropreplace=[drop a replacement of the given module path and version]:dropreplace'
'*-dropreplace=[drop a replacement of the given module path and version]:dropreplace' \ '-json[prints the final go.mod/work file in JSON format]'
'-json[prints the final go.mod/work file in JSON format]' \ '-print[prints the final go.mod/work in its text format]'
'-print[prints the final go.mod/work in its text format]' \
) )
__go_packages() { __go_packages() {
@ -438,8 +434,7 @@ case $state in
;; ;;
env) env)
local -a goenvvars local -a goenvvars=(
goenvvars=(
"GOARCH[architecture, or processor, for which to compile code.]:architecture" "GOARCH[architecture, or processor, for which to compile code.]:architecture"
"GCCGO[gccgo command to run.]:gccgo command" "GCCGO[gccgo command to run.]:gccgo command"
"GOBIN[directory where 'go install' installs to]:go install target dir" "GOBIN[directory where 'go install' installs to]:go install target dir"
@ -497,8 +492,7 @@ case $state in
"GOMOD[absolute path the the main go.mod]:abs path to main go.mod" "GOMOD[absolute path the the main go.mod]:abs path to main go.mod"
"GOTOOLDIR[installation directory of go tools]:tool installation directory" "GOTOOLDIR[installation directory of go tools]:tool installation directory"
) )
local -a exclude_from_w local -a exclude_from_w=(GOENV)
exclude_from_w=(GOENV)
__list_env_vars() { __list_env_vars() {
# the parameter expansion strops off everything after the first [ # the parameter expansion strops off everything after the first [
@ -559,8 +553,7 @@ case $state in
;; ;;
list) list)
local -a list_args local -a list_args=(
list_args=(
'-e[changes the handling of erroneous packages]' '-e[changes the handling of erroneous packages]'
'-f[specifies an alternate format for the list]:format' '-f[specifies an alternate format for the list]:format'
'-json[causes package data to be printed in JSON format]' '-json[causes package data to be printed in JSON format]'
@ -582,8 +575,7 @@ case $state in
;; ;;
mod) mod)
local -a mod_commands local -a mod_commands=(
mod_commands=(
'download:download modules to local cache' 'download:download modules to local cache'
'edit:edit go.mod from tools or scripts' 'edit:edit go.mod from tools or scripts'
'graph:print module requirement graph' 'graph:print module requirement graph'
@ -763,14 +755,13 @@ case $state in
;; ;;
callgraph) callgraph)
local -a algos graphs local -a algos=(
algos=(
'static:static calls only' 'static:static calls only'
'cha:Class Hierarchy Analysis' 'cha:Class Hierarchy Analysis'
'rta:Rapid Type Analysis' 'rta:Rapid Type Analysis'
'pta:inclusion-based Points-To Analysis' 'pta:inclusion-based Points-To Analysis'
) )
graphs=( local -a graphs=(
'digraph:output in digraph format' 'digraph:output in digraph format'
'graphviz:output in AT&T GraphViz (.dot) format' 'graphviz:output in AT&T GraphViz (.dot) format'
) )
@ -1052,7 +1043,6 @@ case $state in
'*:files:_files' '*:files:_files'
;; ;;
vet) vet)
_arguments \ _arguments \
'-n[print commands that would be executed]' \ '-n[print commands that would be executed]' \
@ -1062,8 +1052,7 @@ case $state in
;; ;;
work) work)
local -a work_commands local -a work_commands=(
work_commands=(
'edit:edit go.work from tools or scripts' 'edit:edit go.work from tools or scripts'
'init:initialize workspace file' 'init:initialize workspace file'
'sync:sync workspace build list to modules' 'sync:sync workspace build list to modules'
@ -1103,10 +1092,8 @@ case $state in
esac esac
;; ;;
help) help)
local -a topics local -a topics=(
topics=(
'buildconstraint:build constraints' 'buildconstraint:build constraints'
'buildmode:build modes' 'buildmode:build modes'
'c:calling between Go and C' 'c:calling between Go and C'