This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
updating.go
74 lines (52 loc) · 1.95 KB
/
updating.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
package main
import (
"strings"
)
// Gets and writes a packages info to the proper location.
func rawGetInfo(pkgName string, pkg Package) {
log(1, "Getting info for %s", bolden(pkgName))
log(1, "Checking for info URL...")
if pkg.InfoURL == "" { // Check if package didn't specify info URL
log(1, "Getting info from repos...")
writePkg(pkgName, findPkg(pkgName))
} else {
log(1, "Getting info from %s...", bolden(pkg.InfoURL))
writePkg(pkgName, getPkgFromURL(pkgName, pkg.InfoURL))
}
}
func updatePackage(pkgNames []string) {
fullInit()
for _, pkgName := range pkgNames {
chapLog("=>", "", "Updating %s", pkgName)
pkgDisplayName := bolden(pkgName)
if !pkgExists(pkgName) {
log(3, "%s is not installed, so it can't be updated.", pkgDisplayName)
continue
}
rawGetInfo(pkgName, readLoad(pkgName))
chapLog("==>", textCol.Green, "Success")
log(0, "Successfully updated package info for %s.", pkgDisplayName)
}
chapLog("=>", textCol.Green, "Success")
log(0, "Successfully updated info for all selected packages.")
}
func updateAllPackages() {
fullInit()
chapLog("==>", "", "Getting installed packages")
installedPkgs := make([]string, 0)
log(1, "Getting contents of %s", bolden(infoPath))
files := dirContents(infoPath, "An error occurred while getting list of installed packages")
log(1, "Iterating through contents of %s", bolden(infoPath))
for _, file := range files {
installedPkgs = append(installedPkgs, strings.TrimSuffix(file.Name(), ".json")) // Trim .json from end of file name & append to installedPkgs
}
chapLog("=>", "", "Updating packages")
for _, pkgName := range installedPkgs { // Iterate through installed packages
chapLog("==>", "", "Updating %s", pkgName)
rawGetInfo(pkgName, readLoad(pkgName))
chapLog("===>", textCol.Green, "Success")
log(0, "Successfully updated package info for %s.", bolden(pkgName))
}
chapLog("=>", textCol.Green, "Success")
log(0, "Successfully updated info for all packages.")
}