From 65df4be21c656a147119c85f9e4b099da6136de8 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Thu, 26 Oct 2023 15:57:20 +0200 Subject: [PATCH] mod(cli): remove version command and replace with flag instead --- cmd/root.go | 6 ++++++ cmd/version.go | 20 -------------------- 2 files changed, 6 insertions(+), 20 deletions(-) delete mode 100644 cmd/version.go diff --git a/cmd/root.go b/cmd/root.go index 2714cbf..cd89fa2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,7 +8,10 @@ import ( "github.com/spf13/viper" ) +const VERSION string = "0.1" + var ( + version bool dry_run bool rootCmd = &cobra.Command{ Use: "gitw", @@ -24,6 +27,9 @@ func Execute() error { func init() { cobra.OnInitialize(initConfig) + // version flag + rootCmd.Flags().BoolVarP(&version, "version", "v", false, "Print version of gitwarrior") + rootCmd.Version = VERSION } func initConfig() { diff --git a/cmd/version.go b/cmd/version.go deleted file mode 100644 index 3fa5cf1..0000000 --- a/cmd/version.go +++ /dev/null @@ -1,20 +0,0 @@ -package cmd - -import ( - "fmt" - - "github.com/spf13/cobra" -) - -func init() { - rootCmd.AddCommand(versionCmd) -} - -var versionCmd = &cobra.Command{ - Use: "version", - Short: "Print the version of gitwarrior", - Long: `All software has versions. This is gitwarrior's`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("v0.1") - }, -}