MCPcopy
hub / github.com/spicetify/cli / Update

Function Update

src/cmd/update.go:15–107  ·  view source on GitHub ↗
(currentVersion string)

Source from the content-addressed store, hash-verified

13)
14
15func Update(currentVersion string) bool {
16 tagName, err := utils.FetchLatestTag()
17 if err != nil {
18 utils.PrintError("Cannot fetch latest release info")
19 utils.PrintError(err.Error())
20 return false
21 }
22 if currentVersion == tagName {
23 utils.PrintSuccess("Spicetify is up-to-date.")
24 return false
25 }
26
27 utils.PrintInfo("Latest release: " + tagName)
28 var assetURL string = "https://github.com/spicetify/cli/releases/download/v" + tagName + "/spicetify-" + tagName + "-" + runtime.GOOS + "-"
29 var location string = os.TempDir() + "/spicetify-" + tagName
30
31 if runtime.GOARCH == "386" && runtime.GOOS == "windows" {
32 assetURL += "x32"
33 } else if runtime.GOARCH == "arm64" {
34 assetURL += "arm64"
35 } else if runtime.GOOS == "windows" {
36 assetURL += "x64"
37 } else {
38 assetURL += "amd64"
39 }
40
41 if runtime.GOOS == "windows" {
42 assetURL += ".zip"
43 location += ".zip"
44 } else {
45 assetURL += ".tar.gz"
46 location += ".tar.gz"
47 }
48
49 spinner, _ := utils.Spinner.Start("Downloading Spicetify")
50
51 out, err := os.Create(location)
52 if err != nil {
53 spinner.Fail("Failed to download Spicetify")
54 utils.Fatal(err)
55 }
56 defer out.Close()
57
58 resp2, err := http.Get(assetURL)
59 if err != nil {
60 spinner.Fail("Failed to download Spicetify")
61 utils.Fatal(err)
62 }
63 defer resp2.Body.Close()
64
65 if resp2.StatusCode != http.StatusOK {
66 spinner.Fail("Failed to download Spicetify")
67 utils.Fatal(fmt.Errorf("unexpected HTTP status: %s for %s", resp2.Status, assetURL))
68 }
69
70 _, err = io.Copy(out, resp2.Body)
71 if err != nil {
72 spinner.Fail("Failed to download Spicetify")

Callers 1

mainFunction · 0.92

Calls 9

FetchLatestTagFunction · 0.92
PrintErrorFunction · 0.92
PrintSuccessFunction · 0.92
PrintInfoFunction · 0.92
FatalFunction · 0.92
CheckExistAndDeleteFunction · 0.92
UnzipFunction · 0.92
GetExecutableDirFunction · 0.92
permissionErrorFunction · 0.85

Tested by

no test coverage detected