mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
pkg: move DeprecatedFlag to new package
This commit is contained in:
parent
002ace2403
commit
314c13a8f0
41
main.go
41
main.go
@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/coreos/etcd/etcdserver"
|
||||
"github.com/coreos/etcd/etcdserver/etcdhttp"
|
||||
"github.com/coreos/etcd/pkg"
|
||||
"github.com/coreos/etcd/proxy"
|
||||
"github.com/coreos/etcd/raft"
|
||||
"github.com/coreos/etcd/snap"
|
||||
@ -86,12 +87,12 @@ func init() {
|
||||
flag.StringVar(&peerTLSInfo.KeyFile, "peer-key-file", "", "Path to the peer server TLS key file.")
|
||||
|
||||
for _, f := range deprecated {
|
||||
flag.Var(&deprecatedFlag{f}, f, "")
|
||||
flag.Var(&pkg.DeprecatedFlag{f}, f, "")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usageWithIgnoredFlagsFunc(flag.CommandLine, deprecated)
|
||||
flag.Usage = pkg.UsageWithIgnoredFlagsFunc(flag.CommandLine, deprecated)
|
||||
flag.Parse()
|
||||
|
||||
setFlagsFromEnv()
|
||||
@ -349,39 +350,3 @@ func setFlagsFromEnv() {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
type deprecatedFlag struct {
|
||||
name string
|
||||
}
|
||||
|
||||
// IsBoolFlag is defined to allow the flag to be defined without an argument
|
||||
func (df *deprecatedFlag) IsBoolFlag() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (df *deprecatedFlag) Set(s string) error {
|
||||
log.Printf("WARNING: flag \"-%s\" is no longer supported.", df.name)
|
||||
return nil
|
||||
}
|
||||
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
44
pkg/flag.go
Normal file
44
pkg/flag.go
Normal file
@ -0,0 +1,44 @@
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type DeprecatedFlag struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
// IsBoolFlag is defined to allow the flag to be defined without an argument
|
||||
func (df *DeprecatedFlag) IsBoolFlag() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (df *DeprecatedFlag) Set(s string) error {
|
||||
log.Printf("WARNING: flag \"-%s\" is no longer supported.", df.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
2
test
2
test
@ -17,7 +17,7 @@ source ./build
|
||||
# Hack: gofmt ./ will recursively check the .git directory. So use *.go for gofmt.
|
||||
TESTABLE_AND_FORMATTABLE="client etcdserver etcdserver/etcdhttp etcdserver/etcdserverpb functional proxy raft snap store wait wal transport"
|
||||
TESTABLE="$TESTABLE_AND_FORMATTABLE ./"
|
||||
FORMATTABLE="$TESTABLE_AND_FORMATTABLE *.go"
|
||||
FORMATTABLE="$TESTABLE_AND_FORMATTABLE *.go pkg"
|
||||
|
||||
# user has not provided PKG override
|
||||
if [ -z "$PKG" ]; then
|
||||
|
Loading…
x
Reference in New Issue
Block a user