From 1b9ce9f6882e8098b7aa6d1528c6110c82e771c5 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Mon, 21 Aug 2023 19:14:43 +0000 Subject: [PATCH] jpictl: add `dump` command with toml output Signed-off-by: Alejandro Mery --- cmd/jpictl/config.go | 10 ++++++++++ cmd/jpictl/dump.go | 40 ++++++++++++++++++++++++++++++++++++++++ go.mod | 5 +++-- go.sum | 10 ++++++---- 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 cmd/jpictl/config.go create mode 100644 cmd/jpictl/dump.go diff --git a/cmd/jpictl/config.go b/cmd/jpictl/config.go new file mode 100644 index 0000000..805707f --- /dev/null +++ b/cmd/jpictl/config.go @@ -0,0 +1,10 @@ +package main + +// Config describes the repository +type Config struct { + Base string +} + +var cfg = &Config{ + Base: "./m", +} diff --git a/cmd/jpictl/dump.go b/cmd/jpictl/dump.go new file mode 100644 index 0000000..2823582 --- /dev/null +++ b/cmd/jpictl/dump.go @@ -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) +} diff --git a/go.mod b/go.mod index 1e69b71..210abf9 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.19 require ( darvaza.org/sidecar v0.0.0-20230721122716-b9c54b8adbaf darvaza.org/slog v0.5.2 + github.com/burntSushi/toml v0.3.1 github.com/mgechev/revive v1.3.2 github.com/spf13/cobra v1.7.0 ) @@ -20,7 +21,7 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect - github.com/mattn/go-runewidth v0.0.14 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect @@ -31,5 +32,5 @@ require ( golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.11.0 // indirect golang.org/x/text v0.12.0 // indirect - golang.org/x/tools v0.11.0 // indirect + golang.org/x/tools v0.12.0 // indirect ) diff --git a/go.sum b/go.sum index 7abdbc0..4f21ba3 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ darvaza.org/slog/handlers/zerolog v0.4.4 h1:OR1ASvH1fBCq3t85t4OU6oJPPuqMB1tsDoSp darvaza.org/slog/handlers/zerolog v0.4.4/go.mod h1:t60TeEbFcMLo74CkXC2S0rKlnwF4ixZyBR4fqIJV1GE= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/burntSushi/toml v0.3.1 h1:Hu1cOEC2qtKULZJCzym5tyA35bZr3HREuolgiAzMlhY= +github.com/burntSushi/toml v0.3.1/go.mod h1:sGTquCpRYr9McuHdv0m6YKIhx8DJGJa4t04/Y9pfSio= github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8 h1:W9o46d2kbNL06lq7UNDPV0zYLzkrde/bjIqO02eoll0= github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8/go.mod h1:gakxgyXaaPkxvLw1XQxNGK4I37ys9iBRzNUx/B7pUCo= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= @@ -32,8 +34,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= -github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517 h1:zpIH83+oKzcpryru8ceC6BxnoG8TBrhgAvRg8obzup0= github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg= github.com/mgechev/revive v1.3.2 h1:Wb8NQKBaALBJ3xrrj4zpwJwqwNA6nDpyJSEQWcCka6U= @@ -76,8 +78,8 @@ golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= -golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= +golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss= +golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=