Update 'go fix' completion
This commit is contained in:
parent
5a4bbc1ad8
commit
057d9a9940
75
src/_golang
75
src/_golang
|
@ -320,6 +320,40 @@ __go_envvarvals() {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__go_packages() {
|
||||||
|
local -a gopaths=("${(s/:/)$(go env GOPATH)}")
|
||||||
|
gopaths+=("$(go env GOROOT)")
|
||||||
|
for p in $gopaths; do
|
||||||
|
_path_files $@ -W "$p/src" -/
|
||||||
|
done
|
||||||
|
# no special treatment for
|
||||||
|
# - relative paths starting with ..
|
||||||
|
# - absolute path starting with /
|
||||||
|
# - variables, substitutions, subshells
|
||||||
|
if [[ $words[$CURRENT] = ..* || $words[$CURRENT] = \$* || $words[$CURRENT] = /* ]]; then
|
||||||
|
_path_files $@ -/ -g '*.go'
|
||||||
|
else
|
||||||
|
# go build accepts paths relative to the cwd but they must start with './', so prefix them
|
||||||
|
_path_files $@ -P './' -/ -g '*.go'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
__go_fix_names() {
|
||||||
|
local -a fix_names=(
|
||||||
|
'buildtag[remove +build comments from modules using Go 1.18 or later]'
|
||||||
|
'cftype[fixes initialzers and casts of C.*Ref and JNI types]'
|
||||||
|
'context[Change imports of golang.org/x/net/context to context]'
|
||||||
|
'egl[fixes initializers of EGLDisplay]'
|
||||||
|
'eglconf[fixes initializers of EGLConfig]'
|
||||||
|
'gotypes[change imports of oglang.org/x/tools/go{exact,types} to go/{constant,types}]'
|
||||||
|
"jni[fixes initializers of JNI's jobject and subtypes]"
|
||||||
|
'netipv6zone[adapt element key to IPAddr, UPDAddr, TCPAddr composite literals]'
|
||||||
|
'printerconfig[add element keys to Config composite literals]'
|
||||||
|
)
|
||||||
|
|
||||||
|
_values -s ',' 'fix name' $fix_names
|
||||||
|
}
|
||||||
|
|
||||||
if [[ "$service" = -value-* ]]; then
|
if [[ "$service" = -value-* ]]; then
|
||||||
variable=${${service%,-default-}#-value-,}
|
variable=${${service%,-default-}#-value-,}
|
||||||
# some special variables are not read from the environment
|
# some special variables are not read from the environment
|
||||||
|
@ -382,26 +416,6 @@ case $state in
|
||||||
'-print[prints the final go.mod/work in its text format]'
|
'-print[prints the final go.mod/work in its text format]'
|
||||||
)
|
)
|
||||||
|
|
||||||
__go_packages() {
|
|
||||||
local gopaths
|
|
||||||
declare -a gopaths
|
|
||||||
gopaths=("${(s/:/)$(go env GOPATH)}")
|
|
||||||
gopaths+=("$(go env GOROOT)")
|
|
||||||
for p in $gopaths; do
|
|
||||||
_path_files $@ -W "$p/src" -/
|
|
||||||
done
|
|
||||||
# no special treatment for
|
|
||||||
# - relative paths starting with ..
|
|
||||||
# - absolute path starting with /
|
|
||||||
# - variables, substitutions, subshells
|
|
||||||
if [[ $words[$CURRENT] = ..* || $words[$CURRENT] = \$* || $words[$CURRENT] = /* ]]; then
|
|
||||||
_path_files $@ -/ -g '*.go'
|
|
||||||
else
|
|
||||||
# go build accepts paths relative to the cwd but they must start with './', so prefix them
|
|
||||||
_path_files $@ -P './' -/ -g '*.go'
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
case $words[1] in
|
case $words[1] in
|
||||||
build)
|
build)
|
||||||
_arguments \
|
_arguments \
|
||||||
|
@ -495,7 +509,7 @@ case $state in
|
||||||
)
|
)
|
||||||
local -a exclude_from_w=(GOENV)
|
local -a exclude_from_w=(GOENV)
|
||||||
|
|
||||||
__list_env_vars() {
|
__go_list_env_vars() {
|
||||||
# the parameter expansion strops off everything after the first [
|
# the parameter expansion strops off everything after the first [
|
||||||
_values -s ' ' -w 'environment variable' ${goenvvars[@]%%\[*}
|
_values -s ' ' -w 'environment variable' ${goenvvars[@]%%\[*}
|
||||||
}
|
}
|
||||||
|
@ -507,13 +521,17 @@ case $state in
|
||||||
'-json[print the environment in JSON format]' \
|
'-json[print the environment in JSON format]' \
|
||||||
'-u[unset environment variables]' \
|
'-u[unset environment variables]' \
|
||||||
'-w[change the default setting of environment variables]' \
|
'-w[change the default setting of environment variables]' \
|
||||||
'*:[show environment variable]: __list_env_vars' || _values \
|
'*:[show environment variable]: __go_list_env_vars' || _values \
|
||||||
-s ' ' -S "=" -w 'environment variable' ${^goenvvars:#GOENV*}": __go_envvarvals"
|
-s ' ' -S "=" -w 'environment variable' ${^goenvvars:#GOENV*}": __go_envvarvals"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
fix)
|
(fix)
|
||||||
_arguments \
|
_arguments \
|
||||||
'-C[change to directory before running the command]: :_files -/' \
|
'-C[change to directory before running the command]: :_files -/' \
|
||||||
|
'-diff[display diffs instead of rewriting files]' \
|
||||||
|
'-force[force these fixes to run even if the code looks updated]:fix_names:__go_fix_names' \
|
||||||
|
'-go[go language version for files]:version' \
|
||||||
|
'-r[restrict the rewrites to this comma-separated list]:fix_names:__go_fix_names' \
|
||||||
'*:importpaths:__go_packages'
|
'*:importpaths:__go_packages'
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -860,11 +878,11 @@ case $state in
|
||||||
'*:file:_files -g "*.go(-.)"'
|
'*:file:_files -g "*.go(-.)"'
|
||||||
;;
|
;;
|
||||||
|
|
||||||
doc)
|
(doc)
|
||||||
_arguments \
|
_arguments \
|
||||||
'-c[respect case when matching symbols]' \
|
'-c[respect case when matching symbols]' \
|
||||||
'-cmd[treat a command (package main) like a regular package]' \
|
'-cmd[treat a command (package main) like a regular package]' \
|
||||||
'-u[show docs for unexported and exported symbols and methods]' \
|
'-u[show docs for unexported and exported symbols and methods]'
|
||||||
;;
|
;;
|
||||||
|
|
||||||
fix)
|
fix)
|
||||||
|
@ -1023,13 +1041,6 @@ case $state in
|
||||||
'-v[verbose]' \
|
'-v[verbose]' \
|
||||||
'*:files:_files'
|
'*:files:_files'
|
||||||
;;
|
;;
|
||||||
|
|
||||||
yacc)
|
|
||||||
_arguments \
|
|
||||||
'-o[output]:output' \
|
|
||||||
'-v[parsetable]:parsetable' \
|
|
||||||
'*:files:_files'
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in New Issue