From 0521a462f07b698090b8fb3220c07755899e9108 Mon Sep 17 00:00:00 2001 From: Gemma Lynn Date: Thu, 6 Jul 2017 15:35:57 +0200 Subject: [PATCH 1/5] add -k to list known Go versions --- gimme | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gimme b/gimme index d3e11a9..e65fcf8 100755 --- a/gimme +++ b/gimme @@ -395,6 +395,23 @@ _list_versions() { done } +_list_known() { + local exp="go([[:alnum:]\.]*)\.src.*" # :alnum: catches beta versions too + local list="${GIMME_TMP}/known-versions" + local known="" + + _do_curl "${GIMME_LIST_KNOWN}" "${list}" + + while read -r line; do + if [[ "${line}" =~ ${exp} ]]; then + known="$known\n${BASH_REMATCH[1]}" + fi + done <"${list}" + + rm -f "${list}" &>/dev/null + echo -e "${known}" |sort -n -r |uniq +} + _realpath() { # shellcheck disable=SC2005 [ -d "$1" ] && echo "$(cd "$1" && pwd)" || echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" @@ -510,6 +527,7 @@ _to_goarch() { : "${GIMME_TYPE:=auto}" # 'auto', 'binary', 'source', or 'git' : "${GIMME_BINARY_OSX:=osx10.8}" : "${GIMME_DOWNLOAD_BASE:=https://storage.googleapis.com/golang}" +: "${GIMME_LIST_KNOWN:=https://golang.org/dl}" # The version prefix must be an absolute path case "${GIMME_VERSION_PREFIX}" in @@ -555,6 +573,10 @@ while [[ $# -gt 0 ]]; do _list_versions exit 0 ;; + -k | --known | known) + _list_known + exit 0 + ;; -f | --force | force) force=1 ;; From 81119264af67d2803fbd6631d8d82a9fdce4503d Mon Sep 17 00:00:00 2001 From: Gemma Lynn Date: Sat, 8 Jul 2017 10:38:38 +0200 Subject: [PATCH 2/5] add -k to the help text --- gimme | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gimme b/gimme index e65fcf8..76b9703 100755 --- a/gimme +++ b/gimme @@ -17,6 +17,7 @@ #+ -V --version version - show the version only and exit #+ -f --force force - remove the existing go installation if present prior to install #+ -l --list list - list installed go versions and exit +#+ -k --known known - list known go versions and exit #+ - #+ Influential env vars: #+ - @@ -37,6 +38,7 @@ #+ GIMME_CGO_ENABLED - enable build of cgo support #+ GIMME_CC_FOR_TARGET - cross compiler for cgo support #+ GIMME_DOWNLOAD_BASE - override base URL dir for download (default '${GIMME_DOWNLOAD_BASE}') +#+ GIMME_LIST_KNOWN - override base URL for known go versions (default '${GIMME_LIST_KNOWN}') #+ - # set -e From 79ef137a062e3441819e273a3dfc0975295cc415 Mon Sep 17 00:00:00 2001 From: Gemma Lynn Date: Sat, 8 Jul 2017 11:53:56 +0200 Subject: [PATCH 3/5] fix linter errors --- gimme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gimme b/gimme index 76b9703..9c5e169 100755 --- a/gimme +++ b/gimme @@ -411,7 +411,7 @@ _list_known() { done <"${list}" rm -f "${list}" &>/dev/null - echo -e "${known}" |sort -n -r |uniq + echo -e "${known}" | sort -n -r | uniq } _realpath() { From 6092bd04e98f2401569f72742bbb1c8107cef924 Mon Sep 17 00:00:00 2001 From: Gemma Lynn Date: Sat, 8 Jul 2017 20:41:10 +0200 Subject: [PATCH 4/5] filter blank lines --- gimme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gimme b/gimme index 9c5e169..f81a5f6 100755 --- a/gimme +++ b/gimme @@ -411,7 +411,7 @@ _list_known() { done <"${list}" rm -f "${list}" &>/dev/null - echo -e "${known}" | sort -n -r | uniq + echo -e "${known}" | grep . | sort -n -r | uniq } _realpath() { From 27c1e6ca4578628ac2eacfb432df5a01b002c6c2 Mon Sep 17 00:00:00 2001 From: Gemma Lynn Date: Sat, 8 Jul 2017 20:54:36 +0200 Subject: [PATCH 5/5] include locally-installed versions in -k --- gimme | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gimme b/gimme index f81a5f6..973d775 100755 --- a/gimme +++ b/gimme @@ -400,7 +400,9 @@ _list_versions() { _list_known() { local exp="go([[:alnum:]\.]*)\.src.*" # :alnum: catches beta versions too local list="${GIMME_TMP}/known-versions" - local known="" + + local known + known="$(_list_versions 2>/dev/null)" _do_curl "${GIMME_LIST_KNOWN}" "${list}"