Browse Source

pkg: move DeprecatedFlag to new package

Brian Waldon 11 years ago
parent
commit
314c13a8f0
3 changed files with 48 additions and 39 deletions
  1. 3 38
      main.go
  2. 44 0
      pkg/flag.go
  3. 1 1
      test

+ 3 - 38
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 - 0
pkg/flag.go

@@ -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)
+		})
+	}
+}

+ 1 - 1
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