/
update.go
120 lines (102 loc) · 3.18 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package cmd
import (
"context"
"fmt"
"path/filepath"
"time"
"github.com/briandowns/spinner"
"github.com/minepkg/minepkg/internals/downloadmgr"
"github.com/minepkg/minepkg/internals/globals"
"github.com/minepkg/minepkg/internals/instances"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(updateCmd)
rootCmd.AddCommand(updateReqCmd)
}
var updateCmd = &cobra.Command{
Use: "update",
Short: "Updates all installed dependencies",
Long: `
This updates the local mods according to the minepkg.toml.
Edit the minepkg.toml to change the version requirements.
`,
Aliases: []string{"upd"},
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
instance, err := instances.NewFromWd()
instance.MinepkgAPI = globals.ApiClient
if err != nil {
logger.Fail("Instance problem: " + err.Error())
}
fmt.Printf("Installing to %s\n", instance.Desc())
fmt.Println() // empty line
installManifest(instance)
},
}
var updateReqCmd = &cobra.Command{
Use: "update-requirements",
Short: "Updates installed requirements (minecraft & loader version)",
Long: `
This updates the installed requirements according to the minepkg.toml.
Edit the minepkg.toml to change the version requirements.
`,
Aliases: []string{"update-req"},
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
instance, err := instances.NewFromWd()
instance.MinepkgAPI = globals.ApiClient
if err != nil {
logger.Fail("Instance problem: " + err.Error())
}
fmt.Printf("Installing to %s\n\n", instance.Desc())
logger.Headline("Updating installed requirements")
instance.UpdateLockfileRequirements(context.TODO())
lock := instance.Lockfile
switch {
case lock.Fabric != nil:
fmt.Println(" Fabric loader: " + lock.Fabric.FabricLoader)
fmt.Println(" Fabric mapping: " + lock.Fabric.Mapping)
fmt.Println(" Minecraft: " + lock.Fabric.Minecraft)
case lock.Forge != nil:
fmt.Println(" Forge loader: " + lock.Forge.ForgeLoader)
fmt.Println(" Minecraft: " + lock.Forge.Minecraft)
default:
fmt.Println(" Minecraft: " + lock.Vanilla.Minecraft)
}
instance.SaveLockfile()
fmt.Println()
s := spinner.New(spinner.CharSets[9], 300*time.Millisecond) // Build our new spinner
s.Prefix = " "
s.Start()
mgr := downloadmgr.New()
mgr.OnProgress = func(p int) {
s.Suffix = fmt.Sprintf(" Downloading %v", p) + "%"
}
launchManifest, err := instance.GetLaunchManifest()
if err != nil {
logger.Fail(err.Error())
}
missingAssets, err := instance.FindMissingAssets(launchManifest)
if err != nil {
logger.Fail(err.Error())
}
missingLibs, err := instance.FindMissingLibraries(launchManifest)
if err != nil {
logger.Fail(err.Error())
}
for _, asset := range missingAssets {
target := filepath.Join(instance.GlobalDir, "assets/objects", asset.UnixPath())
mgr.Add(downloadmgr.NewHTTPItem(asset.DownloadURL(), target))
}
for _, lib := range missingLibs {
target := filepath.Join(instance.GlobalDir, "libraries", lib.Filepath())
mgr.Add(downloadmgr.NewHTTPItem(lib.DownloadURL(), target))
}
if err = mgr.Start(context.TODO()); err != nil {
logger.Fail(err.Error())
}
s.Stop()
installManifest(instance)
},
}