Add "--version" parameters to cmd

Closes-bug: #1712486

Change-Id: I824bba993fa82eb0c74b53c7b2cb7835c3e53b37
Signed-off-by: Kevin Zhao <kevin.zhao@arm.com>
This commit is contained in:
Kevin Zhao 2017-08-25 14:00:45 +08:00
parent d49fd75750
commit 3eda49669c
3 changed files with 17 additions and 2 deletions

View File

@ -356,11 +356,11 @@ func AddIgnoreUnknownArgs() error {
}
func main() {
// Display the version on "-v", otherwise just delegate to the skel code.
// Display the version on "--version", otherwise just delegate to the skel code.
// Use a new flag set so as not to conflict with existing libraries which use "flag"
flagSet := flag.NewFlagSet("kubestack", flag.ExitOnError)
version := flagSet.Bool("v", false, "Display version")
version := flagSet.Bool("version", false, "Display version")
err := flagSet.Parse(os.Args[1:])
if err != nil {
fmt.Println(err)

View File

@ -45,6 +45,8 @@ var (
"path to stackube config file")
userCIDR = pflag.String("user-cidr", "10.244.0.0/16", "user Pod network CIDR")
userGateway = pflag.String("user-gateway", "10.244.0.1", "user Pod network gateway")
version = pflag.Bool("version", false, "Display version")
VERSION = "0.1"
)
func startControllers(kubeClient *kubernetes.Clientset,
@ -133,6 +135,11 @@ func main() {
util.InitLogs()
defer util.FlushLogs()
if *version {
fmt.Println(VERSION)
os.Exit(0)
}
// Initilize kubernetes and openstack clients.
kubeClient, osClient, kubeExtClient, err := initClients()
if err != nil {

View File

@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"os"
)
var (
@ -34,6 +35,8 @@ var (
"path to kubernetes admin config file")
cloudconfig = pflag.String("cloudconfig", "/etc/stackube.conf",
"path to stackube config file")
version = pflag.Bool("version", false, "Display version")
VERSION = "0.1"
)
func verifyClientSetting() error {
@ -60,6 +63,11 @@ func main() {
util.InitLogs()
defer util.FlushLogs()
if *version {
fmt.Println(VERSION)
os.Exit(0)
}
// Verify client setting at the beginning and fail early if there are errors.
err := verifyClientSetting()
if err != nil {