diff --git a/cmd/apiserver/apiserver.go b/cmd/apiserver/apiserver.go index 7a564b219a1..32856352052 100644 --- a/cmd/apiserver/apiserver.go +++ b/cmd/apiserver/apiserver.go @@ -30,7 +30,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider" "github.com/GoogleCloudPlatform/kubernetes/pkg/master" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" - verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag" + "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" "github.com/golang/glog" ) diff --git a/cmd/controller-manager/controller-manager.go b/cmd/controller-manager/controller-manager.go index 091e7bddeb1..c1372674c4d 100644 --- a/cmd/controller-manager/controller-manager.go +++ b/cmd/controller-manager/controller-manager.go @@ -27,7 +27,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/controller" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" - verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag" + "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" "github.com/golang/glog" ) diff --git a/cmd/kubecfg/kubecfg.go b/cmd/kubecfg/kubecfg.go index ad36985ea86..f93f18e1e7c 100644 --- a/cmd/kubecfg/kubecfg.go +++ b/cmd/kubecfg/kubecfg.go @@ -34,7 +34,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/version" - verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag" + "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" "github.com/golang/glog" ) diff --git a/cmd/kubelet/kubelet.go b/cmd/kubelet/kubelet.go index 05166581f7f..21052332c8f 100644 --- a/cmd/kubelet/kubelet.go +++ b/cmd/kubelet/kubelet.go @@ -36,7 +36,7 @@ import ( kconfig "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/config" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" - verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag" + "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" "github.com/coreos/go-etcd/etcd" "github.com/fsouza/go-dockerclient" "github.com/golang/glog" diff --git a/cmd/proxy/proxy.go b/cmd/proxy/proxy.go index 982aa3f8795..adfcf3babc7 100644 --- a/cmd/proxy/proxy.go +++ b/cmd/proxy/proxy.go @@ -24,7 +24,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy" "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" - verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag" + "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" "github.com/coreos/go-etcd/etcd" "github.com/golang/glog" ) diff --git a/pkg/version/flag/flag.go b/pkg/version/flag/flag.go deleted file mode 100644 index e467a80ca5f..00000000000 --- a/pkg/version/flag/flag.go +++ /dev/null @@ -1,39 +0,0 @@ -/* -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 flag defines utility functions to handle command line flags related to version of Kubernetes. -package flag - -import ( - "flag" - "fmt" - "os" - - "github.com/GoogleCloudPlatform/kubernetes/pkg/version" -) - -var ( - versionFlag = flag.Bool("version", false, "Print version information and quit") -) - -// PrintAndExitIfRequested will check if the -version flag was passed -// and, if so, print the version and exit. -func PrintAndExitIfRequested() { - if *versionFlag { - fmt.Printf("Kubernetes %s\n", version.Get()) - os.Exit(0) - } -} diff --git a/pkg/version/verflag/verflag.go b/pkg/version/verflag/verflag.go new file mode 100644 index 00000000000..85c47bc5214 --- /dev/null +++ b/pkg/version/verflag/verflag.go @@ -0,0 +1,94 @@ +/* +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 verflag defines utility functions to handle command line flags +// related to version of Kubernetes. +package verflag + +import ( + "flag" + "fmt" + "os" + "strconv" + + "github.com/GoogleCloudPlatform/kubernetes/pkg/version" +) + +type versionValue int + +const ( + VersionFalse versionValue = 0 + VersionTrue versionValue = 1 + VersionRaw versionValue = 2 +) + +const strRawVersion string = "raw" + +func (v *versionValue) IsBoolFlag() bool { + return true +} + +func (v *versionValue) Get() interface{} { + return versionValue(*v) +} + +func (v *versionValue) Set(s string) error { + if s == strRawVersion { + *v = VersionRaw + return nil + } + boolVal, err := strconv.ParseBool(s) + if boolVal { + *v = VersionTrue + } else { + *v = VersionFalse + } + return err +} + +func (v *versionValue) String() string { + if *v == VersionRaw { + return strRawVersion + } + return fmt.Sprintf("%v", bool(*v == VersionTrue)) +} + +func VersionVar(p *versionValue, name string, value versionValue, usage string) { + *p = value + flag.Var(p, name, usage) +} + +func Version(name string, value versionValue, usage string) *versionValue { + p := new(versionValue) + VersionVar(p, name, value, usage) + return p +} + +var ( + versionFlag = Version("version", VersionFalse, "Print version information and quit") +) + +// PrintAndExitIfRequested will check if the -version flag was passed +// and, if so, print the version and exit. +func PrintAndExitIfRequested() { + if *versionFlag == VersionRaw { + fmt.Printf("%#v\n", version.Get()) + os.Exit(0) + } else if *versionFlag == VersionTrue { + fmt.Printf("Kubernetes %s\n", version.Get()) + os.Exit(0) + } +} diff --git a/plugin/cmd/scheduler/scheduler.go b/plugin/cmd/scheduler/scheduler.go index 6a58f2420ed..b4ea15939fe 100644 --- a/plugin/cmd/scheduler/scheduler.go +++ b/plugin/cmd/scheduler/scheduler.go @@ -21,7 +21,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" - verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag" + "github.com/GoogleCloudPlatform/kubernetes/pkg/version/verflag" "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler" "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory" "github.com/golang/glog"