log debug viper settings and print keys if set
@@ -18,6 +18,7 @@ import (
"context"
"crypto/tls"
"crypto/x509"
+ "encoding/json"
"errors"
"fmt"
"io"
@@ -128,6 +129,7 @@ func rootCmdPersistentPreRunE(cmd *cobra.Command, args []string) error {
logger.Printf("config file:\n%s", string(b))
}
}
+ logConfigKeysValues()
return nil
}
@@ -137,6 +139,27 @@ func rootCmdPersistentPostRun(cmd *cobra.Command, args []string) {
}
}
+func logConfigKeysValues() {
+ if viper.GetBool("debug") {
+ b, err := json.MarshalIndent(viper.AllSettings(), "", " ")
+ if err != nil {
+ logger.Printf("could not marshal viper settings: %v", err)
+ } else {
+ logger.Printf("set flags/config:\n%s\n", string(b))
+ }
+ keys := viper.AllKeys()
+ sort.Strings(keys)
+
+ for _, k := range keys {
+ if !viper.IsSet(k) {
+ continue
+ }
+ v := viper.Get(k)
+ logger.Printf("%s='%v'(%T)", k, v, v)
+ }
+ }
+}
+
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gnmic",
