title: How is a Cobra Flag of type `StringToStringVar` access using Viper?
body: <p>I am trying to develop an application in Go that accepts inputs on the command line as a string of key value pairs. To do this I am using <code>StrngToStringVar</code> from the Cobra library.</p>
  
  <p>I am also using Viper to bind these flags to configuration, however whatever value I put it I do not seem to be able to get it from Viper.</p>
  
  <p>This is the code</p>
  
  <pre><code>package main
  
  import (
      "fmt"
  
      "github.com/spf13/cobra"
      "github.com/spf13/viper"
  
      "github.com/davecgh/go-spew/spew"
  )
  
  func main() {
      var items map[string]string
      var name string
  
      rootCmd := &amp;cobra.Command{
          Use:   "cobra",
          Short: "Test options on the command line",
          Long:  ``,
          Run: func(ccmd *cobra.Command, args []string) {
  
              spew.Dump(viper.GetString("name"))
              spew.Println("")
  
              fmt.Println("GetStringMap")
              spew.Dump(viper.GetStringMap("items"))
  
              fmt.Println("")
  
              fmt.Println("GetStringMapString")
              spew.Dump(viper.GetStringMapString("items"))
          },
      }
  
      rootCmd.Flags().StringVar(&amp;name, "name", "", "Name of the list")
      rootCmd.Flags().StringToStringVar(&amp;items, "item", nil, "Map stating the items to be included")
  
      viper.BindPFlag("name", rootCmd.Flags().Lookup("name"))
      viper.BindPFlag("items", rootCmd.Flags().Lookup("item"))
  
      rootCmd.Execute()
  }
  </code></pre>
  
  <p>If I run this with the command <code>go run .\main.go --item shopping=apple,banana --name foobar</code> I get the following result</p>
  
  <pre><code>(string) (len=6) "foobar"
  
  GetStringMap
  (map[string]interface {}) {
  }
  
  GetStringMapString
  (map[string]string) {
  }
  </code></pre>
  
  <p>As can be seent he output contains nothing for the items even though I set the input (I believe) correctly. I have been trying to use PR <a href="https://github.com/spf13/pflag/pull/133" rel="nofollow noreferrer">https://github.com/spf13/pflag/pull/133</a> to work out how to do it but I am not having any luck.</p>
  
  <p>I am wondering if the binding is incorrect, but I have used CObra successfully in other projects so it is my lack of understanding as to how to reference the generated <code>map[string]string</code> from Cobra.</p>