version

package
v0.36.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 7 Imported by: 3,850

Documentation

Overview

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.

Configure the version command

The version command can be just added to your cobra root command. 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=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"

Index

Constants

This section is empty.

Variables

View Source
var (
	// application's name
	Name = ""
	// server binary name
	ServerName = "<appd>"
	// client binary name
	ClientName = "<appcli>"
	// application's version string
	Version = ""
	// commit
	Commit = ""
	// hash of the go.sum file
	GoSumHash = ""
	// build tags
	BuildTags = ""
)
View Source
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
		}

		var bz []byte
		var err error

		switch viper.GetString(cli.OutputFlag) {
		case "json":
			bz, err = json.Marshal(verInfo)
		default:
			bz, err = yaml.Marshal(&verInfo)
		}

		if err != nil {
			return err
		}

		_, err = fmt.Println(string(bz))
		return err
	},
}

Cmd prints out the application's version information passed via build flags.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL