From 32e53546ed84d83c825af45a81d6fca075732849 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Tue, 4 Jul 2023 16:05:49 -0400 Subject: [PATCH] =?UTF-8?q?Ajouter=20configCmd=20pour=20print=20config=20?= =?UTF-8?q?=C3=A0=20l'=C3=A9cran?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/config.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 cmd/config.go diff --git a/cmd/config.go b/cmd/config.go new file mode 100644 index 0000000..a8d41f0 --- /dev/null +++ b/cmd/config.go @@ -0,0 +1,44 @@ +/* +Copyright © 2023 AGECEM +*/ +package cmd + +import ( + "encoding/json" + "fmt" + "log" + + "git.agecem.com/agecem/agecem-org/config" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// configCmd represents the config command +var configCmd = &cobra.Command{ + Use: "config", + Short: "Print the config to stdout in indented JSON format", + Run: func(cmd *cobra.Command, args []string) { + var cfg config.Config + + if err := viper.Unmarshal(&cfg); err != nil { + log.Fatal(err) + } + + printConfig(cfg) + }, +} + +func init() { + rootCmd.AddCommand(configCmd) +} + +func printConfig(config config.Config) error { + buf, err := json.MarshalIndent(config, "", " ") + if err != nil { + return err + } + + fmt.Println(string(buf)) + + return nil +}