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

`CountVar` doesn't support default value setting #384

Open ZhouXing19 opened 1 year ago

ZhouXing19 commented 1 year ago

When setting a count flag, the default value setting is not supported -- FlagSet.CountVarP() or FlagSet.CountVar() only takes name and usage as parameters. Weirdly, it is noted in the comment that default value is allowed.

https://github.com/spf13/pflag/blob/d5e0c0615acee7028e1e2740a11102313be88de1/count.go#L47-L58

fredbi commented 1 year ago

IMHO, the only way to preserve a backard compatibility would be to extend these methods with some ...Option parameter. One such option could support adding a default value.