commands: Cleanup the hugo config command
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 31 Jul 2019 07:59:32 +0000 (09:59 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 31 Jul 2019 10:10:05 +0000 (12:10 +0200)
Most importantly filter out some keys not relevant for the end user.

See #6144

commands/config.go

index 33a61733d396e3758b7376c9d89fe08aa3d37793..64f0cdbbf9fb854193310b752d487c99b4f7d12e 100644 (file)
@@ -15,7 +15,9 @@ package commands
 
 import (
        "reflect"
+       "regexp"
        "sort"
+       "strings"
 
        "github.com/spf13/cobra"
        jww "github.com/spf13/jwalterweatherman"
@@ -52,15 +54,21 @@ func (c *configCmd) printConfig(cmd *cobra.Command, args []string) error {
 
        allSettings := cfg.Cfg.(*viper.Viper).AllSettings()
 
-       var separator string
-       if allSettings["metadataformat"] == "toml" {
+       // We need to clean up this, but we store objects in the config that
+       // isn't really interesting to the end user, so filter these.
+       ignoreKeysRe := regexp.MustCompile("client|sorted|filecacheconfigs|allmodules|multilingual")
+
+       separator := ": "
+
+       if len(cfg.configFiles) > 0 && strings.HasSuffix(cfg.configFiles[0], ".toml") {
                separator = " = "
-       } else {
-               separator = ": "
        }
 
        var keys []string
        for k := range allSettings {
+               if ignoreKeysRe.MatchString(k) {
+                       continue
+               }
                keys = append(keys, k)
        }
        sort.Strings(keys)