Skip to content

Commit

Permalink
Add support for listing and installing unstable versions
Browse files Browse the repository at this point in the history
This also adds a big performance boost when loading remote versions.
This is because we switched the versions source from the golang.org
download page to the web UI of the git project hosted at
googlesource.com

https://go.googlesource.com/go/+refs   25 KB   59 ms
https://golang.org/dl/                341 KB  371 ms

This was not the actual reason for the switch, but the fact that the
golang.org download page doesn't list any previuos unstable versions.
  • Loading branch information
stefanmaric committed Jul 8, 2019
1 parent 0580331 commit ed51afd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changelog

## Unreleased

- Add support for listing and installing unstable versions
- Prevent bugs in config files without final newline
- Ensure the modified PATH is exported on bash and zsh
- Prevent multiple selection of the same shell in g-install
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ curl -sSL https://git.io/g-install | bash
-y, --non-interactive Prevent prompts
-o, --os Override operating system
-a, --arch Override system architecture
-u, --unstable Include unstable versions in list
```

## Uninstall
Expand Down Expand Up @@ -216,7 +217,7 @@ At this point you would have removed `g` and `go` entirely.
- [x] Add non-interactive mode
- [x] Warn about installing in an uncommon path. See #5
- [x] Upgrade script
- [ ] Add support to select `unstable` versions
- [x] Add support to select `unstable` versions
- [x] Install requested version when `g run` cannot find it. See #3
- [ ] Use better naming for `g install <version>`, maybe `use` or `set`. See #8
- [x] Improve the --quiet and --non-interactive modifiers
Expand Down
20 changes: 16 additions & 4 deletions bin/g
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ACTIVATE=true
QUIET=false
NO_COLOR=false
NON_INTERACTIVE=false
INCLUDE_UNSTABLE=false
STDIN=
ARCH=
OS=
Expand Down Expand Up @@ -101,6 +102,7 @@ display_help() {
-y, --non-interactive Prevent prompts
-o, --os Override operating system
-a, --arch Override system architecture
-u, --unstable Include unstable versions in list
EOF
}
Expand Down Expand Up @@ -269,11 +271,20 @@ download() {
#

get_all_remote_versions() {
download 2> /dev/null "https://golang.org/dl/" \
| grep -E -o '\"https://dl.google.com/go/go.*\.tar\.gz\"' \
| grep -E -o 'go[[:digit:]]+\.[[:digit:]]+(\.[[:digit:]]+)?\b' \
local pattern

if [[ "$INCLUDE_UNSTABLE" = true ]]; then
pattern='go[[:digit:]]+(\.[[:alnum:]]+)+\b'
else
pattern='go[[:digit:]]+(\.[[:digit:]]+)+\b'
fi

download 2> /dev/null "https://go.googlesource.com/go/+refs" \
| grep -E -o '\"/go/\+/refs/tags/go.+?\"' \
| grep -E -o "$pattern" \
| tr -d 'go' \
| sort -u -k 1,1n -k 2,2n -k 3,3n -t .
| sort -k 1,1n -k 2,2n -k 3,3n -t . \
| uniq
}


Expand Down Expand Up @@ -701,6 +712,7 @@ else
-y|--non-interactive) NON_INTERACTIVE=true;;
-o|--os) shift; OS=$1;;
-a|--arch) shift; ARCH=$1;;
-u|--unstable) INCLUDE_UNSTABLE=true;;
--) __cmd_args+=("$@"); break;;
*) __cmd_args+=("$1");;
esac
Expand Down

0 comments on commit ed51afd

Please sign in to comment.