#!/bin/bash set -e usage() { base="$(basename "$0")" cat <&2 exit 1 fi goDir="$(go list -e -f '{{.ImportComment}}' 2>/dev/null || true)" if [ -z "$goDir" -a -s .godir ]; then goDir="$(cat .godir)" fi dir="$(pwd -P)" if [ "$goDir" ]; then goPath="${GOPATH%%:*}" # this just grabs the first path listed in GOPATH, if there are multiple (which is the detection logic "go get" itself uses, too) goDirPath="$goPath/src/$goDir" mkdir -p "$(dirname "$goDirPath")" if [ ! -e "$goDirPath" ]; then ln -sfv "$dir" "$goDirPath" elif [ ! -L "$goDirPath" ]; then echo >&2 "error: $goDirPath already exists but is unexpectedly not a symlink!" exit 1 fi goBin="$goPath/bin/$(basename "$goDir")" else goBin="$(basename "$dir")" # likely "app" fi case "$cmd" in download) execCommand=( go get -v -d "$@" ) if [ "$goDir" ]; then execCommand+=( "$goDir" ); fi set -x; exec "${execCommand[@]}" ;; install) execCommand=( go install -v "$@" ) if [ "$goDir" ]; then execCommand+=( "$goDir" ); fi set -x; exec "${execCommand[@]}" ;; run) set -x; exec "$goBin" "$@" ;; *) echo >&2 'error: unknown command:' "$cmd" usage >&2 exit 1 ;; esac