mirror of
https://github.com/element-hq/ess-helm.git
synced 2026-12-06 00:32:31 -08:00
Skip render-config when output exists
This commit is contained in:
1 parent
8bef958b4b
commit
7e35be93fd
1 file changed
+39
-34
@@ -29,42 +29,47 @@ func readFiles(paths []string) ([]io.Reader, []func() error, error) {
|
||||
}
|
||||
|
||||
func Run(options *RenderConfigOptions) {
|
||||
// If output file already exists, exit 0
|
||||
if _, err := os.Stat(options.Output); err == nil {
|
||||
fmt.Printf("Output file %s already exists, exiting\n", options.Output)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
fileReaders, closeFiles, err := readFiles(options.Files)
|
||||
defer func() {
|
||||
for _, closeFn := range closeFiles {
|
||||
err := closeFn()
|
||||
if err != nil {
|
||||
fmt.Println("Error closing file : ", err)
|
||||
}
|
||||
fileReaders, closeFiles, err := readFiles(options.Files)
|
||||
defer func() {
|
||||
for _, closeFn := range closeFiles {
|
||||
err := closeFn()
|
||||
if err != nil {
|
||||
fmt.Println("Error closing file : ", err)
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
result, err := renderer.RenderConfig(fileReaders)
|
||||
if err != nil {
|
||||
if err == flag.ErrHelp {
|
||||
flag.CommandLine.Usage()
|
||||
} else {
|
||||
fmt.Println("Error:", err)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
var outputYAML []byte
|
||||
if outputYAML, err = yaml.Marshal(result); err != nil {
|
||||
fmt.Println("Error marshalling merged config to YAML:", err)
|
||||
os.Exit(1)
|
||||
}()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
result, err := renderer.RenderConfig(fileReaders)
|
||||
if err != nil {
|
||||
if err == flag.ErrHelp {
|
||||
flag.CommandLine.Usage()
|
||||
} else {
|
||||
fmt.Println("Error:", err)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
var outputYAML []byte
|
||||
if outputYAML, err = yaml.Marshal(result); err != nil {
|
||||
fmt.Println("Error marshalling merged config to YAML:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Rendering config to file: %v\n", options.Output)
|
||||
if os.Getenv("DEBUG_RENDERING") == "1" {
|
||||
fmt.Println(string(outputYAML))
|
||||
}
|
||||
err = os.WriteFile(options.Output, outputYAML, 0440)
|
||||
if err != nil {
|
||||
fmt.Println("Error writing to file:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
fmt.Printf("Rendering config to file: %v\n", options.Output)
|
||||
if os.Getenv("DEBUG_RENDERING") == "1" {
|
||||
fmt.Println(string(outputYAML))
|
||||
}
|
||||
err = os.WriteFile(options.Output, outputYAML, 0440)
|
||||
if err != nil {
|
||||
fmt.Println("Error writing to file:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user