pflag icon indicating copy to clipboard operation
pflag copied to clipboard

Quotes not preserved in flags of type StringToString

Open octachrome opened this issue 1 year ago • 0 comments

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)
}

octachrome avatar Oct 08 '23 09:10 octachrome