#!/bin/sh set -e usage() { base="$(basename "$0")" cat <&2 exit 1 fi # "shift" so that "$@" becomes the remaining arguments and can be passed along to other "go" subcommands easily cmd="$1" shift 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) set -- go get -v -d "$@" if [ "$goDir" ]; then set -- "$@" "$goDir"; fi set -x; exec "$@" ;; install) set -- go install -v "$@" if [ "$goDir" ]; then set -- "$@" "$goDir"; fi set -x; exec "$@" ;; run) set -x; exec "$goBin" "$@" ;; *) echo >&2 'error: unknown command:' "$cmd" usage >&2 exit 1 ;; esac