jpictl: add dump command with toml output
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
// Config describes the repository
|
||||
type Config struct {
|
||||
Base string
|
||||
}
|
||||
|
||||
var cfg = &Config{
|
||||
Base: "./m",
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user