Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -k/--known to list known Go versions #100

Merged
merged 5 commits into from
Jul 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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