Pass version from main

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd) 2019-12-31 12:22:21 +00:00
parent 17a5e2c625
commit 03fe48db99
5 changed files with 36 additions and 27 deletions

View File

@ -1,6 +1,6 @@
Version := $(shell git describe --tags --dirty)
GitCommit := $(shell git rev-parse HEAD)
LDFLAGS := "-s -w -X pkg.Version=$(Version) -X pkg.GitCommit=$(GitCommit)"
LDFLAGS := "-s -w -X main.Version=$(Version) -X main.GitCommit=$(GitCommit)"
.PHONY: all
all: local

View File

@ -13,7 +13,16 @@ func init() {
rootCommand.AddCommand(installCmd)
}
func Execute() error {
var (
// GitCommit Git Commit SHA
GitCommit string
// Version version of the CLI
Version string
)
func Execute(gitCommit, version string) error {
GitCommit = gitCommit
Version = version
if err := rootCommand.Execute(); err != nil {
return err

View File

@ -21,10 +21,26 @@ func parseBaseCommand(_ *cobra.Command, _ []string) {
`faasd
Commit: %s
Version: %s
`, pkg.GitCommit, pkg.GetVersion())
`, GitCommit, GetVersion())
}
func printLogo() {
logoText := aec.WhiteF.Apply(pkg.Logo)
fmt.Println(logoText)
}
// GetVersion get latest version
func GetVersion() string {
if len(Version) == 0 {
return "dev"
}
return Version
}
// Logo for version and root command
const Logo = ` __ _
/ _| __ _ __ _ ___ __| |
| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` |
| _| (_| | (_| \__ \ (_| |
|_| \__,_|\__,_|___/\__,_|
`

View File

@ -6,8 +6,15 @@ import (
"github.com/alexellis/faasd/cmd"
)
var (
// GitCommit Git Commit SHA
GitCommit string
// Version version of the CLI
Version string
)
func main() {
if err := cmd.Execute(); err != nil {
if err := cmd.Execute(GitCommit, Version); err != nil {
os.Exit(1)
}
return

View File

@ -1,24 +1 @@
package pkg
var (
// GitCommit Git Commit SHA
GitCommit string
// Version version of the CLI
Version string
)
// GetVersion get latest version
func GetVersion() string {
if len(Version) == 0 {
return "dev"
}
return Version
}
// Logo for version and root command
const Logo = ` __ _
/ _| __ _ __ _ ___ __| |
| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` |
| _| (_| | (_| \__ \ (_| |
|_| \__,_|\__,_|___/\__,_|
`