~whereswaldon/gover

6ff3747e326386dbf9b7be43afbe46d9b3a8b5e0 — Chris Waldon 8 months ago 8684e64
bugfix: handle nonexistent versions elegantly
1 files changed, 11 insertions(+), 2 deletions(-)

M gover
M gover => gover +11 -2
@@ 33,13 33,22 @@ install_version() {
    MINOR=$1
    PATCH=$2
    LIB_DIR=$(version_dir "$MINOR" "$PATCH")
    FILENAME=go1.$MINOR.$PATCH.$GOOS-$GOARCH.tar.gz
    DL_PATH=$LIB_DIR/../$FILENAME
    mkdir -p "$LIB_DIR"
    if ! curl -L "https://golang.org/dl/go1.$MINOR.$PATCH.$GOOS-$GOARCH.tar.gz"\
        | tar --strip-components=1 -xzC "$LIB_DIR"; then
    if ! curl -L -o "$DL_PATH" "https://golang.org/dl/$FILENAME"; then
            echo "Couldn't download Go 1.$MINOR.$PATCH. Are you sure it exists?"
            rm "$DL_PATH"
            rm -rf "$LIB_DIR"
            return 1
    fi
    if ! tar --strip-components=1 -xzC "$LIB_DIR" -f "$DL_PATH"; then
            echo "Couldn't download Go 1.$MINOR.$PATCH. Are you sure it exists?"
            rm "$DL_PATH"
            rm -rf "$LIB_DIR"
            return 1
    fi
    rm "$DL_PATH"
}

# activate_version symlinks a particular version of go to be the active