Merge PR #4372: Use Build's Client/Server Name
This commit is contained in:
+28
-34
@@ -10,40 +10,34 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
)
|
||||
|
||||
const (
|
||||
flagLong = "long"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
// VersionCmd prints out the application's version
|
||||
// information passed via build flags.
|
||||
VersionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print the app version",
|
||||
RunE: func(_ *cobra.Command, _ []string) error {
|
||||
verInfo := newVersionInfo()
|
||||
|
||||
if !viper.GetBool(flagLong) {
|
||||
fmt.Println(verInfo.Version)
|
||||
return nil
|
||||
}
|
||||
|
||||
if viper.GetString(cli.OutputFlag) != "json" {
|
||||
fmt.Println(verInfo)
|
||||
return nil
|
||||
}
|
||||
|
||||
bz, err := json.Marshal(verInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(string(bz))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
)
|
||||
const flagLong = "long"
|
||||
|
||||
func init() {
|
||||
VersionCmd.Flags().Bool(flagLong, false, "Print long version information")
|
||||
Cmd.Flags().Bool(flagLong, false, "Print long version information")
|
||||
}
|
||||
|
||||
// Cmd prints out the application's version information passed via build flags.
|
||||
var Cmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print the app version",
|
||||
RunE: func(_ *cobra.Command, _ []string) error {
|
||||
verInfo := newVersionInfo()
|
||||
|
||||
if !viper.GetBool(flagLong) {
|
||||
fmt.Println(verInfo.Version)
|
||||
return nil
|
||||
}
|
||||
|
||||
if viper.GetString(cli.OutputFlag) != "json" {
|
||||
fmt.Println(verInfo)
|
||||
return nil
|
||||
}
|
||||
|
||||
bz, err := json.Marshal(verInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(string(bz))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
+31
-18
@@ -1,4 +1,4 @@
|
||||
// This package is a convenience utility that provides SDK
|
||||
// Package version is a convenience utility that provides SDK
|
||||
// consumers with a ready-to-use version command that
|
||||
// produces apps versioning information based on flags
|
||||
// passed at compile time.
|
||||
@@ -9,7 +9,9 @@
|
||||
// At build time, the variables Name, Version, Commit, and BuildTags
|
||||
// can be passed as build flags as shown in the following example:
|
||||
//
|
||||
// go build -X github.com/cosmos/cosmos-sdk/version.Name=dapp \
|
||||
// go build -X github.com/cosmos/cosmos-sdk/version.Name=gaia \
|
||||
// -X github.com/cosmos/cosmos-sdk/version.ServerName=gaiad \
|
||||
// -X github.com/cosmos/cosmos-sdk/version.ClientName=gaiacli \
|
||||
// -X github.com/cosmos/cosmos-sdk/version.Version=1.0 \
|
||||
// -X github.com/cosmos/cosmos-sdk/version.Commit=f0f7b7dab7e36c20b757cebce0e8f4fc5b95de60 \
|
||||
// -X "github.com/cosmos/cosmos-sdk/version.BuildTags=linux darwin amd64"
|
||||
@@ -21,38 +23,49 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// Application's name
|
||||
// application's name
|
||||
Name = ""
|
||||
// Application's version string
|
||||
// server binary name
|
||||
ServerName = "<appd>"
|
||||
// client binary name
|
||||
ClientName = "<appcli>"
|
||||
// application's version string
|
||||
Version = ""
|
||||
// Commit
|
||||
// commit
|
||||
Commit = ""
|
||||
// Hash of the go.sum file
|
||||
// hash of the go.sum file
|
||||
GoSumHash = ""
|
||||
// Build tags
|
||||
// build tags
|
||||
BuildTags = ""
|
||||
)
|
||||
|
||||
type versionInfo struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
GitCommit string `json:"commit"`
|
||||
BuildTags string `json:"build_tags"`
|
||||
GoVersion string `json:"go"`
|
||||
Name string `json:"name"`
|
||||
ServerName string `json:"server_name"`
|
||||
ClientName string `json:"client_name"`
|
||||
Version string `json:"version"`
|
||||
GitCommit string `json:"commit"`
|
||||
BuildTags string `json:"build_tags"`
|
||||
GoVersion string `json:"go"`
|
||||
}
|
||||
|
||||
func (v versionInfo) String() string {
|
||||
return fmt.Sprintf(`%s: %s
|
||||
git commit: %s
|
||||
build tags: %s
|
||||
%s`, v.Name, v.Version, v.GitCommit, v.BuildTags, v.GoVersion)
|
||||
%s`,
|
||||
v.Name, v.Version, v.GitCommit, v.BuildTags, v.GoVersion,
|
||||
)
|
||||
}
|
||||
|
||||
func newVersionInfo() versionInfo {
|
||||
return versionInfo{
|
||||
Name,
|
||||
Version,
|
||||
Commit,
|
||||
BuildTags,
|
||||
fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH)}
|
||||
Name: Name,
|
||||
ServerName: ServerName,
|
||||
ClientName: ClientName,
|
||||
Version: Version,
|
||||
GitCommit: Commit,
|
||||
BuildTags: BuildTags,
|
||||
GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user