From fab155699b29fdadc729375a3092272a993480bc Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Sun, 15 Oct 2023 14:50:31 -0400 Subject: [PATCH] Make Mount command more standard Signed-off-by: Matt Lord --- .../command/vreplication/mount/mount.go | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/go/cmd/vtctldclient/command/vreplication/mount/mount.go b/go/cmd/vtctldclient/command/vreplication/mount/mount.go index df7e801988c..7b981b755f1 100644 --- a/go/cmd/vtctldclient/command/vreplication/mount/mount.go +++ b/go/cmd/vtctldclient/command/vreplication/mount/mount.go @@ -29,8 +29,8 @@ import ( ) var ( - // mount is the base command for all actions related to the mount action. - mount = &cobra.Command{ + // base is the base command for all actions related to the mount action. + base = &cobra.Command{ Use: "Mount [command] [command-flags]", Short: "Mount is used to link an external Vitess cluster in order to migrate data from it.", DisableFlagsInUseLine: true, @@ -40,6 +40,7 @@ var ( ) var mountOptions struct { + Name string TopoType string TopoServer string TopoRoot string @@ -48,7 +49,7 @@ var mountOptions struct { var register = &cobra.Command{ Use: "register", Short: "Register an external Vitess Cluster.", - Example: `vtctldclient --server localhost:15999 mount register --topo-type etcd2 --topo-server localhost:12379 --topo-root /vitess/global ext1`, + Example: `vtctldclient --server localhost:15999 mount register --name ext1 --topo-type etcd2 --topo-server localhost:12379 --topo-root /vitess/global`, DisableFlagsInUseLine: true, Aliases: []string{"Register"}, Args: cobra.ExactArgs(1), @@ -59,10 +60,10 @@ func commandRegister(cmd *cobra.Command, args []string) error { cli.FinishedParsing(cmd) req := &vtctldatapb.MountRegisterRequest{ + Name: mountOptions.Name, TopoType: mountOptions.TopoType, TopoServer: mountOptions.TopoServer, TopoRoot: mountOptions.TopoRoot, - Name: cmd.Flags().Arg(0), } _, err := common.GetClient().MountRegister(common.GetCommandCtx(), req) if err != nil { @@ -75,7 +76,7 @@ func commandRegister(cmd *cobra.Command, args []string) error { var unregister = &cobra.Command{ Use: "unregister", Short: "Unregister a previously mounted external Vitess Cluster.", - Example: `vtctldclient --server localhost:15999 mount unregister ext1`, + Example: `vtctldclient --server localhost:15999 mount unregister --name ext1`, DisableFlagsInUseLine: true, Aliases: []string{"Unregister"}, Args: cobra.ExactArgs(1), @@ -99,7 +100,7 @@ func commandUnregister(cmd *cobra.Command, args []string) error { var show = &cobra.Command{ Use: "show", Short: "Show attributes of a previously mounted external Vitess Cluster.", - Example: `vtctldclient --server localhost:15999 Mount Show ext1`, + Example: `vtctldclient --server localhost:15999 mount show --name ext1`, DisableFlagsInUseLine: true, Aliases: []string{"Show"}, Args: cobra.ExactArgs(1), @@ -154,21 +155,27 @@ func commandList(cmd *cobra.Command, args []string) error { } func registerCommands(root *cobra.Command) { - root.AddCommand(mount) - addRegisterFlags(register) - mount.AddCommand(register) - mount.AddCommand(unregister) - mount.AddCommand(show) - mount.AddCommand(list) -} - -func addRegisterFlags(cmd *cobra.Command) { - cmd.Flags().StringVar(&mountOptions.TopoType, "topo-type", "", "Topo server implementation to use.") - cmd.Flags().StringVar(&mountOptions.TopoServer, "topo-server", "", "Topo server address.") - cmd.Flags().StringVar(&mountOptions.TopoRoot, "topo-root", "", "Topo server root path.") - cmd.MarkFlagRequired("topo-type") - cmd.MarkFlagRequired("topo-server") - cmd.MarkFlagRequired("topo-root") + root.AddCommand(base) + + register.Flags().StringVar(&mountOptions.Name, "name", "", "Name to use for the mount.") + register.MarkFlagRequired("name") + register.Flags().StringVar(&mountOptions.TopoType, "topo-type", "", "Topo server implementation to use.") + register.MarkFlagRequired("topo-type") + register.Flags().StringVar(&mountOptions.TopoServer, "topo-server", "", "Topo server address.") + register.MarkFlagRequired("topo-server") + register.Flags().StringVar(&mountOptions.TopoRoot, "topo-root", "", "Topo server root path.") + register.MarkFlagRequired("topo-root") + base.AddCommand(register) + + unregister.Flags().StringVar(&mountOptions.Name, "name", "", "Name of the mount.") + unregister.MarkFlagRequired("name") + base.AddCommand(unregister) + + show.Flags().StringVar(&mountOptions.Name, "name", "", "Name of the mount.") + show.MarkFlagRequired("name") + base.AddCommand(show) + + base.AddCommand(list) } func init() {