mirror of
https://github.com/wahyd4/gvm.git
synced 2026-08-09 04:46:19 +10:00
While replacing pakcageset name with "--local", the packageset information will be managed under some/local/repo/.gvm_local folder, and add the root path of repository as the first path in GOPATH and PATH. This makes the repository more portable since we don't store all the go-installed package files under $HOME/.gvm . The repository root path for gvm is definded as $PWD while "pkgset create --local" . When "pkgset list" under some configured local repository, it will list the root path as the first packageset, and marked with "L".
45 lines
1.5 KiB
Bash
45 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
function gvm_pkgset_use() {
|
|
[[ "$1" != "" ]] ||
|
|
display_error "Please specify a package set" || return 1
|
|
|
|
[[ "$gvm_go_name" != "" ]] ||
|
|
display_error "No Go version selected" || return 1
|
|
|
|
if [[ "$1" == "--local" ]]; then
|
|
. $GVM_ROOT/scripts/function/find_local_pkgset
|
|
local LOCAL_TOP=$(find_local_pkgset)
|
|
unset -f find_local_pkgset
|
|
[[ -d $LOCAL_TOP ]] ||
|
|
display_error "Caonnt find local pakcage set" || return 1
|
|
LOCAL_TOP=$LOCAL_TOP/.gvm_local
|
|
|
|
fuzzy_match=`$LS_PATH $LOCAL_TOP/environments | $SORT_PATH | $GREP_PATH "$gvm_go_name@" | $GREP_PATH "local" | $HEAD_PATH -n 1` ||
|
|
display_error "Cannot find local package set" || return 1
|
|
|
|
[[ "$2" != "--default" ]] ||
|
|
display_error "Cannot set local pkgset as default" || return 1
|
|
|
|
export PATH=$GVM_PATH_BACKUP
|
|
. "$LOCAL_TOP/environments/$fuzzy_match" ||
|
|
display_error "Failed to source the package set environment" || return 1
|
|
|
|
echo "Now using version $gvm_go_name in local package set"
|
|
echo "Local GOPATH is now $LOCAL_TOP"
|
|
else
|
|
fuzzy_match=`$LS_PATH $GVM_ROOT/environments | $SORT_PATH | $GREP_PATH "$gvm_go_name@" | $GREP_PATH "$1" | $HEAD_PATH -n 1` ||
|
|
display_error "Invalid package set" || return 1
|
|
|
|
export PATH=$GVM_PATH_BACKUP
|
|
. "$GVM_ROOT/environments/$fuzzy_match" ||
|
|
display_error "Failed to source the package set environment" || return 1
|
|
|
|
if [[ "$2" == "--default" ]]; then
|
|
cp $GVM_ROOT/environments/$fuzzy_match $GVM_ROOT/environments/default
|
|
fi
|
|
|
|
echo "Now using version $fuzzy_match"
|
|
fi
|
|
}
|
|
|