dir2config: support json output
This commit is contained in:
@ -1,10 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
@ -127,12 +129,22 @@ func main() {
|
|||||||
|
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
|
switch ext := path.Ext(*outPath); ext {
|
||||||
|
case ".yaml":
|
||||||
out.Write([]byte("# dkl-dir2config " + Version + "\n"))
|
out.Write([]byte("# dkl-dir2config " + Version + "\n"))
|
||||||
|
|
||||||
if err = yaml.NewEncoder(out).Encode(dst); err != nil {
|
if err = yaml.NewEncoder(out).Encode(dst); err != nil {
|
||||||
log.Fatal("failed to render output: ", err)
|
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: ", ext)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cfgPath(subPath string) string { return filepath.Join(*dir, subPath) }
|
func cfgPath(subPath string) string { return filepath.Join(*dir, subPath) }
|
||||||
|
|||||||
Reference in New Issue
Block a user