From 8a2b3a93d7b3cd4c8aa0310234befd59896b7240 Mon Sep 17 00:00:00 2001 From: Andreas Ulm Date: Sun, 28 Apr 2019 23:24:35 +0200 Subject: [PATCH] moved version to --version flag of Cobra Signed-off-by: Andreas Ulm --- cmd/root.go | 11 +++++++++++ cmd/version.go | 35 ----------------------------------- 2 files changed, 11 insertions(+), 35 deletions(-) delete mode 100644 cmd/version.go diff --git a/cmd/root.go b/cmd/root.go index 1ee6cce..2b16a43 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,6 +7,7 @@ package cmd import ( "fmt" "os" + "strings" homedir "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" @@ -15,6 +16,12 @@ import ( var cfgFile string +// Version holds the current Gitea version +var Version = "0.1.0-dev" + +// Tags holds the build tags used +var Tags = "" + // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "tea", @@ -40,6 +47,10 @@ func init() { // Cobra supports persistent flags, which, if defined here, // will be global for your application. rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.tea/tea.yaml)") + if len(Tags) > 0 { + Version += " built with: " + strings.Replace(Tags, " ", ", ", -1) + } + rootCmd.Version = Version } // initConfig reads in config file and ENV variables if set. diff --git a/cmd/version.go b/cmd/version.go deleted file mode 100644 index e9f8813..0000000 --- a/cmd/version.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright © 2019 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package cmd - -import ( - "fmt" - "strings" - - "github.com/spf13/cobra" -) - -// Version holds the current Gitea version -var Version = "0.1.0-dev" - -// Tags holds the build tags used -var Tags = "" - -// versionCmd represents the version command -var versionCmd = &cobra.Command{ - Use: "version", - Short: "Print version", - Long: ``, - Run: func(cmd *cobra.Command, args []string) { - if len(Tags) > 0 { - Version += " built with: " + strings.Replace(Tags, " ", ", ", -1) - } - fmt.Println("Version " + Version) - }, -} - -func init() { - rootCmd.AddCommand(versionCmd) -}