dir2config: add version

This commit is contained in:
Mikaël Cluseau 2023-11-25 16:21:47 +01:00
parent 40d08139db
commit 07e9dccd06
2 changed files with 6 additions and 0 deletions

View File

@ -16,6 +16,8 @@ import (
"novit.tech/direktil/local-server/pkg/clustersconfig" "novit.tech/direktil/local-server/pkg/clustersconfig"
) )
var Version = "dev"
var ( var (
Debug = false Debug = false
@ -124,6 +126,8 @@ func main() {
defer out.Close() defer out.Close()
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)
} }

View File

@ -185,6 +185,8 @@ func (ctx *renderContext) renderConfigTo(buf io.Writer, configTemplate *clusters
return hex.EncodeToString(ba[:]) return hex.EncodeToString(ba[:])
} }
extraFuncs["version"] = func() string { return Version }
if err := configTemplate.Execute(ctxName, "config", buf, ctxMap, extraFuncs); err != nil { if err := configTemplate.Execute(ctxName, "config", buf, ctxMap, extraFuncs); err != nil {
log.Fatalf("failed to render config %q for host %q: %v", ctx.Host.Config, ctx.Host.Name, err) log.Fatalf("failed to render config %q for host %q: %v", ctx.Host.Config, ctx.Host.Name, err)
} }