Address code review comments

Add some documentation.
Create new util.InitFlags() function to merge and parse in one step.
pull/6/head
Joe Beda 2015-01-14 14:59:55 -08:00
parent 1d0b6ee5f5
commit 6bd6b905f5
10 changed files with 36 additions and 17 deletions

View File

@ -700,8 +700,7 @@ func TestPodHasServiceEnvVars(c *client.Client) bool {
}
func main() {
util.AddAllFlagsToPFlags()
flag.Parse()
util.InitFlags()
goruntime.GOMAXPROCS(goruntime.NumCPU())
util.ReallyCrash = true
util.InitLogs()

View File

@ -53,7 +53,6 @@ import (
"github.com/coreos/go-etcd/etcd"
"github.com/golang/glog"
flag "github.com/spf13/pflag"
)
var (
@ -563,8 +562,7 @@ func runServiceTest(client *client.Client) {
type testFunc func(*client.Client)
func main() {
util.AddAllFlagsToPFlags()
flag.Parse()
util.InitFlags()
runtime.GOMAXPROCS(runtime.NumCPU())
util.ReallyCrash = true
util.InitLogs()

View File

@ -124,8 +124,7 @@ func newEtcd(etcdConfigFile string, etcdServerList util.StringList) (helper tool
}
func main() {
util.AddAllFlagsToPFlags()
flag.Parse()
util.InitFlags()
util.InitLogs()
defer util.FlushLogs()

View File

@ -75,8 +75,7 @@ func verifyMinionFlags() {
}
func main() {
util.AddAllFlagsToPFlags()
flag.Parse()
util.InitFlags()
util.InitLogs()
defer util.FlushLogs()

View File

@ -53,8 +53,7 @@ func init() {
}
func main() {
util.AddAllFlagsToPFlags()
flag.Parse()
util.InitFlags()
util.InitLogs()
defer util.FlushLogs()

View File

@ -90,8 +90,7 @@ func setupRunOnce() {
}
func main() {
util.AddAllFlagsToPFlags()
flag.Parse()
util.InitFlags()
util.InitLogs()
defer util.FlushLogs()
rand.Seed(time.Now().UTC().UnixNano())

View File

@ -66,8 +66,7 @@ func newApiClient(addr string, port int) *client.Client {
}
func main() {
util.AddAllFlagsToPFlags()
flag.Parse()
util.InitFlags()
util.InitLogs()
defer util.FlushLogs()

27
pkg/util/flags.go Normal file
View File

@ -0,0 +1,27 @@
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
flag "github.com/spf13/pflag"
)
// InitFlags normalizes and parses the command line flags
func InitFlags() {
AddAllFlagsToPFlags()
flag.Parse()
}

View File

@ -66,6 +66,7 @@ func (v *versionValue) String() string {
return fmt.Sprintf("%v", bool(*v == VersionTrue))
}
// The type of the flag as requred by the pflag.Value interface
func (v *versionValue) Type() string {
return "version"
}

View File

@ -48,8 +48,7 @@ func init() {
}
func main() {
util.AddAllFlagsToPFlags()
flag.Parse()
util.InitFlags()
util.InitLogs()
defer util.FlushLogs()