Ajouter configCmd pour print config à l'écran
This commit is contained in:
parent
da42387211
commit
32e53546ed
1 changed files with 44 additions and 0 deletions
44
cmd/config.go
Normal file
44
cmd/config.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue