spf13 / pflag

Drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.
BSD 3-Clause "New" or "Revised" License
2.43k stars 348 forks source link

`SortFlags` not exported #382

Open plungingChode opened 1 year ago

plungingChode commented 1 year ago

The SortFlags option mentioned in the README is not actually exported. https://github.com/spf13/pflag/blob/d5e0c0615acee7028e1e2740a11102313be88de1/README.md?plain=1#L257 Instead CommandLine.SortFlags is available.

# README.md
flags.BoolP("verbose", "v", false, "verbose output")
flags.String("coolflag", "yeaah", "it's really cool flag")
flags.Int("usefulflag", 777, "sometimes it's very useful")
-flags.SortFlags = false
+flags.CommandLine.SortFlags = false
flags.PrintDefaults()
fredbi commented 1 year ago

The example code should be completed regarding how the "flags" variable is created.

The FlagSet.SortFlags field is indeed exported. CommandLine is a convenient FlagSet exposed by the package.

Documentation bug, I'd say.