From 2f9ca25488eea2ccfafbca5f61678095c1c0c451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Thu, 3 Sep 2020 14:26:14 +0200 Subject: [PATCH 1/2] go/oasis-node/cmd/common: Add SetBasicVersionTemplate() function --- .changelog/3233.feature.md | 4 ++++ go/oasis-node/cmd/common/common.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .changelog/3233.feature.md diff --git a/.changelog/3233.feature.md b/.changelog/3233.feature.md new file mode 100644 index 00000000000..e0c7535c509 --- /dev/null +++ b/.changelog/3233.feature.md @@ -0,0 +1,4 @@ +go/oasis-node/cmd/common: Add `SetBasicVersionTemplate()` function + +It can be used to set a basic custom version template for the given cobra +command that shows the version of Oasis Core and the Go toolchain. diff --git a/go/oasis-node/cmd/common/common.go b/go/oasis-node/cmd/common/common.go index 7a4ed65dc93..4b2e7fad555 100644 --- a/go/oasis-node/cmd/common/common.go +++ b/go/oasis-node/cmd/common/common.go @@ -18,6 +18,7 @@ import ( "github.com/oasisprotocol/oasis-core/go/common/entity" "github.com/oasisprotocol/oasis-core/go/common/logging" "github.com/oasisprotocol/oasis-core/go/common/sgx/ias" + "github.com/oasisprotocol/oasis-core/go/common/version" "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags" cmdSigner "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/signer" ) @@ -309,3 +310,15 @@ func GetUserConfirmation(prompt string) bool { } } } + +// SetBasicVersionTemplate sets a basic custom version template for the given +// cobra command that shows the version of Oasis Core and the Go toolchain. +func SetBasicVersionTemplate(cmd *cobra.Command) { + cobra.AddTemplateFunc("additionalVersions", func() interface{} { return version.Versions }) + + cmd.SetVersionTemplate(`Software version: {{.Version}} +{{- with additionalVersions }} +Go toolchain version: {{ .Toolchain }} +{{ end -}} +`) +} From 7c25faaf945f7bf99a939233ca1b5544fe98715b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Thu, 3 Sep 2020 14:36:06 +0200 Subject: [PATCH 2/2] go: Unify CLI tools' version display and also display Go version --- .changelog/3233.feature.2.md | 1 + go/extra/stats/cmd/root.go | 2 ++ go/oasis-net-runner/cmd/root.go | 2 ++ go/oasis-remote-signer/cmd/root.go | 2 ++ go/oasis-test-runner/cmd/root.go | 2 ++ 5 files changed, 9 insertions(+) create mode 100644 .changelog/3233.feature.2.md diff --git a/.changelog/3233.feature.2.md b/.changelog/3233.feature.2.md new file mode 100644 index 00000000000..28265cd127c --- /dev/null +++ b/.changelog/3233.feature.2.md @@ -0,0 +1 @@ +go: Unify CLI tools' version display and also display the Go toolchain version diff --git a/go/extra/stats/cmd/root.go b/go/extra/stats/cmd/root.go index a05723c2e13..d88bc9a3806 100644 --- a/go/extra/stats/cmd/root.go +++ b/go/extra/stats/cmd/root.go @@ -44,6 +44,8 @@ func Execute() { } func init() { + common.SetBasicVersionTemplate(rootCmd) + logLevel := logging.LevelInfo rootFlags.Var(&logLevel, cfgLogLevel, "log level") _ = viper.BindPFlags(rootFlags) diff --git a/go/oasis-net-runner/cmd/root.go b/go/oasis-net-runner/cmd/root.go index d233b5ca0c7..9fce93a7668 100644 --- a/go/oasis-net-runner/cmd/root.go +++ b/go/oasis-net-runner/cmd/root.go @@ -181,6 +181,8 @@ func doDumpFixture(cmd *cobra.Command, args []string) { } func init() { + common.SetBasicVersionTemplate(rootCmd) + logFmt := logging.FmtLogfmt logLevel := logging.LevelInfo diff --git a/go/oasis-remote-signer/cmd/root.go b/go/oasis-remote-signer/cmd/root.go index e3ebbb963ac..da95274be48 100644 --- a/go/oasis-remote-signer/cmd/root.go +++ b/go/oasis-remote-signer/cmd/root.go @@ -212,6 +212,8 @@ func runRoot(cmd *cobra.Command, args []string) error { } func init() { + cmdCommon.SetBasicVersionTemplate(rootCmd) + _ = viper.BindPFlags(cmdCommon.RootFlags) rootFlags.String(cfgClientCertificate, "client_cert.pem", "client TLS certificate (REQUIRED)") diff --git a/go/oasis-test-runner/cmd/root.go b/go/oasis-test-runner/cmd/root.go index e4d7ac08044..4da44354847 100644 --- a/go/oasis-test-runner/cmd/root.go +++ b/go/oasis-test-runner/cmd/root.go @@ -568,6 +568,8 @@ func runList(cmd *cobra.Command, args []string) { } func init() { + nodeCommon.SetBasicVersionTemplate(rootCmd) + logFmt := logging.FmtLogfmt logLevel := logging.LevelWarn