-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
48 lines (37 loc) · 1.59 KB
/
main.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
package main
import (
"os"
"github.com/spf13/cobra"
)
const appName = "tgen"
var version = "development"
func main() {
if err := run(); err != nil {
os.Exit(1)
}
}
func run() error {
var configs conf
var withValues bool
var root = &cobra.Command{
Use: appName,
Short: appName + " is a template generator with the power of Go Templates",
Version: version,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if withValues {
configs.valuesFile = "values.yaml"
}
return command(os.Stdout, configs)
},
}
root.Flags().StringVarP(&configs.environmentFile, "environment", "e", "", "an optional environment file to use (key=value formatted) to perform replacements")
root.Flags().StringVarP(&configs.templateFilePath, "file", "f", "", "the template file to process, or \"-\" to read from stdin")
root.Flags().StringVarP(&configs.customDelimiters, "delimiter", "d", "", `template delimiter (default "{{}}")`)
root.Flags().StringVarP(&configs.stdinTemplateFile, "execute", "x", "", "a raw template to execute directly, without providing --file")
root.Flags().StringVarP(&configs.valuesFile, "values", "v", "", "a file containing values to use for the template, a la Helm")
root.Flags().BoolVar(&withValues, "with-values", false, "automatically include a values.yaml file from the current working directory")
root.Flags().BoolVarP(&configs.strictMode, "strict", "s", false, "strict mode: if an environment variable or value is used in the template but not set, it fails rendering")
root.Flags().SortFlags = false
return root.Execute()
}