2021-01-24 18:12:33 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
2021-02-08 22:17:19 -04:00
|
|
|
"risk/api"
|
|
|
|
"risk/cli"
|
|
|
|
"risk/tools"
|
|
|
|
"risk/utils"
|
2021-01-29 16:28:21 -04:00
|
|
|
"strings"
|
2021-01-24 18:12:33 -04:00
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
)
|
|
|
|
|
2021-01-29 16:28:21 -04:00
|
|
|
var version string = "0.0.1"
|
|
|
|
|
2021-02-08 22:17:19 -04:00
|
|
|
// Init starts the CLI frontend for risk
|
2021-01-24 18:12:33 -04:00
|
|
|
func main() {
|
2021-01-29 16:42:45 -04:00
|
|
|
logFile, err := os.OpenFile(utils.SystemInfo.ProgDir+"/r2mod-go.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
|
2021-01-24 18:12:33 -04:00
|
|
|
utils.CheckErr(err)
|
|
|
|
|
|
|
|
defer logFile.Close()
|
|
|
|
log.SetOutput(logFile)
|
|
|
|
|
|
|
|
// Setup CLI switch
|
|
|
|
|
|
|
|
var operation string
|
|
|
|
if len(os.Args) >= 2 {
|
|
|
|
operation = os.Args[1]
|
|
|
|
} else {
|
|
|
|
operation = "help"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Color
|
|
|
|
white := color.New(color.FgWhite).SprintFunc()
|
|
|
|
|
|
|
|
// CLI Operations
|
|
|
|
|
|
|
|
switch operation {
|
|
|
|
case "help":
|
2021-01-29 16:28:21 -04:00
|
|
|
fmt.Println("> Commands:")
|
|
|
|
fmt.Println(" > info -- get info about a mod")
|
|
|
|
fmt.Println(" > install, ins, i -- install mod(s)")
|
|
|
|
fmt.Println(" > remove, rm, r -- remove mod(s)")
|
|
|
|
fmt.Println(" > list, ls, li -- list mods")
|
|
|
|
fmt.Println(" > search, s, find -- search mods")
|
|
|
|
fmt.Println(" > update, upgrade, up -- update mods and API cache")
|
|
|
|
fmt.Println(" > toggle, tm, togglemods -- toggle mods")
|
|
|
|
fmt.Println(" > pull -- forcefully update API cache, not mods")
|
|
|
|
fmt.Println(" > filter -- remove version numbers using regex from stdin")
|
|
|
|
fmt.Println(" > version, ver, v -- print information about the program")
|
2021-01-24 18:12:33 -04:00
|
|
|
case "info":
|
2021-01-29 16:28:21 -04:00
|
|
|
api.InitAPI()
|
2021-01-27 19:41:55 -04:00
|
|
|
if len(os.Args) <= 2 {
|
2021-02-08 22:17:19 -04:00
|
|
|
fmt.Println("Usage: risk info <dependency string>")
|
2021-01-27 19:41:55 -04:00
|
|
|
} else {
|
2021-01-30 16:02:49 -04:00
|
|
|
status, selectedmod := api.GetModData(os.Args[2])
|
|
|
|
if status != 0 {
|
|
|
|
fmt.Println("> Could not find the mod specified.")
|
|
|
|
}
|
2021-01-27 19:41:55 -04:00
|
|
|
color.Cyan("Mod Info: %s", os.Args[2])
|
|
|
|
fmt.Println(" Name: " + selectedmod.Versions[0].FullName)
|
|
|
|
fmt.Println(" Desc: " + selectedmod.Versions[0].Description)
|
|
|
|
fmt.Println(" Version: " + selectedmod.Versions[0].VersionNumber)
|
|
|
|
fmt.Println(" Download URL: " + selectedmod.Versions[0].DownloadURL)
|
|
|
|
}
|
2021-01-24 18:12:33 -04:00
|
|
|
case "install", "ins", "i":
|
|
|
|
api.CheckAPICache()
|
2021-01-29 16:28:21 -04:00
|
|
|
api.InitAPI()
|
|
|
|
fmt.Println("> Downloading mods...")
|
2021-01-31 12:47:05 -04:00
|
|
|
|
2021-01-24 18:12:33 -04:00
|
|
|
for _, m := range os.Args[2:] {
|
2021-01-31 12:47:05 -04:00
|
|
|
cli.InstallMod(m)
|
2021-01-24 18:12:33 -04:00
|
|
|
}
|
2021-01-31 12:47:05 -04:00
|
|
|
|
2021-01-29 16:28:21 -04:00
|
|
|
color.Green("> Complete!")
|
|
|
|
case "remove", "rm", "r":
|
2021-01-31 12:47:05 -04:00
|
|
|
api.InitAPI()
|
2021-01-31 07:33:31 -04:00
|
|
|
fmt.Println("> Removing mods...")
|
2021-01-24 18:12:33 -04:00
|
|
|
for _, m := range os.Args[2:] {
|
2021-01-29 17:06:40 -04:00
|
|
|
cli.RemoveMod(m)
|
2021-01-24 18:12:33 -04:00
|
|
|
}
|
2021-01-31 07:33:31 -04:00
|
|
|
color.Green("> Complete!")
|
2021-01-24 18:12:33 -04:00
|
|
|
case "list", "ls", "li":
|
|
|
|
files, err := ioutil.ReadDir(utils.SystemInfo.PluginDir)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, f := range files {
|
|
|
|
color.Blue("%3v %s", i, white(f.Name()))
|
|
|
|
}
|
|
|
|
case "update", "upgrade", "up":
|
2021-01-29 13:56:49 -04:00
|
|
|
color.Cyan("> Checking API Cache")
|
2021-01-29 16:28:21 -04:00
|
|
|
api.InitAPI()
|
2021-01-29 13:56:49 -04:00
|
|
|
if api.CheckAPICache() == 0 {
|
|
|
|
color.Green("> API Cache is up to date!")
|
|
|
|
} else {
|
|
|
|
color.Red("> API Cache out of date!")
|
|
|
|
api.UpdateAPICache()
|
|
|
|
}
|
|
|
|
|
2021-01-24 18:12:33 -04:00
|
|
|
files, err := ioutil.ReadDir(utils.SystemInfo.PluginDir)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range files {
|
2021-01-29 17:06:40 -04:00
|
|
|
cli.InstallMod(f.Name())
|
2021-01-24 18:12:33 -04:00
|
|
|
}
|
|
|
|
|
2021-01-29 16:28:21 -04:00
|
|
|
color.Green("> Complete!")
|
2021-01-29 13:56:49 -04:00
|
|
|
case "pull":
|
2021-01-29 16:28:21 -04:00
|
|
|
api.InitAPI()
|
2021-01-30 16:02:49 -04:00
|
|
|
color.Cyan("> Checking API Cache")
|
|
|
|
if api.CheckAPICache() == 0 {
|
|
|
|
color.Green("> API Cache is up to date!")
|
|
|
|
} else {
|
|
|
|
color.Red("> API Cache out of date!")
|
|
|
|
api.UpdateAPICache()
|
|
|
|
}
|
2021-01-31 07:33:31 -04:00
|
|
|
color.Green("> Complete!")
|
2021-01-24 18:12:33 -04:00
|
|
|
case "toggle", "tm", "togglemods":
|
2021-01-29 13:56:49 -04:00
|
|
|
if tools.ToggleMods() {
|
|
|
|
color.Cyan("> Mods Enabled")
|
|
|
|
} else {
|
2021-01-30 15:08:08 -04:00
|
|
|
color.Cyan("> Mods Disabled")
|
2021-01-29 13:56:49 -04:00
|
|
|
}
|
2021-01-24 18:12:33 -04:00
|
|
|
case "filter":
|
|
|
|
fmt.Println(tools.ExposeModString(os.Args[2]))
|
2021-01-29 16:28:21 -04:00
|
|
|
case "version", "ver", "v":
|
2021-02-08 22:17:19 -04:00
|
|
|
color.Magenta("> risk", version)
|
2021-01-30 16:02:49 -04:00
|
|
|
fmt.Println(" > github.com/endigma442")
|
2021-01-29 16:28:21 -04:00
|
|
|
case "search", "s", "find":
|
|
|
|
api.InitAPI()
|
|
|
|
|
|
|
|
query := strings.Join(os.Args[2:], "-")
|
|
|
|
|
|
|
|
blue := color.New(color.FgBlue).SprintFunc()
|
|
|
|
|
2021-01-31 07:33:31 -04:00
|
|
|
fmt.Printf("%s %s\n", "> Querying API for mods matching:", blue(query))
|
2021-01-29 16:28:21 -04:00
|
|
|
|
|
|
|
for _, mod := range api.SearchMods(query) {
|
|
|
|
fmt.Println(" -", mod.Target)
|
|
|
|
}
|
2021-01-31 07:33:31 -04:00
|
|
|
color.Green("> Complete!")
|
2021-01-24 18:12:33 -04:00
|
|
|
default:
|
2021-02-08 22:17:19 -04:00
|
|
|
fmt.Println("Unknown command, use 'risk help' for a list of commands.")
|
2021-01-24 18:12:33 -04:00
|
|
|
}
|
|
|
|
}
|