-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
81 lines (60 loc) · 1.79 KB
/
Copy pathmain.go
File metadata and controls
81 lines (60 loc) · 1.79 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
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"git.cmplx.dev/yoko/adoptium"
"git.cmplx.dev/yoko/cmd"
"git.cmplx.dev/yoko/globals"
"git.cmplx.dev/yoko/util"
"github.com/mitchellh/colorstring"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
)
func main() {
var root = cobra.Command{Use: "yoko"}
downloadJDKs := root.PersistentFlags().Bool("install-jdks", false, "always get requrired jdks")
debug := root.PersistentFlags().Bool("debug", false, "run in debug mode")
_ = debug
root.PersistentPreRun = func(cmd *cobra.Command, args []string) {
home, err := homedir.Dir()
if *debug {
home, _ = filepath.Abs("./fakehome")
}
if err != nil {
log.Fatal(err)
}
var yokoHome = filepath.Join(home, ".yoko")
globals.UserCacheDir = yokoHome
jdks := []int{
8, // 1.6.2 - 1.17
17, // 1.17 - 1.20.5
21, // 1.20.5 +
}
missing := []int{}
for _, v := range jdks {
var jdkPath = filepath.Join(yokoHome, fmt.Sprintf("java%d", v))
if _, err := os.Stat(jdkPath); err != nil {
missing = append(missing, v)
} else {
globals.JDKPaths[v] = jdkPath
}
}
if len(missing) > 0 {
var missingStr = strings.Trim(strings.Join(strings.Split(fmt.Sprint(missing), " "), ", "), "[]")
if !*downloadJDKs && !util.Confirm(fmt.Sprintf("[red]Required JDKs (%s) missing, Download?", missingStr)) {
util.Abort()
}
colorstring.Println("[cyan]Downloading required JDKs...")
for _, v := range missing {
var jdkPath = filepath.Join(yokoHome, fmt.Sprintf("java%d", v))
adoptium.GetJDK(v, jdkPath)
globals.JDKPaths[v] = jdkPath
}
}
}
root.AddCommand(cmd.InitCmd, cmd.HydrateCmd, cmd.BuildCmd, cmd.TestCmd, cmd.CleanCmd)
root.Execute()
}