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" "log"
"os" "os"
"r2go/api" "r2go/api"
"r2go/cli"
"r2go/tools" "r2go/tools"
"r2go/utils" "r2go/utils"
"strings" "strings"
@ -15,40 +16,7 @@ import (
var version string = "0.0.1" var version string = "0.0.1"
func downloadMod(pkg string) { // Init starts the CLI frontend for r2go
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)
}
func main() { func main() {
logFile, err := os.OpenFile(utils.SystemInfo.ProgDir+"/r2mod-go.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) 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() api.InitAPI()
fmt.Println("> Downloading mods...") fmt.Println("> Downloading mods...")
for _, m := range os.Args[2:] { for _, m := range os.Args[2:] {
downloadMod(m) cli.InstallMod(m)
} }
color.Green("> Complete!") color.Green("> Complete!")
case "remove", "rm", "r": case "remove", "rm", "r":
for _, m := range os.Args[2:] { for _, m := range os.Args[2:] {
removeMod(m) cli.RemoveMod(m)
} }
case "list", "ls", "li": case "list", "ls", "li":
files, err := ioutil.ReadDir(utils.SystemInfo.PluginDir) files, err := ioutil.ReadDir(utils.SystemInfo.PluginDir)
@ -133,7 +101,7 @@ func main() {
} }
for _, f := range files { for _, f := range files {
downloadMod(f.Name()) cli.InstallMod(f.Name())
} }
color.Green("> Complete!") color.Green("> Complete!")

View File

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