Skip to content

Commit

Permalink
Add standard version command that prints current version untillpro#7
Browse files Browse the repository at this point in the history
  • Loading branch information
host6 committed Apr 13, 2023
1 parent 8ee1090 commit 8791920
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions cobrau/rootcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package cobrau

import (
"fmt"

"github.com/spf13/cobra"
"github.com/untillpro/goutils/logger"
)
Expand All @@ -19,11 +21,11 @@ Persistent flags:
*/

func PrepareRootCmd(use string, short string, args []string, cmds ...*cobra.Command) *cobra.Command {
func PrepareRootCmd(use string, short string, args []string, version string, cmds ...*cobra.Command) *cobra.Command {

var rootCmd = &cobra.Command{
Use: use,
Short: "Cluster management utility written in golang",
Short: short,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if ok, _ := cmd.Flags().GetBool("trace"); ok {
logger.SetLogLevel(logger.LogLevelTrace)
Expand All @@ -35,7 +37,17 @@ func PrepareRootCmd(use string, short string, args []string, cmds ...*cobra.Comm
},
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print current version",
Aliases: []string{"ver"},
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version)
},
}

rootCmd.SetArgs(args[1:])
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(cmds...)
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Verbose output")
rootCmd.PersistentFlags().Bool("trace", false, "Extremely verbose output")
Expand Down

0 comments on commit 8791920

Please sign in to comment.