moved version to --version flag of Cobra

Signed-off-by: Andreas Ulm <andreas.ulm@root360.de>
This commit is contained in:
Andreas Ulm 2019-04-28 23:24:35 +02:00
parent 98b7f52e44
commit 8a2b3a93d7
2 changed files with 11 additions and 35 deletions

View File

@ -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.

View File

@ -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)
}