Skip to content

Commit

Permalink
Merge pull request #100 from ellotheth/list-known
Browse files Browse the repository at this point in the history
Add -k/--known to list known Go versions
  • Loading branch information
philpennock authored Jul 8, 2017
2 parents 31c7d80 + 27c1e6c commit b56eeef
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions gimme
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#+ -
Expand All @@ -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
Expand Down Expand Up @@ -395,6 +397,25 @@ _list_versions() {
done
}

_list_known() {
local exp="go([[:alnum:]\.]*)\.src.*" # :alnum: catches beta versions too
local list="${GIMME_TMP}/known-versions"

local known
known="$(_list_versions 2>/dev/null)"

_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}" | grep . | sort -n -r | uniq
}

_realpath() {
# shellcheck disable=SC2005
[ -d "$1" ] && echo "$(cd "$1" && pwd)" || echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
Expand Down Expand Up @@ -510,6 +531,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
Expand Down Expand Up @@ -555,6 +577,10 @@ while [[ $# -gt 0 ]]; do
_list_versions
exit 0
;;
-k | --known | known)
_list_known
exit 0
;;
-f | --force | force)
force=1
;;
Expand Down

0 comments on commit b56eeef

Please sign in to comment.