pflag
pflag copied to clipboard
Quotes not preserved in flags of type StringToString
When the program below is run with go run ./main.go --sts 'key="495"'
I get map[string]string{"key":"\"123"}
, where only one double quote has been trimmed from the value. I don't see anything in the documentation about quote handling, so I would expect quotes to be preserved here: map[string]string{"key":"\"123\""}
.
package main
import (
"fmt"
"os"
"github.com/spf13/pflag"
)
func main() {
fs := pflag.NewFlagSet("Example", pflag.PanicOnError)
fs.StringToString("sts", make(map[string]string), "")
_ = fs.Parse(os.Args)
sts, err := fs.GetStringToString("sts")
if err != nil {
panic(err)
}
fmt.Printf("%#v\n", sts)
}