Merge pull request #1267 from cornfeedhobo/fix-go-env-vars
Add multiple path support to go plugin
This commit is contained in:
@@ -5,7 +5,25 @@ about-plugin 'go environment variables & path configuration'
|
|||||||
|
|
||||||
[ ! command -v go &>/dev/null ] && return
|
[ ! command -v go &>/dev/null ] && return
|
||||||
|
|
||||||
|
function _split_path_reverse() {
|
||||||
|
local a=( ${@//:/ } )
|
||||||
|
local i=${#a[@]}
|
||||||
|
local r=
|
||||||
|
while [ $i -gt 0 ] ; do
|
||||||
|
i=$(( i - 1 ))
|
||||||
|
if [ $(( i + 1 )) -eq ${#a[@]} ] ; then
|
||||||
|
r="${a[i]}"
|
||||||
|
else
|
||||||
|
r="${r} ${a[i]}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "$r"
|
||||||
|
}
|
||||||
|
|
||||||
export GOROOT=${GOROOT:-$(go env GOROOT)}
|
export GOROOT=${GOROOT:-$(go env GOROOT)}
|
||||||
pathmunge "${GOROOT}/bin"
|
pathmunge "${GOROOT}/bin"
|
||||||
|
|
||||||
export GOPATH=${GOPATH:-$(go env GOPATH)}
|
export GOPATH=${GOPATH:-$(go env GOPATH)}
|
||||||
pathmunge "${GOPATH}/bin"
|
for p in $( _split_path_reverse ${GOPATH} ) ; do
|
||||||
|
pathmunge "${p}/bin"
|
||||||
|
done
|
||||||
|
|||||||
44
test/plugins/go.plugin.bats
Normal file
44
test/plugins/go.plugin.bats
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
#load ../test_helper
|
||||||
|
load ../../lib/helpers
|
||||||
|
load ../../lib/composure
|
||||||
|
load ../../plugins/available/go.plugin
|
||||||
|
|
||||||
|
@test 'plugins go: reverse path: single entry' {
|
||||||
|
run _split_path_reverse '/foo'
|
||||||
|
echo "output = ${output}"
|
||||||
|
[ "$output" = "/foo" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'plugins go: reverse path: single entry, colon empty' {
|
||||||
|
run _split_path_reverse '/foo:'
|
||||||
|
echo "output = ${output}"
|
||||||
|
[ "$output" = "/foo" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'plugins go: reverse path: single entry, colon whitespace' {
|
||||||
|
run _split_path_reverse '/foo: '
|
||||||
|
echo "output = ${output}"
|
||||||
|
[ "$output" = "/foo" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'plugins go: reverse path: multiple entries' {
|
||||||
|
run _split_path_reverse '/foo:/bar'
|
||||||
|
echo "output = ${output}"
|
||||||
|
[ "$output" = "/bar /foo" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'plugins go: single entry in GOPATH' {
|
||||||
|
export GOPATH="/foo"
|
||||||
|
load ../../plugins/available/go.plugin
|
||||||
|
echo "$(echo $PATH | cut -d':' -f1,2)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f1)" = "/foo/bin" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'plugins go: multiple entries in GOPATH' {
|
||||||
|
export GOPATH="/foo:/bar"
|
||||||
|
load ../../plugins/available/go.plugin
|
||||||
|
echo "$(echo $PATH | cut -d':' -f1,2)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f1,2)" = "/foo/bin:/bar/bin" ]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user