~whereswaldon/gover

79922712c6e46b81890d15ba323f86b5f7ef702b — Chris Waldon 8 months ago 7a860c6
feat: more friendly and descriptive output

This commit stops showing the raw curl download progress in favor of messages explaining
what we're doing with curl. This has the disadvantage of hiding the progress of the
download, but I think that's probably reasonable.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
1 files changed, 8 insertions(+), 3 deletions(-)

M gover
M gover => gover +8 -3
@@ 66,12 66,14 @@ install_version() {
    FILENAME=go$target.$GOOS-$GOARCH.tar.gz
    DL_PATH=$LIB_DIR/../$FILENAME
    mkdir -p "$LIB_DIR"
    if ! curl -L -o "$DL_PATH" "https://go.dev/dl/$FILENAME"; then
    echo "Downloading $target"
    if ! curl -s -L -o "$DL_PATH" "https://go.dev/dl/$FILENAME"; then
            echo "Couldn't download Go $target. Are you sure it exists?"
            rm "$DL_PATH"
            rm -rf "$LIB_DIR"
            return 1
    fi
    echo "Extracting $target"
    if ! tar --strip-components=1 -xzC "$LIB_DIR" -f "$DL_PATH"; then
            echo "Couldn't uncompress Go $target."
            rm "$DL_PATH"


@@ 91,7 93,7 @@ activate_version() {

# latest_version emits the latest version of go on stdout
latest_version() {
    versions=$(curl -q https://api.github.com/repos/golang/go/git/refs/tags | grep -e "\"ref\":" | grep -e "go" | grep -v -e "beta" -e "rc" | sed -E 's/.*go([[:digit:]]+(.[[:digit:]]+){0,2}).*/\1/')
    versions=$(curl -s -q https://api.github.com/repos/golang/go/git/refs/tags | grep -e "\"ref\":" | grep -e "go" | grep -v -e "beta" -e "rc" | sed -E 's/.*go([[:digit:]]+(.[[:digit:]]+){0,2}).*/\1/')
    highest_major=0
    highest_minor=0
    highest_patch=0


@@ 123,7 125,10 @@ latest_version() {

gover() {
    target="$1"
    if [ "$target" = "latest" ]; then target=$(latest_version); fi
    if [ "$target" = "latest" ]; then
        echo "Looking up latest version..."
        target=$(latest_version)
    fi
    if [ "$target" = "-h" ] || [ "$target" = "--help" ]; then
        printf "Usage: gover [version|latest]\n\nExamples:\n\tgover 1.15\n\tgover 1.7.1\n\tgover latest\n\tgover\n"
        return 1