-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.go
163 lines (150 loc) · 4.67 KB
/
cli.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
)
// InteractiveCliInstall installs mods from the command line.
func InteractiveCliInstall() {
// Lock Mutexes.
selectedVersionMutex.Lock()
installFabricOptMutex.Lock()
minecraftFolderMutex.Lock()
defer selectedVersionMutex.Unlock()
defer installFabricOptMutex.Unlock()
defer minecraftFolderMutex.Unlock()
println("ibu's mod installer - CLI")
println("FAQ: Open the GUI, or use https://mythicmc.org/modpack/faq.html")
println("")
// Detect if update is possible.
updatableVersions := getUpdatableVersions()
versions := "1.14.4/1.15.2/1.16.5/1.17.1/1.18.2/1.19.4/1.20.4"
if len(updatableVersions) > 0 {
versions += " (updatable: " + strings.Join(updatableVersions, ", ") + ")"
}
/* updatable := areModsUpdatable()
if updatable != "" {
update := takeInput(
"It looks like you already have "+updatable+" version installed. "+
"Would you like to update your mods for "+updatable+" to the latest version? [yes/no]",
&Inputs{"y", "yes", "n", "no"},
)
if update == "y" || update == "yes" {
confirm := takeInput("Confirm? [yes/no]", &Inputs{"y", "yes", "n", "no"})
if confirm == "y" || confirm == "yes" {
selectedVersion = updatable
err := installMods(func(s string) { println(s) }, func(s string) bool {
response := takeInput(s+" [yes/no]", &Inputs{"y", "yes", "n", "no"})
if response == "y" || response == "yes" {
return true
}
return false
})
if err != nil {
log.Println(err)
print("An error occurred. Press Enter on keyboard to close.")
inputHalt()
os.Exit(1)
} else {
print("Installation succeeded. Press Enter on keyboard to close.")
inputHalt()
return
}
} else {
println("Alright, sending you to the installation prompt instead of updating your mods.")
}
} else {
println("Alright, sending you to the installation prompt instead of updating your mods.")
}
} */
// Take inputs.
selectedVersion = getMajorMinecraftVersion(takeInput(
"Version of Minecraft to use? ["+versions+"]",
&Inputs{
"1.14.4", "1.15.2", "1.16.5", "1.17.1", "1.18.2", "1.19.4", "1.20.4",
"1.14", "1.15", "1.16", "1.17", "1.18", "1.19", "1.20",
},
))
println("")
quilt := "Quilt"
if strings.HasPrefix(selectedVersion, "1.14") ||
strings.HasPrefix(selectedVersion, "1.15") ||
strings.HasPrefix(selectedVersion, "1.16") ||
strings.HasPrefix(selectedVersion, "1.17") {
quilt = "Fabric"
}
installFabric := takeInput("Should the modpack install "+quilt+"? [yes/no]", &Inputs{"y", "yes", "n", "no"})
if installFabric == "y" || installFabric == "yes" {
installFabricOpt = true
} else {
installFabricOpt = false
}
println("")
minecraftFolderYes := takeInput("Do you want to install to custom .minecraft folder? [yes/no]", &Inputs{"y", "yes", "n", "no"})
if minecraftFolderYes == "y" || minecraftFolderYes == "yes" {
minecraftFolder = takeInput("Enter path to .minecraft folder:", nil)
}
println("")
// Confirm.
println("Installing mods for " + selectedVersion + " (Install " + quilt + ": " + strconv.FormatBool(installFabricOpt) + ")")
confirm := takeInput("Confirm? [yes/no]", &Inputs{"y", "yes", "n", "no"})
if confirm == "n" || confirm == "no" {
print("Installation cancelled! Exiting...")
inputHalt()
os.Exit(1)
}
// Install the mods.
err := installMods(func(s string) { println(s) }, func(s string) bool {
response := takeInput(s+" [yes/no]", &Inputs{"y", "yes", "n", "no"})
if response == "y" || response == "yes" {
return true
}
return false
})
if err != nil {
log.Println(err)
print("An error occurred. Press Enter on keyboard to close.")
inputHalt()
os.Exit(1)
}
print("Installation succeeded. Press Enter on keyboard to close.")
inputHalt()
}
func inputHalt() {
var input string
fmt.Scanln(&input)
}
func takeInput(prompt string, inputs *Inputs) string {
for {
print(prompt + " ")
var input string
fmt.Scanln(&input)
if inputs != nil && inputs.IsValidInput(input) {
return input
} else if inputs == nil {
return input
}
println("Invalid input! Possible values: " + strings.Join(*inputs, ", "))
}
}
// Inputs is a type that defines a set of valid inputs.
type Inputs []string
// IsValidInput checks if an input in an array matches.
func (inputs *Inputs) IsValidInput(input string) bool {
for _, val := range *inputs {
if val == input {
return true
}
}
return false
}
// Abstraction because yes.
// GetValidInputs gets a list of valid inputs.
// func (inputs *Inputs) GetValidInputs() []string { return *inputs }
// InputChecker is an interface that represents inputs of all types.
// type InputChecker interface {
// IsValidInput(input string) bool
// GetValidInputs() []string
// }