-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
50 lines (39 loc) · 931 Bytes
/
config.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
package main
import (
"strings"
"text/template"
"github.com/vinyl-linux/vin/config"
)
var (
cfg config.Config
)
type InstallationValues struct {
*Manifest
config.Config
}
// Expand takes a string (containing an ostensible template) and
// expands it using Config and Manifest.
//
// What an incredibly comment that was... Okay... we allow for
// the commands section of a package manifest to be a template, and
// we grant it access to certain configuration items. This function
// is where we take that template and turn it into an actual command
// which can be used
func (c InstallationValues) Expand(s string) (cmd string, err error) {
b := &strings.Builder{}
tmpl, err := template.New("cmd").Parse(s)
if err != nil {
return
}
c.Config = cfg
err = tmpl.Execute(b, c)
if err != nil {
return
}
cmd = b.String()
return
}
func loadConfig() (err error) {
cfg, err = config.Load(configFile)
return
}