Skip to content

Commit

Permalink
cmd: adjust version printing of components
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroProfundis committed Feb 26, 2021
1 parent b02b7fe commit 1653f84
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
16 changes: 4 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ func init() {
cobra.EnableCommandSorting = false

var (
binary string
binPath string
tag string
printVersion bool
binary string
binPath string
tag string
)

rootCmd = &cobra.Command{
Expand All @@ -49,15 +48,13 @@ locally will be used. If the specified component does not have any version insta
the latest stable version will be downloaded from the repository.`,

SilenceErrors: true,
Version: version.NewTiUPVersion().String(),
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
Args: func(cmd *cobra.Command, args []string) error {
// Support `tiup <component>`
return nil
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if printVersion && len(args) == 0 {
return nil
}
e, err := environment.InitEnv(repoOpts)
if err != nil {
return err
Expand All @@ -66,10 +63,6 @@ the latest stable version will be downloaded from the repository.`,
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if printVersion && len(args) == 0 {
fmt.Println(version.NewTiUPVersion().String())
return nil
}
env := environment.GlobalEnv()
if binary != "" {
component, ver := environment.ParseCompVersion(binary)
Expand Down Expand Up @@ -113,7 +106,6 @@ the latest stable version will be downloaded from the repository.`,
}

rootCmd.PersistentFlags().BoolVarP(&repoOpts.SkipVersionCheck, "skip-version-check", "", false, "Skip the strict version check, by default a version must be a valid SemVer string")
rootCmd.Flags().BoolVarP(&printVersion, "version", "v", false, "Print the version of tiup")
rootCmd.Flags().StringVarP(&binary, "binary", "B", "", "Print binary path of a specific version of a component `<component>[:version]`\n"+
"and the latest version installed will be selected if no version specified")
rootCmd.Flags().StringVarP(&tag, "tag", "T", "", "Specify a tag for component instance")
Expand Down
2 changes: 2 additions & 0 deletions components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/pingcap/tiup/pkg/localdata"
"github.com/pingcap/tiup/pkg/repository"
"github.com/pingcap/tiup/pkg/utils"
"github.com/pingcap/tiup/pkg/version"
"github.com/spf13/cobra"
"go.etcd.io/etcd/clientv3"
"go.uber.org/zap"
Expand Down Expand Up @@ -108,6 +109,7 @@ Examples:
$ tiup playground --db.binpath /xx/tidb-server # Start a local cluster with component binary path`,
SilenceUsage: true,
SilenceErrors: true,
Version: version.NewTiUPVersion().String(),
Args: func(cmd *cobra.Command, args []string) error {
return nil
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func (v *TiUPVersion) Name() string {

// SemVer returns TiUPVersion in semver format
func (v *TiUPVersion) SemVer() string {
return fmt.Sprintf("v%d.%d.%d", v.major, v.minor, v.patch)
return fmt.Sprintf("%d.%d.%d", v.major, v.minor, v.patch)
}

// String converts TiUPVersion to a string
func (v *TiUPVersion) String() string {
return fmt.Sprintf("v%d.%d.%d %s\n%s", v.major, v.minor, v.patch, v.name, NewTiUPBuildInfo())
return fmt.Sprintf("%s %s\n%s", v.SemVer(), v.name, NewTiUPBuildInfo())
}

// TiUPBuild is the info of building environment
Expand Down
6 changes: 4 additions & 2 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"os"

"github.com/pingcap/tiup/pkg/logger/log"
"github.com/pingcap/tiup/pkg/version"
"github.com/spf13/cobra"
)

Expand All @@ -27,8 +28,9 @@ func main() {
upstream := "https://tiup-mirrors.pingcap.com"

cmd := &cobra.Command{
Use: fmt.Sprintf("%s <root-dir>", os.Args[0]),
Short: "bootstrap a mirror server",
Use: fmt.Sprintf("%s <root-dir>", os.Args[0]),
Short: "bootstrap a mirror server",
Version: version.NewTiUPVersion().String(),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return cmd.Help()
Expand Down

0 comments on commit 1653f84

Please sign in to comment.