Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go: Unify CLI tools' version display #3233

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/3233.feature.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go: Unify CLI tools' version display and also display the Go toolchain version
4 changes: 4 additions & 0 deletions .changelog/3233.feature.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions go/extra/stats/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func Execute() {
}

func init() {
common.SetBasicVersionTemplate(rootCmd)

logLevel := logging.LevelInfo
rootFlags.Var(&logLevel, cfgLogLevel, "log level")
_ = viper.BindPFlags(rootFlags)
Expand Down
2 changes: 2 additions & 0 deletions go/oasis-net-runner/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ func doDumpFixture(cmd *cobra.Command, args []string) {
}

func init() {
common.SetBasicVersionTemplate(rootCmd)

logFmt := logging.FmtLogfmt
logLevel := logging.LevelInfo

Expand Down
13 changes: 13 additions & 0 deletions go/oasis-node/cmd/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 -}}
`)
}
2 changes: 2 additions & 0 deletions go/oasis-remote-signer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
2 changes: 2 additions & 0 deletions go/oasis-test-runner/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ func runList(cmd *cobra.Command, args []string) {
}

func init() {
nodeCommon.SetBasicVersionTemplate(rootCmd)

logFmt := logging.FmtLogfmt
logLevel := logging.LevelWarn

Expand Down