2021-01-29 17:06:40 -04:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"r2go/tools"
|
2021-01-31 12:47:05 -04:00
|
|
|
"r2go/utils"
|
2021-01-29 17:06:40 -04:00
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
)
|
|
|
|
|
|
|
|
// InstallMod is a CLI frontend for tools.DownloadMod.
|
2021-01-31 12:47:05 -04:00
|
|
|
func InstallMod(pkg string) {
|
2021-01-29 17:06:40 -04:00
|
|
|
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()
|
2021-01-29 17:06:40 -04:00
|
|
|
blue := color.New(color.FgBlue).SprintFunc()
|
2021-01-30 16:14:03 -04:00
|
|
|
cyan := color.New(color.FgCyan).SprintFunc()
|
|
|
|
|
|
|
|
buffer := cyan(fmt.Sprint(" > ", tools.ExposeModString(pkg), "... "))
|
2021-01-31 06:25:17 -04:00
|
|
|
stat, ov, deps := tools.DownloadMod(tools.ExposeModString(pkg))
|
2021-01-29 17:06:40 -04:00
|
|
|
|
|
|
|
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 {
|
2021-01-31 07:27:29 -04:00
|
|
|
buffer += fmt.Sprintf("%s", red("could not find the mod specified"))
|
2021-01-29 17:06:40 -04:00
|
|
|
} else {
|
|
|
|
buffer += blue("downloaded")
|
|
|
|
}
|
|
|
|
|
2021-01-31 13:21:56 -04:00
|
|
|
fmt.Println(deps)
|
2021-01-31 12:47:05 -04:00
|
|
|
dependencies := []string{}
|
|
|
|
for _, d := range deps {
|
|
|
|
dependency := tools.ExposeModString(d)
|
2021-01-31 13:21:56 -04:00
|
|
|
|
|
|
|
// Prevents duplication within this install, overall duplication would require a buffer
|
2021-01-31 12:47:05 -04:00
|
|
|
if !utils.ExistsInArray(dependencies, d) {
|
|
|
|
if dependency != "bbepis-BepInExPack" && dependency != "tristanmcpherson-R2API" {
|
2021-01-31 13:21:56 -04:00
|
|
|
dependencies = append(dependencies, dependency)
|
2021-01-31 12:47:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-29 17:06:40 -04:00
|
|
|
|
2021-01-31 12:47:05 -04:00
|
|
|
for _, d := range dependencies {
|
|
|
|
InstallMod(d)
|
|
|
|
}
|
2021-01-31 13:21:56 -04:00
|
|
|
|
|
|
|
fmt.Println(buffer)
|
2021-01-29 17:06:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-29 17:06:40 -04:00
|
|
|
|
2021-01-30 16:14:03 -04:00
|
|
|
buffer := cyan(fmt.Sprint(" > ", tools.ExposeModString(pkg), "... "))
|
2021-01-29 17:06:40 -04:00
|
|
|
|
2021-01-31 07:26:41 -04:00
|
|
|
status := tools.RemoveMod(tools.ExposeModString(pkg))
|
|
|
|
if status == 2 {
|
|
|
|
buffer += red("mod not found")
|
|
|
|
} else if status == 1 {
|
2021-01-29 17:06:40 -04:00
|
|
|
buffer += red("not installed")
|
|
|
|
} else {
|
|
|
|
buffer += blue("uninstalled")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(buffer)
|
|
|
|
}
|