fix(export): format overrules file extension

This commit is contained in:
Jan De Dobbeleer 2024-03-11 09:47:28 +01:00 committed by Jan De Dobbeleer
parent 87d1719bd0
commit 5b7b4afec9

View file

@ -2,6 +2,7 @@ package cli
import ( import (
"fmt" "fmt"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -42,15 +43,29 @@ Exports the ~/myconfig.omp.json config file to toml and prints the result to std
env.Init() env.Init()
defer env.Close() defer env.Close()
cfg := engine.LoadConfig(env) cfg := engine.LoadConfig(env)
if len(output) == 0 { if len(output) == 0 {
fmt.Print(cfg.Export(format)) fmt.Print(cfg.Export(format))
return return
} }
cfg.Output = cleanOutputPath(output, env) cfg.Output = cleanOutputPath(output, env)
format := strings.TrimPrefix(filepath.Ext(output), ".")
if format == "yml" { if len(format) == 0 {
format = engine.YAML format = strings.TrimPrefix(filepath.Ext(output), ".")
} }
switch format {
case "json", "jsonc":
format = engine.JSON
case "toml", "tml":
format = engine.TOML
case "yaml", "yml":
format = engine.YAML
default:
os.Exit(1)
}
cfg.Write(format) cfg.Write(format)
}, },
} }