etcd: override flag usage func

No need to communicate deprecated flags, so prevent them from getting
printed in the usage info.
This commit is contained in:
Brian Waldon 2014-09-24 12:05:57 -07:00
parent 784d7ac680
commit bcedef83d3

19
main.go
View File

@ -91,6 +91,7 @@ func init() {
}
func main() {
flag.CommandLine.Usage = usageWithIgnoredFlagsFunc(flag.CommandLine, deprecated)
flag.Parse()
setFlagsFromEnv()
@ -366,3 +367,21 @@ func (df *deprecatedFlag) Set(s string) error {
func (df *deprecatedFlag) String() string {
return ""
}
func usageWithIgnoredFlagsFunc(fs *flag.FlagSet, ignore []string) func() {
iMap := make(map[string]struct{}, len(ignore))
for _, name := range ignore {
iMap[name] = struct{}{}
}
return func() {
fs.VisitAll(func(f *flag.Flag) {
if _, ok := iMap[f.Name]; ok {
return
}
format := " -%s=%s: %s\n"
fmt.Fprintf(os.Stderr, format, f.Name, f.DefValue, f.Usage)
})
}
}