@@ -3,13 +3,15 @@ package main
33import (
44 "fmt"
55 "os"
6+ "path/filepath"
67 "strings"
78
89 hssm "github.com/codacy/helm-ssm/internal"
910 "github.com/spf13/cobra"
1011)
1112
1213var valueFiles valueFilesList
14+ var targetDir string
1315var verbose bool
1416var dryRun bool
1517
@@ -41,8 +43,10 @@ func main() {
4143 f .VarP (& valueFiles , "values" , "f" , "specify values in a YAML file (can specify multiple)" )
4244 f .BoolVarP (& verbose , "verbose" , "v" , false , "show the computed YAML values file/s" )
4345 f .BoolVarP (& dryRun , "dry-run" , "d" , false , "doesn't replace the file content" )
46+ f .StringVarP (& targetDir , "target-dir" , "o" , "" , "dir to output content" )
4447
4548 cmd .MarkFlagRequired ("values" )
49+
4650 if err := cmd .Execute (); err != nil {
4751 fmt .Println (err )
4852 os .Exit (1 )
@@ -52,9 +56,21 @@ func main() {
5256func run (cmd * cobra.Command , args []string ) error {
5357 funcMap := hssm .GetFuncMap ()
5458 for _ , filePath := range valueFiles {
55- if err := hssm .ExecuteTemplate (filePath , funcMap , verbose , dryRun ); err != nil {
59+ content , err := hssm .ExecuteTemplate (filePath , funcMap , verbose )
60+ if err != nil {
5661 return err
5762 }
63+ if ! dryRun {
64+ write (filePath , targetDir , content )
65+ }
5866 }
5967 return nil
6068}
69+
70+ func write (filePath string , targetDir string , content string ) error {
71+ if targetDir != "" {
72+ fileName := filepath .Base (filePath )
73+ return hssm .WriteFileD (fileName , targetDir , content )
74+ }
75+ return hssm .WriteFile (filePath , content )
76+ }
0 commit comments