Skip to content

Commit

Permalink
support output flag to write to the result to file
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Sucharevich committed Aug 25, 2019
1 parent 83a3a97 commit 7c20557
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.0
0.10.0
16 changes: 14 additions & 2 deletions cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -83,7 +94,7 @@ var renderCmd = &cobra.Command{
})
res, err := engine.Render()
dieOnError(err, log)
fmt.Println(res.String())
fmt.Fprintln(writer, res.String())
},
}

Expand All @@ -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")
}
1 change: 1 addition & 0 deletions examples/output-to-file/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Run: `pikolo render --template examples/with-namespace/template --value Context=examples/with-namespace/values.yaml`
2 changes: 2 additions & 0 deletions examples/output-to-file/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
pikolo render --template examples/output-to-file/template --value Context=examples/output-to-file/values.yaml --output ./out
3 changes: 3 additions & 0 deletions examples/output-to-file/template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
steps:
step_1:
image: {{ .Context.image }}
1 change: 1 addition & 0 deletions examples/output-to-file/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
image: alpine:3.8

0 comments on commit 7c20557

Please sign in to comment.