diff --git a/components/cluster/command/clean.go b/components/cluster/command/clean.go index e455f64a72..044866bccb 100644 --- a/components/cluster/command/clean.go +++ b/components/cluster/command/clean.go @@ -57,6 +57,14 @@ You can retain some nodes and roles data when cleanup the cluster, eg: return cm.CleanCluster(clusterName, gOpt, cleanOpt, skipConfirm) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringArrayVar(&cleanOpt.RetainDataNodes, "ignore-node", nil, "Specify the nodes or hosts whose data will be retained") diff --git a/components/cluster/command/deploy.go b/components/cluster/command/deploy.go index 77c4ca04eb..78caab41e4 100644 --- a/components/cluster/command/deploy.go +++ b/components/cluster/command/deploy.go @@ -67,6 +67,14 @@ func newDeploy() *cobra.Command { return cm.Deploy(clusterName, version, topoFile, opt, postDeployHook, skipConfirm, gOpt) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 2: + return nil, cobra.ShellCompDirectiveDefault + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.") diff --git a/components/cluster/command/destroy.go b/components/cluster/command/destroy.go index 4325c607a5..d8d6e7a2dd 100644 --- a/components/cluster/command/destroy.go +++ b/components/cluster/command/destroy.go @@ -53,6 +53,14 @@ You can retain some nodes and roles data when destroy cluster, eg: return cm.DestroyCluster(clusterName, gOpt, destroyOpt, skipConfirm) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringArrayVar(&destroyOpt.RetainDataNodes, "retain-node-data", nil, "Specify the nodes or hosts whose data will be retained") diff --git a/components/cluster/command/disable.go b/components/cluster/command/disable.go index e0cb80972e..2e53c0ace0 100644 --- a/components/cluster/command/disable.go +++ b/components/cluster/command/disable.go @@ -36,6 +36,14 @@ func newDisableCmd() *cobra.Command { return cm.EnableCluster(clusterName, gOpt, false) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only disable specified roles") diff --git a/components/cluster/command/display.go b/components/cluster/command/display.go index a37c0aaf3f..b38b0b9557 100644 --- a/components/cluster/command/display.go +++ b/components/cluster/command/display.go @@ -16,9 +16,11 @@ package command import ( "errors" "fmt" + "strings" "time" perrs "github.com/pingcap/errors" + "github.com/pingcap/tiup/pkg/cluster/manager" "github.com/pingcap/tiup/pkg/cluster/spec" "github.com/pingcap/tiup/pkg/meta" "github.com/spf13/cobra" @@ -77,6 +79,14 @@ func newDisplayCmd() *cobra.Command { } return cm.Display(clusterName, gOpt) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only display specified roles") @@ -89,3 +99,14 @@ func newDisplayCmd() *cobra.Command { return cmd } + +func shellCompGetClusterName(cm *manager.Manager, toComplete string) ([]string, cobra.ShellCompDirective) { + var result []string + clusters, _ := cm.GetClusterList() + for _, c := range clusters { + if strings.HasPrefix(c.Name, toComplete) { + result = append(result, c.Name) + } + } + return result, cobra.ShellCompDirectiveNoFileComp +} diff --git a/components/cluster/command/edit_config.go b/components/cluster/command/edit_config.go index 7166a5c53b..a305c53ec4 100644 --- a/components/cluster/command/edit_config.go +++ b/components/cluster/command/edit_config.go @@ -34,6 +34,14 @@ func newEditConfigCmd() *cobra.Command { return cm.EditConfig(clusterName, opt, skipConfirm) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringVarP(&opt.NewTopoFile, "topology-file", "", opt.NewTopoFile, "Use provided topology file to substitute the original one instead of editing it.") diff --git a/components/cluster/command/enable.go b/components/cluster/command/enable.go index 3a38b41092..f5a457c827 100644 --- a/components/cluster/command/enable.go +++ b/components/cluster/command/enable.go @@ -36,6 +36,14 @@ func newEnableCmd() *cobra.Command { return cm.EnableCluster(clusterName, gOpt, true) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only enable specified roles") diff --git a/components/cluster/command/exec.go b/components/cluster/command/exec.go index 17ad5c14c3..01566642c0 100644 --- a/components/cluster/command/exec.go +++ b/components/cluster/command/exec.go @@ -35,6 +35,14 @@ func newExecCmd() *cobra.Command { return cm.Exec(clusterName, opt, gOpt) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringVar(&opt.Command, "command", "ls", "the command run on cluster host") diff --git a/components/cluster/command/prune.go b/components/cluster/command/prune.go index 26b67374be..44f2aeb463 100644 --- a/components/cluster/command/prune.go +++ b/components/cluster/command/prune.go @@ -32,6 +32,14 @@ func newPruneCmd() *cobra.Command { return cm.DestroyTombstone(clusterName, gOpt, skipConfirm) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().BoolVar(&gOpt.Force, "force", false, "Ignore errors when deleting the instance with data from the cluster") diff --git a/components/cluster/command/reload.go b/components/cluster/command/reload.go index 3c5ea4bdc1..ff2096b5b8 100644 --- a/components/cluster/command/reload.go +++ b/components/cluster/command/reload.go @@ -39,6 +39,14 @@ func newReloadCmd() *cobra.Command { return cm.Reload(clusterName, gOpt, skipRestart, skipConfirm) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().BoolVar(&gOpt.Force, "force", false, "Force reload without transferring PD leader and ignore remote error") diff --git a/components/cluster/command/restart.go b/components/cluster/command/restart.go index fb799fbadf..435a0a80da 100644 --- a/components/cluster/command/restart.go +++ b/components/cluster/command/restart.go @@ -36,6 +36,14 @@ func newRestartCmd() *cobra.Command { return cm.RestartCluster(clusterName, gOpt, skipConfirm) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only restart specified roles") diff --git a/components/cluster/command/scale_in.go b/components/cluster/command/scale_in.go index e976a89b95..441717f1a6 100644 --- a/components/cluster/command/scale_in.go +++ b/components/cluster/command/scale_in.go @@ -50,6 +50,14 @@ func newScaleInCmd() *cobra.Command { return cm.ScaleIn(clusterName, skipConfirm, gOpt, scale) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Specify the nodes (required)") diff --git a/components/cluster/command/scale_out.go b/components/cluster/command/scale_out.go index b25a54fa2c..c7e5b9d4f8 100644 --- a/components/cluster/command/scale_out.go +++ b/components/cluster/command/scale_out.go @@ -76,6 +76,16 @@ func newScaleOutCmd() *cobra.Command { gOpt, ) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + case 1: + return nil, cobra.ShellCompDirectiveDefault + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.") diff --git a/components/cluster/command/show_config.go b/components/cluster/command/show_config.go index 8af796f481..08ca0de21e 100644 --- a/components/cluster/command/show_config.go +++ b/components/cluster/command/show_config.go @@ -32,6 +32,14 @@ func newShowConfigCmd() *cobra.Command { return cm.ShowConfig(clusterName) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } return cmd diff --git a/components/cluster/command/start.go b/components/cluster/command/start.go index 884cf880b1..3863e94945 100644 --- a/components/cluster/command/start.go +++ b/components/cluster/command/start.go @@ -80,6 +80,14 @@ func newStartCmd() *cobra.Command { } return nil }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().BoolVar(&initPasswd, "init", false, "Initialize a secure root password for the database") diff --git a/components/cluster/command/stop.go b/components/cluster/command/stop.go index 6d4fbf36e9..d281a40cd0 100644 --- a/components/cluster/command/stop.go +++ b/components/cluster/command/stop.go @@ -38,6 +38,14 @@ func newStopCmd() *cobra.Command { return cm.StopCluster(clusterName, gOpt, skipConfirm, evictLeader) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only stop specified roles") diff --git a/components/cluster/command/upgrade.go b/components/cluster/command/upgrade.go index a0c829be7f..887ecc8e4e 100644 --- a/components/cluster/command/upgrade.go +++ b/components/cluster/command/upgrade.go @@ -40,6 +40,14 @@ func newUpgradeCmd() *cobra.Command { return cm.Upgrade(clusterName, version, gOpt, skipConfirm, offlineMode) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().BoolVar(&gOpt.Force, "force", false, "Force upgrade without transferring PD leader") cmd.Flags().Uint64Var(&gOpt.APITimeout, "transfer-timeout", 600, "Timeout in seconds when transferring PD and TiKV store leaders") diff --git a/components/dm/command/deploy.go b/components/dm/command/deploy.go index 2343419b94..7f7fc18110 100644 --- a/components/dm/command/deploy.go +++ b/components/dm/command/deploy.go @@ -59,6 +59,14 @@ func newDeployCmd() *cobra.Command { return cm.Deploy(clusterName, version, topoFile, opt, postDeployHook, skipConfirm, gOpt) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 2: + return nil, cobra.ShellCompDirectiveDefault + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.") diff --git a/components/dm/command/destroy.go b/components/dm/command/destroy.go index 9f0cfd9a80..1b243f3ac7 100644 --- a/components/dm/command/destroy.go +++ b/components/dm/command/destroy.go @@ -45,6 +45,14 @@ func newDestroyCmd() *cobra.Command { return cm.DestroyCluster(clusterName, gOpt, destroyOpt, skipConfirm) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringArrayVar(&destroyOpt.RetainDataNodes, "retain-node-data", nil, "Specify the nodes or hosts whose data will be retained") diff --git a/components/dm/command/disable.go b/components/dm/command/disable.go index 3251c74646..28739f2fa8 100644 --- a/components/dm/command/disable.go +++ b/components/dm/command/disable.go @@ -34,6 +34,14 @@ func newDisableCmd() *cobra.Command { return cm.EnableCluster(clusterName, gOpt, false) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only disable specified roles") diff --git a/components/dm/command/display.go b/components/dm/command/display.go index e18ac67458..492de9276c 100644 --- a/components/dm/command/display.go +++ b/components/dm/command/display.go @@ -16,8 +16,10 @@ package command import ( "errors" "fmt" + "strings" perrs "github.com/pingcap/errors" + "github.com/pingcap/tiup/pkg/cluster/manager" "github.com/pingcap/tiup/pkg/cluster/spec" "github.com/pingcap/tiup/pkg/meta" "github.com/spf13/cobra" @@ -51,6 +53,14 @@ func newDisplayCmd() *cobra.Command { return cm.Display(clusterName, gOpt) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only display specified roles") @@ -61,3 +71,14 @@ func newDisplayCmd() *cobra.Command { return cmd } + +func shellCompGetClusterName(cm *manager.Manager, toComplete string) ([]string, cobra.ShellCompDirective) { + var result []string + clusters, _ := cm.GetClusterList() + for _, c := range clusters { + if strings.HasPrefix(c.Name, toComplete) { + result = append(result, c.Name) + } + } + return result, cobra.ShellCompDirectiveNoFileComp +} diff --git a/components/dm/command/edit_config.go b/components/dm/command/edit_config.go index 05c2704f8b..e20b531128 100644 --- a/components/dm/command/edit_config.go +++ b/components/dm/command/edit_config.go @@ -32,6 +32,14 @@ func newEditConfigCmd() *cobra.Command { return cm.EditConfig(clusterName, opt, skipConfirm) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringVarP(&opt.NewTopoFile, "topology-file", "", opt.NewTopoFile, "Use provided topology file to substitute the original one instead of editing it.") diff --git a/components/dm/command/enable.go b/components/dm/command/enable.go index 0a4ec5fe78..be2bd71812 100644 --- a/components/dm/command/enable.go +++ b/components/dm/command/enable.go @@ -34,6 +34,14 @@ func newEnableCmd() *cobra.Command { return cm.EnableCluster(clusterName, gOpt, true) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only enable specified roles") diff --git a/components/dm/command/exec.go b/components/dm/command/exec.go index e800ca1707..20161fb7d5 100644 --- a/components/dm/command/exec.go +++ b/components/dm/command/exec.go @@ -33,6 +33,14 @@ func newExecCmd() *cobra.Command { return cm.Exec(clusterName, opt, gOpt) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringVar(&opt.Command, "command", "ls", "the command run on cluster host") diff --git a/components/dm/command/prune.go b/components/dm/command/prune.go index 659ef246cd..c6bb13b97d 100644 --- a/components/dm/command/prune.go +++ b/components/dm/command/prune.go @@ -44,6 +44,14 @@ func newPruneCmd() *cobra.Command { return clearOutDatedEtcdInfo(clusterName, metadata, gOpt) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } return cmd diff --git a/components/dm/command/reload.go b/components/dm/command/reload.go index ee77af7ee5..d4ba206316 100644 --- a/components/dm/command/reload.go +++ b/components/dm/command/reload.go @@ -37,6 +37,14 @@ func newReloadCmd() *cobra.Command { return cm.Reload(clusterName, gOpt, skipRestart, skipConfirm) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only reload specified roles") diff --git a/components/dm/command/restart.go b/components/dm/command/restart.go index fc9e08e2d6..4dfdbbdefa 100644 --- a/components/dm/command/restart.go +++ b/components/dm/command/restart.go @@ -30,6 +30,14 @@ func newRestartCmd() *cobra.Command { return cm.RestartCluster(clusterName, gOpt, skipConfirm) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only restart specified roles") diff --git a/components/dm/command/scale_in.go b/components/dm/command/scale_in.go index 0e43130f04..17ddbdbac5 100644 --- a/components/dm/command/scale_in.go +++ b/components/dm/command/scale_in.go @@ -53,6 +53,14 @@ func newScaleInCmd() *cobra.Command { return cm.ScaleIn(clusterName, skipConfirm, gOpt, scale) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Specify the nodes (required)") diff --git a/components/dm/command/scale_out.go b/components/dm/command/scale_out.go index b3832d2aa1..669303d762 100644 --- a/components/dm/command/scale_out.go +++ b/components/dm/command/scale_out.go @@ -42,6 +42,16 @@ func newScaleOutCmd() *cobra.Command { return cm.ScaleOut(clusterName, topoFile, postScaleOutHook, nil, opt, skipConfirm, gOpt) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + case 1: + return nil, cobra.ShellCompDirectiveDefault + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.") diff --git a/components/dm/command/start.go b/components/dm/command/start.go index 0b3bbc921d..fda235a8f6 100644 --- a/components/dm/command/start.go +++ b/components/dm/command/start.go @@ -30,6 +30,14 @@ func newStartCmd() *cobra.Command { return cm.StartCluster(clusterName, gOpt, false) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only start specified roles") diff --git a/components/dm/command/stop.go b/components/dm/command/stop.go index e8dc8be48c..950c10a9a4 100644 --- a/components/dm/command/stop.go +++ b/components/dm/command/stop.go @@ -30,6 +30,14 @@ func newStopCmd() *cobra.Command { return cm.StopCluster(clusterName, gOpt, skipConfirm, false) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only stop specified roles") diff --git a/components/dm/command/upgrade.go b/components/dm/command/upgrade.go index 9b57b8ca2c..bb6abf0ac7 100644 --- a/components/dm/command/upgrade.go +++ b/components/dm/command/upgrade.go @@ -30,6 +30,14 @@ func newUpgradeCmd() *cobra.Command { return cm.Upgrade(args[0], args[1], gOpt, skipConfirm, offlineMode) }, + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + switch len(args) { + case 0: + return shellCompGetClusterName(cm, toComplete) + default: + return nil, cobra.ShellCompDirectiveNoFileComp + } + }, } cmd.Flags().BoolVarP(&offlineMode, "offline", "", false, "Upgrade a stopped cluster")