mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
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:
parent
784d7ac680
commit
bcedef83d3
19
main.go
19
main.go
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user