Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmd/renderizer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"path/filepath"
"strings"

"github.com/gomatic/renderizer/v2/pkg/renderizer"
"github.com/imdario/mergo"
"github.com/kardianos/osext"
"github.com/gomatic/renderizer/v2/pkg/renderizer"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -123,6 +123,13 @@ func main() {
EnvVars: []string{"RENDERIZER_VEBOSE"},
Destination: &settings.Options.Verbose,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "writes template to output file rather than stdout",
Value: settings.Options.Output,
Destination: &settings.Options.Output,
},
}

app.Before = func(ctx *cli.Context) error {
Expand Down Expand Up @@ -241,7 +248,7 @@ func main() {
flag = parts[0]
}
switch flag[2:] {
case "settings", "missing", "environment", "env":
case "settings", "missing", "environment", "env", "output":
// If the flag requires a parameter but it is not specified with an =, grab the next argument too.
if !strings.Contains(larg, "=") {
next = true
Expand Down
16 changes: 15 additions & 1 deletion pkg/renderizer/renderizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type Options struct {
Verbose bool
//
Testing bool
//
Output string
}

//
Expand Down Expand Up @@ -215,7 +217,19 @@ func (settings *Options) Render() error {
}

data = b.Bytes()
fmt.Println(string(data))
fh := os.Stdout

if settings.Output != "" {
if fh, err = os.Create(settings.Output); err != nil {
log.Print(err)
return 8
}
}

if _, err = fh.Write(data); err != nil {
log.Print(err)
return 8
}

return 0
}()
Expand Down