From a4023d5212ae200b7dc21e8e6cea5c5bbce9410d Mon Sep 17 00:00:00 2001 From: Jianwei Mao Date: Sun, 13 Oct 2024 23:45:42 +0800 Subject: [PATCH] support version command to show code-version for convenience Signed-off-by: Jianwei Mao --- main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 1f53015..b34c9f3 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( branch "MaoServerDiscovery/cmd" "MaoServerDiscovery/util" "errors" + "fmt" "github.com/spf13/cobra" "net" "os" @@ -137,6 +138,16 @@ var serverCmd = &cobra.Command{ }, } +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Mao: Show software version and code version.", + Long: "Mao-Service-Discovery: Show software version and code version.", + // Version: SERVER_VERSION, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("MaoServerDiscovery version " + ROOT_VERSION_SIGNATURE) + }, +} + /** Common: - report_server_addr : connect to / listen on the addr, for service discovery @@ -396,7 +407,7 @@ func main() { util.MaoLog(util.INFO, "enable pprof: %v", http.ListenAndServe("0.0.0.0:39999", nil)) }() - rootCmd.AddCommand(generalClientCmd, serverCmd) + rootCmd.AddCommand(versionCmd, generalClientCmd, serverCmd) if err := rootCmd.Execute(); err != nil { //util.MaoLog(util.ERROR, fmt.Sprintf("Fail to execute rootCmd: %s", err))