2018-02-14 09:57:48 -08:00
|
|
|
package version
|
2018-01-18 03:19:41 -08:00
|
|
|
|
2018-01-18 03:38:25 -08:00
|
|
|
import (
|
|
|
|
"fmt"
|
2018-02-28 23:16:54 -08:00
|
|
|
"net/http"
|
2018-01-18 03:38:25 -08:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
2018-01-18 03:19:41 -08:00
|
|
|
|
|
|
|
var (
|
2018-01-18 06:34:45 -08:00
|
|
|
// VersionCmd prints out the current sdk version
|
|
|
|
VersionCmd = &cobra.Command{
|
2018-01-18 03:19:41 -08:00
|
|
|
Use: "version",
|
|
|
|
Short: "Print the app version",
|
2018-02-28 23:16:54 -08:00
|
|
|
Run: printVersion,
|
2018-01-18 03:19:41 -08:00
|
|
|
}
|
|
|
|
)
|
2018-01-18 03:38:25 -08:00
|
|
|
|
2018-02-28 23:16:54 -08:00
|
|
|
func getVersion() string {
|
2018-02-14 09:57:48 -08:00
|
|
|
v := Version
|
|
|
|
if GitCommit != "" {
|
|
|
|
v = v + " " + GitCommit
|
2018-01-18 03:38:25 -08:00
|
|
|
}
|
2018-02-28 23:16:54 -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-02-28 23:16:54 -08:00
|
|
|
|
|
|
|
// REST
|
|
|
|
|
|
|
|
func VersionRequestHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
v := getVersion()
|
|
|
|
w.Write([]byte(v))
|
|
|
|
}
|