2019-05-18 16:06:08 -07:00
|
|
|
// Package version is a convenience utility that provides SDK
|
2019-05-02 12:37:44 -07:00
|
|
|
// consumers with a ready-to-use version command that
|
|
|
|
// produces apps versioning information based on flags
|
|
|
|
// passed at compile time.
|
|
|
|
//
|
|
|
|
// Configure the version command
|
|
|
|
//
|
|
|
|
// The version command can be just added to your cobra root command.
|
2019-05-13 15:33:34 -07:00
|
|
|
// At build time, the variables Name, Version, Commit, and BuildTags
|
|
|
|
// can be passed as build flags as shown in the following example:
|
2019-05-02 12:37:44 -07:00
|
|
|
//
|
2019-05-18 16:06:08 -07:00
|
|
|
// go build -X github.com/cosmos/cosmos-sdk/version.Name=gaia \
|
2020-07-07 08:40:46 -07:00
|
|
|
// -X github.com/cosmos/cosmos-sdk/version.AppName=gaiad \
|
2019-05-02 12:37:44 -07:00
|
|
|
// -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"
|
2017-03-01 10:12:25 -08:00
|
|
|
package version
|
|
|
|
|
2019-01-29 14:25:43 -08:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
2019-01-22 12:16:29 -08:00
|
|
|
var (
|
2019-05-18 16:06:08 -07:00
|
|
|
// application's name
|
2019-05-02 12:37:44 -07:00
|
|
|
Name = ""
|
2020-07-07 08:40:46 -07:00
|
|
|
// application binary name
|
|
|
|
AppName = "<appd>"
|
2019-05-18 16:06:08 -07:00
|
|
|
// application's version string
|
2019-05-02 12:37:44 -07:00
|
|
|
Version = ""
|
2019-05-18 16:06:08 -07:00
|
|
|
// commit
|
2019-05-02 12:37:44 -07:00
|
|
|
Commit = ""
|
2019-05-18 16:06:08 -07:00
|
|
|
// build tags
|
2019-04-08 08:00:17 -07:00
|
|
|
BuildTags = ""
|
2019-01-22 12:16:29 -08:00
|
|
|
)
|
2019-01-29 14:25:43 -08:00
|
|
|
|
2019-08-02 08:52:55 -07:00
|
|
|
// Info defines the application version information.
|
|
|
|
type Info struct {
|
2020-07-07 08:40:46 -07:00
|
|
|
Name string `json:"name" yaml:"name"`
|
|
|
|
AppName string `json:"server_name" yaml:"server_name"`
|
|
|
|
Version string `json:"version" yaml:"version"`
|
|
|
|
GitCommit string `json:"commit" yaml:"commit"`
|
|
|
|
BuildTags string `json:"build_tags" yaml:"build_tags"`
|
|
|
|
GoVersion string `json:"go" yaml:"go"`
|
2019-01-29 14:25:43 -08:00
|
|
|
}
|
|
|
|
|
2019-08-02 08:52:55 -07:00
|
|
|
func NewInfo() Info {
|
|
|
|
return Info{
|
2020-07-07 08:40:46 -07:00
|
|
|
Name: Name,
|
|
|
|
AppName: AppName,
|
|
|
|
Version: Version,
|
|
|
|
GitCommit: Commit,
|
|
|
|
BuildTags: BuildTags,
|
|
|
|
GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
|
2019-05-18 16:06:08 -07:00
|
|
|
}
|
2019-01-29 14:25:43 -08:00
|
|
|
}
|
2019-08-02 08:52:55 -07:00
|
|
|
|
|
|
|
func (vi Info) String() string {
|
|
|
|
return fmt.Sprintf(`%s: %s
|
|
|
|
git commit: %s
|
|
|
|
build tags: %s
|
|
|
|
%s`,
|
|
|
|
vi.Name, vi.Version, vi.GitCommit, vi.BuildTags, vi.GoVersion,
|
|
|
|
)
|
|
|
|
}
|