Switch to cobra/viper

This commit is contained in:
comp500
2019-09-16 21:44:40 +01:00
parent 8915e16614
commit 4fea7ceebf
17 changed files with 985 additions and 719 deletions

54
cmd/refresh.go Normal file
View File

@@ -0,0 +1,54 @@
package cmd
import (
"fmt"
"os"
"github.com/comp500/packwiz/core"
"github.com/spf13/cobra"
)
// refreshCmd represents the refresh command
var refreshCmd = &cobra.Command{
Use: "refresh",
Short: "Refresh the index file",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Loading modpack...")
pack, err := core.LoadPack()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
index, err := pack.LoadIndex()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = index.Refresh()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = index.Write()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = pack.UpdateIndexHash()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = pack.Write()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Index refreshed!")
},
}
func init() {
rootCmd.AddCommand(refreshCmd)
}