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() {
local -a buildmodes
buildmodes=(
local -a buildmodes=(
'archive[non-main packages into .a files]'
'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]'
@ -60,10 +59,8 @@ __go_buildmodes() {
_values 'mode' $buildmodes
}
__go_runtimedebug() {
local -a vars
vars=(
local -a vars=(
'allocfreetrace[profile allocations]: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"))'
@ -173,7 +170,7 @@ __go_gcflags() {
'-trimpath=[remove prefix from recorded source file paths]:prefix' \
'-v[increase debug verbosity]' \
'-w[debug type checking]' \
'-wb[enable write barrier (default true)]' \
'-wb[enable write barrier (default true)]'
}
__go_pgo() {
@ -182,27 +179,27 @@ __go_pgo() {
"file:file:_files"
}
local -a commands build_flags
commands=(
'bug:start a bug report'
'build:compile packages and dependencies'
'clean:remove object files and cached files'
'doc:show documentation for package or symbol'
'env:print Go environment information'
'fix:update packages to use new APIs'
'fmt:gofmt (reformat) 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 or modules'
'mod:module maintenance'
'work:workspace maintenance'
'run:compile and run Go program'
'test:test packages'
'tool:run specified go tool'
'version:print Go version'
'vet:report likely mistakes in packages'
'help:get more information about a command'
local -a build_flags
local -a commands=(
'bug:start a bug report'
'build:compile packages and dependencies'
'clean:remove object files and cached files'
'doc:show documentation for package or symbol'
'env:print Go environment information'
'fix:update packages to use new APIs'
'fmt:gofmt (reformat) 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 or modules'
'mod:module maintenance'
'work:workspace maintenance'
'run:compile and run Go program'
'test:test packages'
'tool:run specified go tool'
'version:print Go version'
'vet:report likely mistakes in packages'
'help:get more information about a command'
)
__go_envvarvals() {
@ -368,21 +365,20 @@ case $state in
'-trimpath[remove all file system paths from the resulting executable]'
'-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)'
'-modcacherw[leave newly-created directories in the module cache read-write]'
'-modfile=[read an alternate go.mod file]:modfile: _files -g "*.mod"'
)
edit_flags=(
'-fmt[reformats the go.mod/work file without making other changes]' \
'*-require=[add a requirement on the given module path and version]:require' \
'*-droprequire=[drop a requirement on the given module path and version]:droprequire' \
'-go[sets the expected Go language version]:goversion' \
'*-replace=[add a replacement of the given module path and version]:replace' \
'*-dropreplace=[drop a replacement of the given module path and version]:dropreplace' \
'-json[prints the final go.mod/work file in JSON format]' \
'-print[prints the final go.mod/work in its text format]' \
local -a edit_flags=(
'-fmt[reformats the go.mod/work file without making other changes]'
'*-require=[add a requirement on the given module path and version]:require'
'*-droprequire=[drop a requirement on the given module path and version]:droprequire'
'-go[sets the expected Go language version]:goversion'
'*-replace=[add a replacement of the given module path and version]:replace'
'*-dropreplace=[drop a replacement of the given module path and version]:dropreplace'
'-json[prints the final go.mod/work file in JSON format]'
'-print[prints the final go.mod/work in its text format]'
)
__go_packages() {
@ -438,8 +434,7 @@ case $state in
;;
env)
local -a goenvvars
goenvvars=(
local -a goenvvars=(
"GOARCH[architecture, or processor, for which to compile code.]:architecture"
"GCCGO[gccgo command to run.]:gccgo command"
"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"
"GOTOOLDIR[installation directory of go tools]:tool installation directory"
)
local -a exclude_from_w
exclude_from_w=(GOENV)
local -a exclude_from_w=(GOENV)
__list_env_vars() {
# the parameter expansion strops off everything after the first [
@ -559,8 +553,7 @@ case $state in
;;
list)
local -a list_args
list_args=(
local -a list_args=(
'-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]'
@ -582,8 +575,7 @@ case $state in
;;
mod)
local -a mod_commands
mod_commands=(
local -a mod_commands=(
'download:download modules to local cache'
'edit:edit go.mod from tools or scripts'
'graph:print module requirement graph'
@ -763,14 +755,13 @@ case $state in
;;
callgraph)
local -a algos graphs
algos=(
local -a algos=(
'static:static calls only'
'cha:Class Hierarchy Analysis'
'rta:Rapid Type Analysis'
'pta:inclusion-based Points-To Analysis'
)
graphs=(
local -a graphs=(
'digraph:output in digraph format'
'graphviz:output in AT&T GraphViz (.dot) format'
)
@ -1052,7 +1043,6 @@ case $state in
'*:files:_files'
;;
vet)
_arguments \
'-n[print commands that would be executed]' \
@ -1062,8 +1052,7 @@ case $state in
;;
work)
local -a work_commands
work_commands=(
local -a work_commands=(
'edit:edit go.work from tools or scripts'
'init:initialize workspace file'
'sync:sync workspace build list to modules'
@ -1103,10 +1092,8 @@ case $state in
esac
;;
help)
local -a topics
topics=(
local -a topics=(
'buildconstraint:build constraints'
'buildmode:build modes'
'c:calling between Go and C'