-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
97 lines (84 loc) · 2.8 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"os"
"github.com/lpww/govs/app"
"github.com/thatisuday/commando"
)
func FatalError(err error) {
fmt.Println(err.Error())
os.Exit(1)
}
func main() {
commando.
SetExecutableName("govs").
SetVersion("v1.0.3").
SetDescription("A tool for installing and managing multiple go versions")
commando.
Register("releases").
SetDescription("This command displays all official go language releases available for download").
SetShortDescription("List available go releases").
SetAction(func(args map[string]commando.ArgValue, flags map[string]commando.FlagValue) {
err := app.Releases()
if err != nil {
FatalError(err)
}
})
commando.
Register("install").
SetDescription("This command installs the specified version of go and makes it available with a version specific binary, go<version>. Eg: `go1.18.5`").
SetShortDescription("Install a go version").
AddArgument("version", "The version to install", "").
SetAction(func(args map[string]commando.ArgValue, flags map[string]commando.FlagValue) {
err := app.Install(args)
if err != nil {
FatalError(err)
}
})
commando.
Register("list").
SetDescription("This command lists the installed go versions available on the system").
SetShortDescription("List installed go versions").
SetAction(func(args map[string]commando.ArgValue, flags map[string]commando.FlagValue) {
err := app.List()
if err != nil {
FatalError(err)
}
})
commando.
Register("set").
SetDescription("This command uses a symlink to create a default version for the `go` command").
SetShortDescription("Set the default go version").
AddArgument("version", "The version to set as the default", "").
SetAction(func(args map[string]commando.ArgValue, flags map[string]commando.FlagValue) {
err := app.Set(args)
if err != nil {
FatalError(err)
}
})
commando.
Register("get").
SetDescription("This command will install the specified version and set it as the default version for the `go` command").
SetShortDescription("Install and set the default go version").
AddArgument("version", "The version to install and set as the default", "").
SetAction(func(args map[string]commando.ArgValue, flags map[string]commando.FlagValue) {
if err := app.Install(args); err != nil {
FatalError(err)
}
if err := app.Set(args); err != nil {
FatalError(err)
}
})
commando.
Register("remove").
SetDescription("This command removes the specified version of go").
SetShortDescription("Remove a go version").
AddArgument("version", "The version to remove", "").
SetAction(func(args map[string]commando.ArgValue, flags map[string]commando.FlagValue) {
err := app.Remove(args)
if err != nil {
FatalError(err)
}
})
commando.Parse(nil) // nil tells commando to use stdin arguments
}