diff --git a/VERSION b/VERSION index ac39a10..78bc1ab 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.0 +0.10.0 diff --git a/cmd/render.go b/cmd/render.go index c897104..4b5950b 100644 --- a/cmd/render.go +++ b/cmd/render.go @@ -19,14 +19,25 @@ var renderCmdOptions struct { rootContext string rightDelim string leftDelim string + outputFile string } var renderCmd = &cobra.Command{ Use: "render", Run: func(cmd *cobra.Command, args []string) { + log := logger.New(nil) + var writer io.Writer + if renderCmdOptions.outputFile == "" { + writer = os.Stdout + } else { + f, err := os.Create(renderCmdOptions.outputFile) + dieOnError(err, log) + defer f.Close() + writer = f + } + templateReaders := make(map[string]io.Reader) valueReaders := make(map[string][]io.Reader) - log := logger.New(nil) if len(renderCmdOptions.templates) == 0 { dieOnError(fmt.Errorf("No tempalte given"), log) } @@ -83,7 +94,7 @@ var renderCmd = &cobra.Command{ }) res, err := engine.Render() dieOnError(err, log) - fmt.Println(res.String()) + fmt.Fprintln(writer, res.String()) }, } @@ -94,4 +105,5 @@ func init() { renderCmd.Flags().StringVar(&renderCmdOptions.rootContext, "root-namespace", "Values", "Name of the root namespace") renderCmd.Flags().StringVar(&renderCmdOptions.leftDelim, "left-delim", "{{", "Left delimiter ") renderCmd.Flags().StringVar(&renderCmdOptions.rightDelim, "right-delim", "}}", "Right delimiter") + renderCmd.Flags().StringVar(&renderCmdOptions.outputFile, "output", "", "Write the output to file instead of stdout") } diff --git a/examples/output-to-file/README.md b/examples/output-to-file/README.md new file mode 100644 index 0000000..698d267 --- /dev/null +++ b/examples/output-to-file/README.md @@ -0,0 +1 @@ +Run: `pikolo render --template examples/with-namespace/template --value Context=examples/with-namespace/values.yaml` \ No newline at end of file diff --git a/examples/output-to-file/run.sh b/examples/output-to-file/run.sh new file mode 100755 index 0000000..1220e49 --- /dev/null +++ b/examples/output-to-file/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +pikolo render --template examples/output-to-file/template --value Context=examples/output-to-file/values.yaml --output ./out \ No newline at end of file diff --git a/examples/output-to-file/template b/examples/output-to-file/template new file mode 100644 index 0000000..1df9ef2 --- /dev/null +++ b/examples/output-to-file/template @@ -0,0 +1,3 @@ +steps: + step_1: + image: {{ .Context.image }} \ No newline at end of file diff --git a/examples/output-to-file/values.yaml b/examples/output-to-file/values.yaml new file mode 100644 index 0000000..f644453 --- /dev/null +++ b/examples/output-to-file/values.yaml @@ -0,0 +1 @@ +image: alpine:3.8 \ No newline at end of file