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
/
load.go
54 lines (40 loc) · 1.53 KB
/
load.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
package main
import (
"encoding/json"
"strings"
)
// Loads a package.
func loadPkg(packageFile string, pkgName string) Package {
log(1, "Loading package info for %s...", bolden(pkgName))
var pkg Package
environmentVariables := map[string]string{
"PREFIX": config.Paths.Prefix,
"BIN": config.Paths.Prefix + "bin/",
"HOME": home,
"INDIEPKG_PATH": mainPath,
"BOLD": textFx.Bold,
"RESET": RESETCOL,
}
debugLog("Finding environment variables...")
keySlice := make([]string, 0)
for key := range environmentVariables { // Iterate through environment variables & add them to keySlice
keySlice = append(keySlice, key)
}
debugLog("Replacing environment variables...")
for _, key := range keySlice { // Iterate through keySlice & replace them in the package file with their proper values
environmentVariables["PREFIX"] = config.Paths.Prefix
debugLog("Replacing %s with %s...", key, environmentVariables[key])
packageFile = strings.ReplaceAll(packageFile, ":("+key+"):", environmentVariables[key])
}
err := json.Unmarshal([]byte(packageFile), &pkg)
errorLog(err, "An error occurred while loading package info for %s", pkgName)
return pkg
}
// Reads a package file from the standard location and loads it.
func readLoad(pkgName string) Package {
pkgDispName := bolden(pkgName)
log(1, "Reading package info for %s...", pkgDispName)
pkgFile := readFile(infoPath+pkgName+".json", "An error occurred while reading package %s", pkgDispName)
pkg := loadPkg(pkgFile, pkgName)
return pkg
}