diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/main.go b/main.go index 624af0f2c87c..7d0b33aa772e 100644 --- a/main.go +++ b/main.go @@ -38,8 +38,9 @@ var ( excludes = app.Flag("exclude", "Resource sets to exclude explicitly").Short('e').Strings() // Commands - template = app.Command("template", "Template resource sets and print them") - templateFile = template.Arg("file", "Cluster configuration file to use").Required().String() + template = app.Command("template", "Template resource sets and print them") + templateFile = template.Arg("file", "Cluster configuration file to use").Required().String() + templateOutputDir = template.Flag("output", "Output directory in which to save templated files instead of printing them").Short('o').String() apply = app.Command("apply", "Template resources and pass to 'kubectl apply'") applyFile = apply.Arg("file", "Cluster configuration file to use").Required().String() @@ -100,7 +101,13 @@ func templateCommand() { for _, r := range rs.Resources { fmt.Fprintf(os.Stderr, "Rendered file %s/%s:\n", rs.Name, r.Filename) - fmt.Println(r.Rendered) + if *templateOutputDir != "" { + os.MkdirAll(*templateOutputDir, 0777) + f, _ := os.Create(*templateOutputDir + "/" + r.Filename) + fmt.Fprintf(f, r.Rendered) + } else { + fmt.Println(r.Rendered) + } } } } |