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 committed by Alex Ellis
parent 17a5e2c625
commit 300d8b082a
5 changed files with 36 additions and 27 deletions

View File

@ -1,6 +1,6 @@
Version := $(shell git describe --tags --dirty) Version := $(shell git describe --tags --dirty)
GitCommit := $(shell git rev-parse HEAD) 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 .PHONY: all
all: local all: local

View File

@ -13,7 +13,16 @@ func init() {
rootCommand.AddCommand(installCmd) 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 { if err := rootCommand.Execute(); err != nil {
return err return err

View File

@ -21,10 +21,26 @@ func parseBaseCommand(_ *cobra.Command, _ []string) {
`faasd `faasd
Commit: %s Commit: %s
Version: %s Version: %s
`, pkg.GitCommit, pkg.GetVersion()) `, GitCommit, GetVersion())
} }
func printLogo() { func printLogo() {
logoText := aec.WhiteF.Apply(pkg.Logo) logoText := aec.WhiteF.Apply(pkg.Logo)
fmt.Println(logoText) 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" "github.com/alexellis/faasd/cmd"
) )
var (
// GitCommit Git Commit SHA
GitCommit string
// Version version of the CLI
Version string
)
func main() { func main() {
if err := cmd.Execute(); err != nil { if err := cmd.Execute(GitCommit, Version); err != nil {
os.Exit(1) os.Exit(1)
} }
return return

View File

@ -1,24 +1 @@
package pkg 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 = ` __ _
/ _| __ _ __ _ ___ __| |
| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` |
| _| (_| | (_| \__ \ (_| |
|_| \__,_|\__,_|___/\__,_|
`