-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
71 lines (67 loc) · 1.62 KB
/
main.go
File metadata and controls
71 lines (67 loc) · 1.62 KB
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
package main
import (
"github.com/andreimerlescu/go-common/version"
"github.com/andreimerlescu/igo/internal"
"github.com/fatih/color"
"log"
"os"
"runtime"
)
func main() {
if runtime.GOOS == "windows" {
panic("windows not supported, please use Go's MSI installers instead")
}
app := NewApp()
if *app.Figs.Bool(cmdVersion) {
color.Magenta(BinaryVersion() + " - " + internal.About())
os.Exit(0)
}
if *app.Figs.Bool(cmdList) {
list(app)
return
}
if *app.Figs.Bool(cmdEnv) {
env(app)
return
}
maybeVersions := map[string]string{
"install": *app.Figs.String(cmdInstall),
"uninstall": *app.Figs.String(cmdUninstall),
"fix": *app.Figs.String(cmdFix),
"activate": *app.Figs.String(cmdActivate),
"switch": *app.Figs.String(cmdSwitch),
}
for command, maybeVersion := range maybeVersions {
if len(maybeVersion) == 0 {
continue
}
if err := app.validateVersion(maybeVersion); err != nil {
if *app.Figs.Bool(kVerbose) || *app.Figs.Bool(kDebug) {
color.Red("ErrBadVersion(%T %s): %w", maybeVersion, maybeVersion, err)
}
log.Fatalf("ErrBadVersion(%T %s): %s", maybeVersion, maybeVersion, err.Error())
}
ver := version.FromString(maybeVersion)
if ver.String() == "v0.0.1" {
log.Fatalf("failed to parse the version: %s", ver.String())
}
switch command {
case "install":
if len(maybeVersion) > 0 {
install(app, maybeVersion)
}
case "uninstall":
if len(maybeVersion) > 0 {
uninstall(app, maybeVersion)
}
case "fix":
if len(maybeVersion) > 0 {
fix(app, maybeVersion)
}
default:
if len(maybeVersion) > 0 {
use(app, maybeVersion)
}
}
}
}