/
update.go
80 lines (75 loc) · 1.86 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
package main
import (
"github.com/urfave/cli"
"github.com/wttw/wowaddon/output"
)
func update(c *cli.Context) error {
addons := []string{}
if len(c.Args()) == 0 {
for name, addon := range config.Addons {
if !addon.Locked {
addons = append(addons, name)
}
}
} else {
addons = c.Args()
}
updated := 0
wowV := wowVersion()
for _, name := range addons {
addon, ok := config.Addons[name]
if !ok {
output.Printf("%s: isn't installed\n", failed(name))
continue
}
if addon.Locked {
output.Printf("%s: locked, not updating\n", failed(name))
continue
}
meta, err := downloadURL(name, addon.Source)
if err != nil {
output.Printf("%s: failed to retrieve metadata: %s\n", failed(name), err.Error())
continue
}
if meta.Version == addon.Version {
if wowV != 0 && addon.Interface != 0 && addon.Interface < wowV {
output.Printf("%s: (out of date) no update from %s available\n", warn(name), addon.Version)
} else {
output.Printf("%s: up to date at version %s\n", success(name), addon.Version)
continue
}
}
err = installAddon(name, addon.Source, "updated")
if err == nil {
updated++
}
}
output.Printf("%d addons updated\n", updated)
if !config.KeepCache {
purgeCache()
}
return nil
}
func checkupdate(c *cli.Context) error {
updated := 0
for name, addon := range config.Addons {
if addon.Locked {
continue
}
meta, err := downloadURL(name, addon.Source)
if err != nil {
output.Printf("%s: failed to retrieve metadata: %s\n", failed(name), err.Error())
continue
}
if meta.Version != addon.Version {
output.Printf("%s: can be updated from %s to %s\n", success(name), addon.Version, meta.Version)
updated++
}
}
if updated > 0 {
output.Printf("%d addons can be updated\n", updated)
} else {
output.Printf("%s\n", success("You have the latest version of everything"))
}
return nil
}