jpictl: add dump command with toml output

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-21 19:14:43 +00:00
parent 1ea1ab4ac4
commit 1b9ce9f688
4 changed files with 59 additions and 6 deletions
+10
View File
@@ -0,0 +1,10 @@
package main
// Config describes the repository
type Config struct {
Base string
}
var cfg = &Config{
Base: "./m",
}
+40
View File
@@ -0,0 +1,40 @@
package main
import (
"bytes"
"os"
"github.com/burntSushi/toml"
"github.com/spf13/cobra"
"git.jpi.io/amery/jpictl/pkg/zones"
)
// Command
var dumpCmd = &cobra.Command{
Use: "dump",
Short: "generates a toml representation of the config",
RunE: func(_ *cobra.Command, _ []string) error {
var buf bytes.Buffer
m, err := zones.New(cfg.Base)
if err != nil {
return err
}
enc := toml.NewEncoder(&buf)
if err = enc.Encode(m); err != nil {
return err
}
if _, err = buf.WriteTo(os.Stdout); err != nil {
return err
}
return nil
},
}
func init() {
rootCmd.AddCommand(dumpCmd)
}