From 1caa73c6c27fb3248959274f37011376e63d6731 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 12 Jul 2023 15:33:48 +0200 Subject: [PATCH] Add CLI version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` vscode ➜ /workspace/ovm-cli (main) $ go run main.go --version ovm-cli version v0.2.0-1-g6088990 vscode ➜ /workspace/ovm-cli (main) $ ``` --- .gitignore | 1 + cmd/root.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2db3b32d..8b12dafd 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ go.work dist/ tracing/commit.txt +cmd/commit.txt diff --git a/cmd/root.go b/cmd/root.go index 625b9687..d2ea4e90 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "context" + _ "embed" "errors" "fmt" "net/http" @@ -27,11 +28,16 @@ var logLevel string var minStatusInterval = durationpb.New(250 * time.Millisecond) +//go:generate sh -c "echo -n $(git describe --long) > commit.txt" +//go:embed commit.txt +var cliVersion string + // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Use: "ovm-cli", - Short: "A CLI to interact with the overmind API", - Long: `The ovm-cli allows direct access to the overmind API`, + Use: "ovm-cli", + Short: "A CLI to interact with the overmind API", + Long: `The ovm-cli allows direct access to the overmind API`, + Version: cliVersion, PreRun: func(cmd *cobra.Command, args []string) { // Bind these to viper err := viper.BindPFlags(cmd.Flags())