Use --all (or -a) flag instead of * for updating all mods

This commit is contained in:
comp500 2020-05-11 17:38:36 +01:00
parent 4000d0a1a0
commit 68486ca703

View File

@ -3,6 +3,7 @@ package cmd
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/spf13/viper"
"os" "os"
"strings" "strings"
@ -12,10 +13,10 @@ import (
// updateCmd represents the update command // updateCmd represents the update command
var updateCmd = &cobra.Command{ var updateCmd = &cobra.Command{
Use: "update", Use: "update [mod]",
Short: "Update a mod (or all mods) in the modpack", Short: "Update a mod (or all mods) in the modpack",
Aliases: []string{"upgrade"}, Aliases: []string{"upgrade"},
Args: cobra.ExactArgs(1), Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// TODO: --check flag? // TODO: --check flag?
// TODO: specify multiple mods to update at once? // TODO: specify multiple mods to update at once?
@ -37,11 +38,8 @@ var updateCmd = &cobra.Command{
os.Exit(1) os.Exit(1)
} }
multiple := false
var singleUpdatedName string var singleUpdatedName string
if len(args[0]) == 0 || args[0] == "*" { if viper.GetBool("update.all") {
multiple = true
updaterMap := make(map[string][]core.Mod) updaterMap := make(map[string][]core.Mod)
fmt.Println("Reading mod files...") fmt.Println("Reading mod files...")
for _, v := range index.GetAllMods() { for _, v := range index.GetAllMods() {
@ -138,6 +136,10 @@ var updateCmd = &cobra.Command{
} }
} }
} else { } else {
if len(args) < 1 || len(args[0]) == 0 {
fmt.Println("Must specify a valid mod, or use the --all flag!")
os.Exit(1)
}
modPath, ok := index.FindMod(args[0]) modPath, ok := index.FindMod(args[0])
if !ok { if !ok {
fmt.Println("You don't have this mod installed.") fmt.Println("You don't have this mod installed.")
@ -215,7 +217,7 @@ var updateCmd = &cobra.Command{
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
if multiple { if viper.GetBool("update.all") {
fmt.Println("Mods updated!") fmt.Println("Mods updated!")
} else { } else {
fmt.Printf("\"%s\" updated!\n", singleUpdatedName) fmt.Printf("\"%s\" updated!\n", singleUpdatedName)
@ -225,4 +227,7 @@ var updateCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(updateCmd) rootCmd.AddCommand(updateCmd)
updateCmd.Flags().BoolP("all", "a", false, "Update all mods")
_ = viper.BindPFlag("update.all", updateCmd.Flags().Lookup("all"))
} }