-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand.go
59 lines (49 loc) · 1.16 KB
/
command.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
package main
import (
"io"
"os"
)
func command(w io.Writer, c conf) error {
// You can't pass "--file" and "--execute" together
if c.templateFilePath != "" && c.stdinTemplateFile != "" {
return &conflictingArgsError{"file", "execute"}
}
tg := &tgen{Strict: c.strictMode}
// Read template from "-x" or "--execute" flag
if c.stdinTemplateFile != "" {
tg.setTemplate(os.Stdin.Name(), c.stdinTemplateFile)
}
// Read template file (either from "--file" or stdin)
if pathToOpen := c.templateFilePath; pathToOpen != "" {
var err error
switch pathToOpen {
case "-":
err = tg.loadTemplateFile(os.Stdin.Name(), os.Stdin)
default:
err = tg.loadTemplatePath(pathToOpen)
}
if err != nil {
return err
}
}
// Set delimiters
if c.customDelimiters != "" {
if err := tg.setDelimiters(c.customDelimiters); err != nil {
return err
}
}
// Load environment variable file
if c.environmentFile != "" {
if err := tg.loadEnvValues(c.environmentFile); err != nil {
return err
}
}
// Load yaml values file
if c.valuesFile != "" {
if err := tg.loadYAMLValues(c.valuesFile); err != nil {
return err
}
}
// Render code
return tg.render(w)
}