From 2be399d742f902930ccedad0364be1785629f75b Mon Sep 17 00:00:00 2001 From: Emilio Palumbo Date: Fri, 27 Jan 2023 15:28:12 +0100 Subject: [PATCH] Update package and commands with version info --- cmd/root.go | 2 ++ pkg/version/version.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 pkg/version/version.go diff --git a/cmd/root.go b/cmd/root.go index 0baa0db..f405862 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,6 +13,7 @@ import ( "strings" "github.com/guigolab/rnaget-client/pkg/api" + "github.com/guigolab/rnaget-client/pkg/version" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -37,6 +38,7 @@ var ( Use: "rnaget-client", Short: "A demo client for the GA4GH RNAget API", Long: `A demo client for the GA4GH RNAget API`, + Version: version.Get(), PersistentPreRun: getConfig, SilenceUsage: true, SilenceErrors: true, diff --git a/pkg/version/version.go b/pkg/version/version.go new file mode 100644 index 0000000..a95b1ed --- /dev/null +++ b/pkg/version/version.go @@ -0,0 +1,21 @@ +package version + +import ( + "fmt" + "time" +) + +var ( + version = "dev" + date = "" + commit = "" +) + +func Get() string { + parsedDate, err := time.Parse(time.RFC3339, date) + if err != nil { + panic(err) + } + formattedDate := parsedDate.Format(time.RFC1123) + return fmt.Sprintf("%s\n= Git commit: \t%s\n= Built: \t%s", version, commit, formattedDate) +}