risk/cli/cli.go

64 lines
1.6 KiB
Go
Raw Normal View History

package cli
import (
"fmt"
"r2go/api"
"r2go/tools"
"github.com/fatih/color"
)
// InstallMod is a CLI frontend for tools.DownloadMod.
2021-01-31 06:07:37 -04:00
func InstallMod(pkg string) []string {
green := color.New(color.FgGreen).SprintFunc()
magenta := color.New(color.FgMagenta).SprintFunc()
2021-01-30 16:02:49 -04:00
red := color.New(color.FgRed).SprintFunc()
blue := color.New(color.FgBlue).SprintFunc()
2021-01-30 16:14:03 -04:00
cyan := color.New(color.FgCyan).SprintFunc()
2021-01-31 06:07:37 -04:00
deps := []string{}
2021-01-30 16:14:03 -04:00
buffer := cyan(fmt.Sprint(" > ", tools.ExposeModString(pkg), "... "))
stat, ov := 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)
2021-01-30 16:02:49 -04:00
} else if stat == 3 {
buffer += fmt.Sprintf("%s", red("could not find the mod specified."))
} else {
buffer += blue("downloaded")
}
2021-01-30 16:02:49 -04:00
if stat != 3 {
_, mod := api.GetModData(tools.ExposeModString(pkg))
for _, dep := range mod.Versions[0].Dependencies {
depString := tools.ExposeModString(dep)
if depString != "tristanmcpherson-R2API" && depString != "bbepis-BepInExPack" {
2021-01-31 06:07:37 -04:00
deps = append(deps, depString)
2021-01-30 16:02:49 -04:00
}
2021-01-30 15:08:08 -04:00
}
2021-01-30 16:02:49 -04:00
}
fmt.Println(buffer)
2021-01-31 06:07:37 -04:00
return deps
}
// RemoveMod is a CLI frontend for tools.RemoveMod
func RemoveMod(pkg string) {
blue := color.New(color.FgBlue).SprintFunc()
red := color.New(color.FgRed).SprintFunc()
2021-01-30 16:14:03 -04:00
cyan := color.New(color.FgCyan).SprintFunc()
2021-01-30 16:14:03 -04:00
buffer := cyan(fmt.Sprint(" > ", tools.ExposeModString(pkg), "... "))
if tools.RemoveMod(tools.ExposeModString(pkg)) == 1 {
buffer += red("not installed")
} else {
buffer += blue("uninstalled")
}
fmt.Println(buffer)
}