Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit dbb9c2f

Browse files
author
Saul
committed
feat: add js for generate cmd
1 parent 913b057 commit dbb9c2f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cmd/generate.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"io/ioutil"
2020
"os"
2121
"path"
22+
"strings"
2223

2324
"gopkg.in/yaml.v3"
2425

@@ -30,7 +31,7 @@ import (
3031
)
3132

3233
var (
33-
input, output, outputType, configFile string
34+
input, output, outputType, outputFileType, configFile string
3435
)
3536

3637
// GenerateCmd represents the base command when called without any subcommands
@@ -64,7 +65,14 @@ var GenerateCmd = &cobra.Command{
6465
return err
6566
}
6667

67-
file := hierarchy.GeneratePropertiesFile(resources)
68+
var file string
69+
if strings.ToLower(outputFileType) == "" || strings.ToLower(outputFileType) == "env" {
70+
file = hierarchy.GeneratePropertiesFile(resources)
71+
}
72+
if strings.ToLower(outputFileType) == "js" || strings.ToLower(outputFileType) == "javascript" {
73+
file = hierarchy.GenerateJsPropertiesFile(resources)
74+
}
75+
6876
if outputType == "stdout" {
6977
fmt.Println(file)
7078
} else {
@@ -89,6 +97,8 @@ var GenerateCmd = &cobra.Command{
8997
func init() {
9098
GenerateCmd.Flags().StringVarP(&input, "input", "i", "-", "input of yaml dump (default '-' is stdin)")
9199
GenerateCmd.Flags().StringVarP(&configFile, "config", "c", "config.yml", "path to config file containing hierarchy")
92-
GenerateCmd.Flags().StringVarP(&outputType, "output-type", "", "stdout", "type of output: can be one of stdout, properties")
100+
GenerateCmd.Flags().StringVarP(&outputType, "output-type", "", "stdout", "type of output: can be one of 'stdout', 'file'")
101+
GenerateCmd.Flags().StringVarP(&outputFileType, "output-filetype", "", "env", "when output is a file: can be one of 'env', 'js/javascript'")
93102
GenerateCmd.Flags().StringVarP(&output, "output-path", "", "properties/{{.name}}.properties", "output path")
103+
94104
}

0 commit comments

Comments
 (0)