From f07c1dd454ef3bf5a456d33a1ef9bf9cbc5959fa Mon Sep 17 00:00:00 2001 From: jon4hz Date: Thu, 21 Nov 2024 15:56:59 +0100 Subject: [PATCH] chore: add version command --- main.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 68790af..3279e7f 100644 --- a/main.go +++ b/main.go @@ -12,15 +12,17 @@ import ( "github.com/charmbracelet/log" "github.com/charmbracelet/x/term" "github.com/jon4hz/awoolt/config" + "github.com/jon4hz/awoolt/version" "github.com/openbao/openbao/api/v2" "github.com/spf13/cobra" "github.com/spf13/viper" ) var rootCmd = &cobra.Command{ - Use: "awoolt", - Short: "interactively browse vault/openbao in the terminal.", - Run: root, + Use: "awoolt", + Short: "interactively browse vault/openbao in the terminal.", + Version: version.Version, + Run: root, } var rootFlags struct { @@ -39,6 +41,7 @@ func init() { rootCmd.Flags().StringVarP(&rootFlags.path, "path", "p", "", "secret path") must(viper.BindPFlags(rootCmd.Flags())) + rootCmd.AddCommand(versionCmd) } func root(cmd *cobra.Command, _ []string) { @@ -151,6 +154,17 @@ func printSecret(s *api.KVSecret) { } } +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the version info", + Run: func(_ *cobra.Command, _ []string) { + fmt.Printf("Version: %s\n", version.Version) + fmt.Printf("Commit: %s\n", version.Commit) + fmt.Printf("Date: %s\n", version.Date) + fmt.Printf("BuiltBy: %s\n", version.BuiltBy) + }, +} + func main() { if err := rootCmd.Execute(); err != nil { os.Exit(1)