From 03fe48db99fb6784ba7421bd0ad0d47a6e5341eb Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Tue, 31 Dec 2019 12:22:21 +0000 Subject: [PATCH] Pass version from main Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- Makefile | 2 +- cmd/root.go | 11 ++++++++++- cmd/version.go | 18 +++++++++++++++++- main.go | 9 ++++++++- pkg/version.go | 23 ----------------------- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 782541f..7ba99cf 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cmd/root.go b/cmd/root.go index 6de72ae..8087939 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 diff --git a/cmd/version.go b/cmd/version.go index ea8eeae..a9d2d14 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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 = ` __ _ + / _| __ _ __ _ ___ __| | +| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` | +| _| (_| | (_| \__ \ (_| | +|_| \__,_|\__,_|___/\__,_| +` diff --git a/main.go b/main.go index 4b12013..3bb0038 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/pkg/version.go b/pkg/version.go index 04bcae4..c1caffe 100644 --- a/pkg/version.go +++ b/pkg/version.go @@ -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 = ` __ _ - / _| __ _ __ _ ___ __| | -| |_ / _` + "`" + ` |/ _` + "`" + ` / __|/ _` + "`" + ` | -| _| (_| | (_| \__ \ (_| | -|_| \__,_|\__,_|___/\__,_| -`