cosmos-sdk/version/command.go

38 lines
585 B
Go
Raw Normal View History

package version
2018-01-18 03:38:25 -08:00
import (
"fmt"
"net/http"
2018-01-18 03:38:25 -08:00
"github.com/spf13/cobra"
)
var (
// VersionCmd prints out the current sdk version
VersionCmd = &cobra.Command{
Use: "version",
Short: "Print the app version",
Run: printVersion,
}
)
2018-01-18 03:38:25 -08:00
func getVersion() string {
v := Version
if GitCommit != "" {
v = v + "-" + GitCommit
2018-01-18 03:38:25 -08:00
}
return v
}
// CMD
func printVersion(cmd *cobra.Command, args []string) {
v := getVersion()
2018-01-18 03:38:25 -08:00
fmt.Println(v)
}
2018-04-18 21:49:24 -07:00
// version REST handler endpoint
func RequestHandler(w http.ResponseWriter, r *http.Request) {
v := getVersion()
w.Write([]byte(v))
}