SetNormalizeFunc allows you to add a function which can translate flag names. Flags added to the FlagSet will be translated and then when anything tries to look up the flag that will also be translated. So it would be possible to create a flag named "getURL" and have it translated to "geturl". A us
(n func(f *FlagSet, name string) NormalizedName)
| 247 | // a flag named "getURL" and have it translated to "geturl". A user could then pass |
| 248 | // "--getUrl" which may also be translated to "geturl" and everything will work. |
| 249 | func (f *FlagSet) SetNormalizeFunc(n func(f *FlagSet, name string) NormalizedName) { |
| 250 | f.normalizeNameFunc = n |
| 251 | f.sortedFormal = f.sortedFormal[:0] |
| 252 | for fname, flag := range f.formal { |
| 253 | nname := f.normalizeFlagName(flag.Name) |
| 254 | if fname == nname { |
| 255 | continue |
| 256 | } |
| 257 | flag.Name = string(nname) |
| 258 | delete(f.formal, fname) |
| 259 | f.formal[nname] = flag |
| 260 | if _, set := f.actual[fname]; set { |
| 261 | delete(f.actual, fname) |
| 262 | f.actual[nname] = flag |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // GetNormalizeFunc returns the previously set NormalizeFunc of a function which |
| 268 | // does no translation, if not set previously. |