From 0deccc7050da61b712cfaf73e0d525f0b2c4c8ba Mon Sep 17 00:00:00 2001 From: Eric Chiang Date: Fri, 15 Jan 2016 11:12:41 -0800 Subject: [PATCH] cmd: add version to command worker and overlord, print go version Closes #272 --- cmd/dex-overlord/main.go | 9 +++++++++ cmd/dex-worker/main.go | 8 ++++++++ cmd/dexctl/command_version.go | 9 +++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cmd/dex-overlord/main.go b/cmd/dex-overlord/main.go index 9f4715cf..d18271ce 100644 --- a/cmd/dex-overlord/main.go +++ b/cmd/dex-overlord/main.go @@ -7,6 +7,8 @@ import ( "net/http" "net/url" "os" + "runtime" + "strings" "time" "github.com/coreos/go-oidc/key" @@ -50,6 +52,8 @@ func main() { logDebug := fs.Bool("log-debug", false, "log debug-level information") logTimestamps := fs.Bool("log-timestamps", false, "prefix log lines with timestamps") + printVersion := fs.Bool("version", false, "Print the version and exit") + if err := fs.Parse(os.Args[1:]); err != nil { fmt.Fprintln(os.Stderr, err.Error()) os.Exit(1) @@ -60,6 +64,11 @@ func main() { os.Exit(1) } + if *printVersion { + fmt.Printf("dex version %s\ngo version %s\n", strings.TrimPrefix(version, "v"), strings.TrimPrefix(runtime.Version(), "go")) + os.Exit(0) + } + if *logDebug { log.EnableDebug() } diff --git a/cmd/dex-worker/main.go b/cmd/dex-worker/main.go index ae960ed3..bc3d764e 100644 --- a/cmd/dex-worker/main.go +++ b/cmd/dex-worker/main.go @@ -7,6 +7,8 @@ import ( "net/http" "net/url" "os" + "runtime" + "strings" "time" "github.com/coreos/pkg/flagutil" @@ -62,6 +64,7 @@ func main() { dbMaxIdleConns := fs.Int("db-max-idle-conns", 0, "maximum number of connections in the idle connection pool") dbMaxOpenConns := fs.Int("db-max-open-conns", 0, "maximum number of open connections to the database") + printVersion := fs.Bool("version", false, "Print the version and exit") // used only if --no-db is set connectors := fs.String("connectors", "./static/fixtures/connectors.json", "JSON file containg set of IDPC configs") @@ -81,6 +84,11 @@ func main() { os.Exit(1) } + if *printVersion { + fmt.Printf("dex version %s\ngo version %s\n", strings.TrimPrefix(version, "v"), strings.TrimPrefix(runtime.Version(), "go")) + os.Exit(0) + } + if *logDebug { log.EnableDebug() log.Infof("Debug logging enabled.") diff --git a/cmd/dexctl/command_version.go b/cmd/dexctl/command_version.go index 37443f58..d8e25422 100644 --- a/cmd/dexctl/command_version.go +++ b/cmd/dexctl/command_version.go @@ -1,6 +1,11 @@ package main -import "github.com/spf13/cobra" +import ( + "runtime" + "strings" + + "github.com/spf13/cobra" +) var ( // set by the top level build script @@ -11,7 +16,7 @@ var ( Short: "Print the dexctl version.", Long: "Print the dexctl version.", Run: func(cmd *cobra.Command, args []string) { - stdout(version) + stdout("dex version %s\ngo version %s", strings.TrimPrefix(version, "v"), strings.TrimPrefix(runtime.Version(), "go")) }, } )