Skip to content

Commit e1ea485

Browse files
authored
dev: refactor and cleanups (#22)
1 parent e36c8d5 commit e1ea485

12 files changed

+811
-854
lines changed

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ linters:
77
- govet
88
- ineffassign
99
- staticcheck
10-
- typecheck
1110
- unused
1211
# disabled by default:
1312
- gocritic
@@ -21,3 +20,5 @@ linters-settings:
2120
- performance
2221
- experimental
2322
- opinionated
23+
disabled-checks:
24+
- importShadow

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ test/cover:
1010
go test -race -shuffle=on -coverprofile=coverage.out ./...
1111
go tool cover -html=coverage.out
1212

13+
build:
14+
go build -o=goversion
15+
1316
lint:
1417
golangci-lint run
1518

README.md

Lines changed: 70 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
[![goreportcard](https://goreportcard.com/badge/go-simpler.org/goversion)](https://goreportcard.com/report/go-simpler.org/goversion)
66
[![codecov](https://codecov.io/gh/go-simpler/goversion/branch/main/graph/badge.svg)](https://codecov.io/gh/go-simpler/goversion)
77

8-
Easily switch between multiple Go versions
8+
Easily switch between multiple Go versions.
99

1010
## 📌 About
1111

12-
Go already supports [installing multiple versions][1] simultaneously as separate binaries,
13-
e.g. `go` (the main version) and `go1.18` (an additional version).
14-
It works just fine when interacting with `go <command>` directly,
15-
but could be inconvenient when the command is wrapped with something like `Makefile` or shell scripts.
16-
The `goversion` tool attempts to solve this by symlinking `go1.X.Y` to `go`,
17-
so any additional Go version could be used as if it was the main one.
12+
Go supports [installing multiple versions][1] simultaneously as separate binaries,
13+
such as `go` (the main version) and `go1.18` (an add-on version).
14+
This works fine when using `go <command>` directly,
15+
but can be inconvenient when the command is hardcoded in a `Makefile` or a shell script.
16+
The `goversion` tool solves this by symlinking `go1.X.Y` to `go`,
17+
so that an add-on version can be used as the main one.
1818

1919
```shell
2020
> go version
21-
go version go1.19 darwin/arm64
21+
go version go1.20 darwin/arm64
2222

2323
> goversion use 1.18
2424
1.18 is not installed. Looking for it on go.dev ...
@@ -31,112 +31,126 @@ go version go1.18 darwin/arm64
3131

3232
## 🚀 Features
3333

34-
* Use any additional Go version as the main one
35-
* List installed Go versions (and, optionally, all available versions)
36-
* Remove an installed Go version with a single command
37-
38-
## ✏️ Pre-requirements
39-
40-
`$GOBIN` (usually `$HOME/go/bin`) must be in your `$PATH` and it must take precedence over the location of the main Go binary (e.g. `/usr/local/go/bin` or `/opt/homebrew/bin`).
34+
* Install and switch between multiple Go versions
35+
* List installed Go versions (optionally, all available versions)
36+
* Remove installed Go versions with a single command
4137

4238
## 📦 Install
4339

44-
### Go
40+
First, add `$GOBIN` (usually `$HOME/go/bin`) to your `$PATH`.
41+
Make sure it takes precedence over the location of the main `go` binary (e.g. `/usr/local/go/bin` or `/opt/homebrew/bin`).
42+
43+
Then install `goversion` with Go...
4544

4645
```shell
4746
go install go-simpler.org/goversion@latest
4847
```
4948

50-
### Manual
49+
...or download a prebuilt binary from the [Releases][2] page.
5150

52-
Download a prebuilt binary from the [Releases][2] page.
53-
54-
## 📋 Commands
51+
## 📋 Usage
5552

5653
### Use
5754

58-
Switches the current Go version (will be installed if not already exists).
55+
Switches the current Go version (will be installed if not exists).
5956

6057
```shell
6158
> goversion use 1.18
6259
Switched to 1.18
6360
```
6461

65-
As a special case, the `main` string can be provided to quickly switch to the main version.
62+
The special [gotip][3] version can be used just like any other.
6663

6764
```shell
68-
> goversion use main
69-
Switched to 1.19 (main)
65+
> goversion use tip
66+
Switched to tip
7067
```
7168

72-
The `gotip` version can be used just like any other.
69+
To switch back to the main version, use the `main` string.
7370

7471
```shell
75-
> goversion use tip
76-
Switched to tip
72+
> goversion use main
73+
Switched to 1.20 (main)
7774
```
7875

79-
To update it, first switch to a stable Go version and then run `gotip download`.
80-
8176
### List
8277

8378
Prints the list of installed Go versions.
8479
The current version is marked with the `*` symbol.
8580

8681
```shell
8782
> goversion ls
88-
1.19 (main)
83+
1.20 (main)
8984
* 1.18
90-
1.17
9185
```
9286

93-
The `-a (-all)` flag can be provided to print available versions from `go.dev` as well.
87+
The `-a (-all)` flag can be used to print also available versions from `go.dev`.
9488

9589
```shell
96-
> goversion ls -a
97-
1.19.4 (not installed)
98-
1.19.3 (not installed)
99-
# ...
100-
1.19 (main)
90+
> goversion ls -all
91+
tip (not installed)
92+
1.20.14 (not installed)
93+
1.20.13 (not installed)
10194
# ...
102-
1.2.2 (not installed)
103-
1 (not installed)
95+
1.3rc1 (not installed)
96+
1.2.2 (not installed)
97+
1 (not installed)
10498
```
10599

106-
The full list is quite long, to limit it the `-only=<prefix>` flag can be used.
100+
The `-only=<prefix>` flag can be used to print only versions starting with the prefix.
107101

108102
```shell
109-
> goversion ls -a -only=1.18
110-
1.18.9 (not installed)
111-
1.18.8 (not installed)
103+
> goversion ls -all -only=1.18
104+
1.18.10 (not installed)
105+
1.18.9 (not installed)
106+
1.18.8 (not installed)
112107
# ...
113-
* 1.18
114-
# ...
115-
1.18beta2 (not installed)
116-
1.18beta1 (not installed)
108+
1.18rc1 (not installed)
109+
1.18beta2 (not installed)
110+
1.18beta1 (not installed)
117111
```
118112

119-
If the `-only=latest` combination is provided, `ls` prints only the latest patch for each minor version.
113+
If the `-only=latest` combination is given, `ls` prints only the latest patch for each version.
120114

121115
```shell
122-
> goversion ls -a -only=latest
123-
1.19.5 (not installed)
124-
1.18.10 (not installed)
125-
# ...
126-
1.10.8 (not installed)
116+
> goversion ls -all -only=latest
117+
tip (not installed)
118+
1.20.14 (not installed)
119+
1.19.13 (not installed)
127120
# ...
128-
1.2.2 (not installed)
129-
1 (not installed)
121+
1.3.3 (not installed)
122+
1.2.2 (not installed)
123+
1 (not installed)
130124
```
131125

132126
### Remove
133127

134-
Removes the specified Go version (both the binary and the SDK).
128+
Removes the specified Go version (both binary and SDK).
135129

136130
```shell
137131
> goversion rm 1.18
138132
Removed 1.18
139133
```
140134

135+
### Help
136+
137+
```shell
138+
Usage: goversion [flags] <command> [command flags]
139+
140+
Commands:
141+
use main switch to the main Go version
142+
use <version> switch to the specified Go version (will be installed if not exists)
143+
ls print the list of installed Go versions
144+
-a (-all) print also available versions from go.dev
145+
-only=<prefix> print only versions starting with the prefix
146+
-only=latest print only the latest patch for each version
147+
rm <version> remove the specified Go version (both binary and SDK)
148+
149+
Flags:
150+
-h (-help) print this message and quit
151+
-v (-version) print the version of goversion itself and quit
152+
```
153+
141154
[1]: https://go.dev/doc/manage-install
142155
[2]: https://github.com/go-simpler/goversion/releases
156+
[3]: https://pkg.go.dev/golang.org/dl/gotip

0 commit comments

Comments
 (0)