@@ -19,14 +19,25 @@ var renderCmdOptions struct {
1919 rootContext string
2020 rightDelim string
2121 leftDelim string
22+ outputFile string
2223}
2324
2425var renderCmd = & cobra.Command {
2526 Use : "render" ,
2627 Run : func (cmd * cobra.Command , args []string ) {
28+ log := logger .New (nil )
29+ var writer io.Writer
30+ if renderCmdOptions .outputFile == "" {
31+ writer = os .Stdout
32+ } else {
33+ f , err := os .Create (renderCmdOptions .outputFile )
34+ dieOnError (err , log )
35+ defer f .Close ()
36+ writer = f
37+ }
38+
2739 templateReaders := make (map [string ]io.Reader )
2840 valueReaders := make (map [string ][]io.Reader )
29- log := logger .New (nil )
3041 if len (renderCmdOptions .templates ) == 0 {
3142 dieOnError (fmt .Errorf ("No tempalte given" ), log )
3243 }
@@ -83,7 +94,7 @@ var renderCmd = &cobra.Command{
8394 })
8495 res , err := engine .Render ()
8596 dieOnError (err , log )
86- fmt .Println ( res .String ())
97+ fmt .Fprintln ( writer , res .String ())
8798 },
8899}
89100
@@ -94,4 +105,5 @@ func init() {
94105 renderCmd .Flags ().StringVar (& renderCmdOptions .rootContext , "root-namespace" , "Values" , "Name of the root namespace" )
95106 renderCmd .Flags ().StringVar (& renderCmdOptions .leftDelim , "left-delim" , "{{" , "Left delimiter " )
96107 renderCmd .Flags ().StringVar (& renderCmdOptions .rightDelim , "right-delim" , "}}" , "Right delimiter" )
108+ renderCmd .Flags ().StringVar (& renderCmdOptions .outputFile , "output" , "" , "Write the output to file instead of stdout" )
97109}
0 commit comments