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 +}