Skip to content

Commit

Permalink
Make Mount command more standard
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Oct 15, 2023
1 parent 314ebcf commit fab1556
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions go/cmd/vtctldclient/command/vreplication/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -40,6 +40,7 @@ var (
)

var mountOptions struct {
Name string
TopoType string
TopoServer string
TopoRoot string
Expand All @@ -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),
Expand All @@ -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 {
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit fab1556

Please sign in to comment.