Dependency installation, further cli removal from main package

This commit is contained in:
endigma 2021-01-29 17:06:40 -04:00
parent 0866620ab0
commit 523b15e289
3 changed files with 61 additions and 40 deletions

50
cli/cli.go Normal file
View File

@ -0,0 +1,50 @@
package cli
import (
"fmt"
"r2go/api"
"r2go/tools"
"github.com/fatih/color"
)
// InstallMod is a CLI frontend for tools.DownloadMod.
func InstallMod(pkg string) {
buffer := fmt.Sprint(" > ", tools.ExposeModString(pkg), "... ")
stat, ov := tools.DownloadMod(tools.ExposeModString(pkg))
green := color.New(color.FgGreen).SprintFunc()
magenta := color.New(color.FgMagenta).SprintFunc()
blue := color.New(color.FgBlue).SprintFunc()
if stat == 1 {
buffer += green("up to date!")
} else if stat == 2 {
buffer += fmt.Sprintf("%s %s", magenta("updating to version"), ov)
} else {
buffer += blue("downloaded")
}
mod := api.GetModData(tools.ExposeModString(pkg))
for _, dep := range mod.Versions[0].Dependencies {
InstallMod(tools.ExposeModString(dep))
}
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()
buffer := fmt.Sprint(" > ", tools.ExposeModString(pkg), "... ")
if tools.RemoveMod(tools.ExposeModString(pkg)) == 1 {
buffer += red("not installed")
} else {
buffer += blue("uninstalled")
}
fmt.Println(buffer)
}

42
main.go
View File

@ -6,6 +6,7 @@ import (
"log"
"os"
"r2go/api"
"r2go/cli"
"r2go/tools"
"r2go/utils"
"strings"
@ -15,40 +16,7 @@ import (
var version string = "0.0.1"
func downloadMod(pkg string) {
buffer := fmt.Sprint(" > ", tools.ExposeModString(pkg), "... ")
stat, ov := tools.DownloadMod(tools.ExposeModString(pkg))
green := color.New(color.FgGreen).SprintFunc()
magenta := color.New(color.FgMagenta).SprintFunc()
blue := color.New(color.FgBlue).SprintFunc()
if stat == 1 {
buffer += green("up to date!")
} else if stat == 2 {
buffer += fmt.Sprintf("%s %s", magenta("updating to version"), ov)
} else {
buffer += blue("downloaded")
}
fmt.Println(buffer)
}
func removeMod(pkg string) {
blue := color.New(color.FgBlue).SprintFunc()
red := color.New(color.FgRed).SprintFunc()
buffer := fmt.Sprint(" > ", tools.ExposeModString(pkg), "... ")
if tools.RemoveMod(tools.ExposeModString(pkg)) == 1 {
buffer += red("not installed")
} else {
buffer += blue("uninstalled")
}
fmt.Println(buffer)
}
// Init starts the CLI frontend for r2go
func main() {
logFile, err := os.OpenFile(utils.SystemInfo.ProgDir+"/r2mod-go.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
@ -101,12 +69,12 @@ func main() {
api.InitAPI()
fmt.Println("> Downloading mods...")
for _, m := range os.Args[2:] {
downloadMod(m)
cli.InstallMod(m)
}
color.Green("> Complete!")
case "remove", "rm", "r":
for _, m := range os.Args[2:] {
removeMod(m)
cli.RemoveMod(m)
}
case "list", "ls", "li":
files, err := ioutil.ReadDir(utils.SystemInfo.PluginDir)
@ -133,7 +101,7 @@ func main() {
}
for _, f := range files {
downloadMod(f.Name())
cli.InstallMod(f.Name())
}
color.Green("> Complete!")

View File

@ -1,6 +1,7 @@
package tools
import (
"fmt"
"io/ioutil"
"log"
"os"
@ -36,6 +37,7 @@ func DownloadMod(depString string) (int, string) {
modFolder := sysinfo.PluginDir + "/" + depString + "-" + modVersion
if utils.PathExists(modFolder) {
return 1, modver
}
@ -60,9 +62,10 @@ func DownloadMod(depString string) (int, string) {
utils.CheckErr(err)
// TODO: Dependencies!
// for i, dep := range {
// }
fmt.Println("pog")
for _, dep := range mod.Versions[0].Dependencies {
DownloadMod(dep)
}
return status, modver
}