Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster&dm/display: add an option to only show cluster version #1207

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/cluster/command/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func newDisplayCmd() *cobra.Command {
var (
clusterName string
showDashboardOnly bool
showVersionOnly bool
)
cmd := &cobra.Command{
Use: "display <cluster-name>",
Expand All @@ -59,6 +60,12 @@ func newDisplayCmd() *cobra.Command {
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) {
return err
}

if showVersionOnly {
fmt.Println(metadata.Version)
return nil
}

if showDashboardOnly {
tlsCfg, err := metadata.Topology.TLSConfig(tidbSpec.Path(clusterName, spec.TLSCertKeyDir))
if err != nil {
Expand All @@ -74,6 +81,7 @@ func newDisplayCmd() *cobra.Command {
cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only display specified roles")
cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Only display specified nodes")
cmd.Flags().BoolVar(&showDashboardOnly, "dashboard", false, "Only display TiDB Dashboard information")
cmd.Flags().BoolVar(&showVersionOnly, "version", false, "Only display TiDB cluster version")

return cmd
}
Expand Down
20 changes: 19 additions & 1 deletion components/dm/command/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@
package command

import (
"errors"
"fmt"

perrs "github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cluster/spec"
"github.com/pingcap/tiup/pkg/meta"
"github.com/spf13/cobra"
)

func newDisplayCmd() *cobra.Command {
var (
clusterName string
clusterName string
showVersionOnly bool
)
cmd := &cobra.Command{
Use: "display <cluster-name>",
Expand All @@ -31,11 +38,22 @@ func newDisplayCmd() *cobra.Command {

clusterName = args[0]

if showVersionOnly {
metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
return err
}
fmt.Println(metadata.Version)
return nil
}

return cm.Display(clusterName, gOpt)
},
}

cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only display specified roles")
cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Only display specified nodes")
cmd.Flags().BoolVar(&showVersionOnly, "version", false, "Only display DM cluster version")

return cmd
}