From 3464f4e59b28654112f1c8cb6bf92654cf5685eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Wed, 3 Dec 2025 09:43:41 +0100 Subject: [PATCH] dir2config: support json output --- cmd/dkl-dir2config/main.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/dkl-dir2config/main.go b/cmd/dkl-dir2config/main.go index aa9dd86..4291f37 100644 --- a/cmd/dkl-dir2config/main.go +++ b/cmd/dkl-dir2config/main.go @@ -1,10 +1,12 @@ package main import ( + "encoding/json" "flag" "io/fs" "log" "os" + "path" "path/filepath" "github.com/go-git/go-git/v5" @@ -127,12 +129,22 @@ func main() { defer out.Close() - out.Write([]byte("# dkl-dir2config " + Version + "\n")) + switch path.Ext(*outPath) { + case "yaml": + out.Write([]byte("# dkl-dir2config " + Version + "\n")) - if err = yaml.NewEncoder(out).Encode(dst); err != nil { - log.Fatal("failed to render output: ", err) + if err = yaml.NewEncoder(out).Encode(dst); err != nil { + log.Fatal("failed to render output: ", err) + } + + case "json": + if err = json.NewEncoder(out).Encode(dst); err != nil { + log.Fatal("failed to render output: ", err) + } + + default: + log.Fatal("unknown output file extension") } - } func cfgPath(subPath string) string { return filepath.Join(*dir, subPath) }