71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"risk/tools"
|
|
"risk/utils"
|
|
|
|
"github.com/fatih/color"
|
|
)
|
|
|
|
// InstallMod is a CLI frontend for tools.DownloadMod.
|
|
func InstallMod(pkg string) {
|
|
green := color.New(color.FgGreen).SprintFunc()
|
|
magenta := color.New(color.FgMagenta).SprintFunc()
|
|
red := color.New(color.FgRed).SprintFunc()
|
|
blue := color.New(color.FgBlue).SprintFunc()
|
|
cyan := color.New(color.FgCyan).SprintFunc()
|
|
|
|
buffer := cyan(fmt.Sprint(" > ", tools.ExposeModString(pkg), "... "))
|
|
stat, ov, deps := tools.DownloadMod(tools.ExposeModString(pkg))
|
|
|
|
if stat == 1 {
|
|
buffer += green("up to date!")
|
|
} else if stat == 2 {
|
|
buffer += fmt.Sprintf("%s %s", magenta("updating to version"), ov)
|
|
} else if stat == 3 {
|
|
buffer += fmt.Sprintf("%s", red("could not find the mod specified"))
|
|
} else {
|
|
buffer += blue("downloaded")
|
|
}
|
|
|
|
// fmt.Println(deps)
|
|
dependencies := []string{}
|
|
for _, d := range deps {
|
|
dependency := tools.ExposeModString(d)
|
|
|
|
// Prevents duplication within this install, overall duplication would require a buffer
|
|
if !utils.ExistsInArray(dependencies, d) {
|
|
if dependency != "bbepis-BepInExPack" && dependency != "tristanmcpherson-R2API" {
|
|
dependencies = append(dependencies, dependency)
|
|
}
|
|
}
|
|
}
|
|
|
|
for _, d := range dependencies {
|
|
InstallMod(d)
|
|
}
|
|
|
|
fmt.Println(buffer)
|
|
}
|
|
|
|
// RemoveMod is a CLI frontend for tools.RemoveMod
|
|
func RemoveMod(pkg string) {
|
|
blue := color.New(color.FgBlue).SprintFunc()
|
|
red := color.New(color.FgRed).SprintFunc()
|
|
cyan := color.New(color.FgCyan).SprintFunc()
|
|
|
|
buffer := cyan(fmt.Sprint(" > ", tools.ExposeModString(pkg), "... "))
|
|
|
|
status := tools.RemoveMod(tools.ExposeModString(pkg))
|
|
if status == 2 {
|
|
buffer += red("mod not found")
|
|
} else if status == 1 {
|
|
buffer += red("not installed")
|
|
} else {
|
|
buffer += blue("uninstalled")
|
|
}
|
|
|
|
fmt.Println(buffer)
|
|
}
|