Skip to content

Commit 7c20557

Browse files
author
Oleg Sucharevich
committed
support output flag to write to the result to file
1 parent 83a3a97 commit 7c20557

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.0
1+
0.10.0

cmd/render.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,25 @@ var renderCmdOptions struct {
1919
rootContext string
2020
rightDelim string
2121
leftDelim string
22+
outputFile string
2223
}
2324

2425
var 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
}

examples/output-to-file/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Run: `pikolo render --template examples/with-namespace/template --value Context=examples/with-namespace/values.yaml`

examples/output-to-file/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
pikolo render --template examples/output-to-file/template --value Context=examples/output-to-file/values.yaml --output ./out

examples/output-to-file/template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
steps:
2+
step_1:
3+
image: {{ .Context.image }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
image: alpine:3.8

0 commit comments

Comments
 (0)