mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-24 03:21:36 +01:00
moved version to --version flag of Cobra
Signed-off-by: Andreas Ulm <andreas.ulm@root360.de>
This commit is contained in:
parent
98b7f52e44
commit
8a2b3a93d7
11
cmd/root.go
11
cmd/root.go
@ -7,6 +7,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
homedir "github.com/mitchellh/go-homedir"
|
homedir "github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -15,6 +16,12 @@ import (
|
|||||||
|
|
||||||
var cfgFile string
|
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
|
// rootCmd represents the base command when called without any subcommands
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "tea",
|
Use: "tea",
|
||||||
@ -40,6 +47,10 @@ func init() {
|
|||||||
// Cobra supports persistent flags, which, if defined here,
|
// Cobra supports persistent flags, which, if defined here,
|
||||||
// will be global for your application.
|
// will be global for your application.
|
||||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.tea/tea.yaml)")
|
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.
|
// initConfig reads in config file and ENV variables if set.
|
||||||
|
@ -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)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user