diff --git a/weed/shell/command_volume_configure_replication.go b/weed/shell/command_volume_configure_replication.go index ff976c345..539bdb515 100644 --- a/weed/shell/command_volume_configure_replication.go +++ b/weed/shell/command_volume_configure_replication.go @@ -28,7 +28,7 @@ func (c *commandVolumeConfigureReplication) Name() string { func (c *commandVolumeConfigureReplication) Help() string { return `change volume replication value - This command changes a volume replication value. It should be followed by volume.fix.replication. + This command changes a volume replication value. It should be followed by "volume.fix.replication". ` } diff --git a/weed/shell/command_volume_copy.go b/weed/shell/command_volume_copy.go index cdd10863f..f9edf9431 100644 --- a/weed/shell/command_volume_copy.go +++ b/weed/shell/command_volume_copy.go @@ -1,6 +1,7 @@ package shell import ( + "flag" "fmt" "io" @@ -21,7 +22,7 @@ func (c *commandVolumeCopy) Name() string { func (c *commandVolumeCopy) Help() string { return `copy a volume from one volume server to another volume server - volume.copy + volume.copy -source -target -volumeId This command copies a volume from one volume server to another volume server. Usually you will want to unmount the volume first before copying. @@ -35,16 +36,17 @@ func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io. return } - if len(args) != 3 { - fmt.Fprintf(writer, "received args: %+v\n", args) - return fmt.Errorf("need 3 args of ") + volCopyCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) + volumeIdInt := volCopyCommand.Int("volumeId", 0, "the volume id") + sourceNodeStr := volCopyCommand.String("source", "", "the source volume server :") + targetNodeStr := volCopyCommand.String("target", "", "the target volume server :") + if err = volCopyCommand.Parse(args); err != nil { + return nil } - sourceVolumeServer, targetVolumeServer, volumeIdString := args[0], args[1], args[2] - volumeId, err := needle.NewVolumeId(volumeIdString) - if err != nil { - return fmt.Errorf("wrong volume id format %s: %v", volumeId, err) - } + sourceVolumeServer, targetVolumeServer := *sourceNodeStr, *targetNodeStr + + volumeId := needle.VolumeId(*volumeIdInt) if sourceVolumeServer == targetVolumeServer { return fmt.Errorf("source and target volume servers are the same!") diff --git a/weed/shell/command_volume_delete.go b/weed/shell/command_volume_delete.go index c5cc9e277..187caa1a4 100644 --- a/weed/shell/command_volume_delete.go +++ b/weed/shell/command_volume_delete.go @@ -1,7 +1,7 @@ package shell import ( - "fmt" + "flag" "io" "github.com/chrislusf/seaweedfs/weed/storage/needle" @@ -21,7 +21,7 @@ func (c *commandVolumeDelete) Name() string { func (c *commandVolumeDelete) Help() string { return `delete a live volume from one volume server - volume.delete + volume.delete -node -volumeId This command deletes a volume from one volume server. @@ -34,16 +34,16 @@ func (c *commandVolumeDelete) Do(args []string, commandEnv *CommandEnv, writer i return } - if len(args) != 2 { - fmt.Fprintf(writer, "received args: %+v\n", args) - return fmt.Errorf("need 2 args of ") + volDeleteCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) + volumeIdInt := volDeleteCommand.Int("volumeId", 0, "the volume id") + nodeStr := volDeleteCommand.String("node", "", "the volume server :") + if err = volDeleteCommand.Parse(args); err != nil { + return nil } - sourceVolumeServer, volumeIdString := args[0], args[1] - volumeId, err := needle.NewVolumeId(volumeIdString) - if err != nil { - return fmt.Errorf("wrong volume id format %s: %v", volumeId, err) - } + sourceVolumeServer := *nodeStr + + volumeId := needle.VolumeId(*volumeIdInt) return deleteVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer) diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go index b32ccaaab..471b24a2a 100644 --- a/weed/shell/command_volume_fix_replication.go +++ b/weed/shell/command_volume_fix_replication.go @@ -2,6 +2,7 @@ package shell import ( "context" + "flag" "fmt" "github.com/chrislusf/seaweedfs/weed/storage/needle" "io" @@ -50,11 +51,14 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv, return } - takeAction := true - if len(args) > 0 && args[0] == "-n" { - takeAction = false + volFixReplicationCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) + skipChange := volFixReplicationCommand.Bool("n", false, "skip the changes") + if err = volFixReplicationCommand.Parse(args); err != nil { + return nil } + takeAction := !*skipChange + var resp *master_pb.VolumeListResponse err = commandEnv.MasterClient.WithClient(func(client master_pb.SeaweedClient) error { resp, err = client.VolumeList(context.Background(), &master_pb.VolumeListRequest{}) diff --git a/weed/shell/command_volume_mount.go b/weed/shell/command_volume_mount.go index ded7b7e66..bd588d0b5 100644 --- a/weed/shell/command_volume_mount.go +++ b/weed/shell/command_volume_mount.go @@ -2,7 +2,7 @@ package shell import ( "context" - "fmt" + "flag" "io" "github.com/chrislusf/seaweedfs/weed/operation" @@ -25,7 +25,7 @@ func (c *commandVolumeMount) Name() string { func (c *commandVolumeMount) Help() string { return `mount a volume from one volume server - volume.mount + volume.mount -node -volumeId This command mounts a volume from one volume server. @@ -38,16 +38,16 @@ func (c *commandVolumeMount) Do(args []string, commandEnv *CommandEnv, writer io return } - if len(args) != 2 { - fmt.Fprintf(writer, "received args: %+v\n", args) - return fmt.Errorf("need 2 args of ") + volMountCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) + volumeIdInt := volMountCommand.Int("volumeId", 0, "the volume id") + nodeStr := volMountCommand.String("node", "", "the volume server :") + if err = volMountCommand.Parse(args); err != nil { + return nil } - sourceVolumeServer, volumeIdString := args[0], args[1] - volumeId, err := needle.NewVolumeId(volumeIdString) - if err != nil { - return fmt.Errorf("wrong volume id format %s: %v", volumeId, err) - } + sourceVolumeServer := *nodeStr + + volumeId := needle.VolumeId(*volumeIdInt) return mountVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer) diff --git a/weed/shell/command_volume_move.go b/weed/shell/command_volume_move.go index 37174d1d9..b136604e5 100644 --- a/weed/shell/command_volume_move.go +++ b/weed/shell/command_volume_move.go @@ -2,6 +2,7 @@ package shell import ( "context" + "flag" "fmt" "io" "log" @@ -27,7 +28,7 @@ func (c *commandVolumeMove) Name() string { func (c *commandVolumeMove) Help() string { return `move a live volume from one volume server to another volume server - volume.move + volume.move -source -target -volumeId This command move a live volume from one volume server to another volume server. Here are the steps: @@ -48,16 +49,17 @@ func (c *commandVolumeMove) Do(args []string, commandEnv *CommandEnv, writer io. return } - if len(args) != 3 { - fmt.Fprintf(writer, "received args: %+v\n", args) - return fmt.Errorf("need 3 args of ") + volMoveCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) + volumeIdInt := volMoveCommand.Int("volumeId", 0, "the volume id") + sourceNodeStr := volMoveCommand.String("source", "", "the source volume server :") + targetNodeStr := volMoveCommand.String("target", "", "the target volume server :") + if err = volMoveCommand.Parse(args); err != nil { + return nil } - sourceVolumeServer, targetVolumeServer, volumeIdString := args[0], args[1], args[2] - volumeId, err := needle.NewVolumeId(volumeIdString) - if err != nil { - return fmt.Errorf("wrong volume id format %s: %v", volumeId, err) - } + sourceVolumeServer, targetVolumeServer := *sourceNodeStr, *targetNodeStr + + volumeId := needle.VolumeId(*volumeIdInt) if sourceVolumeServer == targetVolumeServer { return fmt.Errorf("source and target volume servers are the same!") diff --git a/weed/shell/command_volume_unmount.go b/weed/shell/command_volume_unmount.go index 7596bb4c8..f7e5a501b 100644 --- a/weed/shell/command_volume_unmount.go +++ b/weed/shell/command_volume_unmount.go @@ -2,7 +2,7 @@ package shell import ( "context" - "fmt" + "flag" "io" "github.com/chrislusf/seaweedfs/weed/operation" @@ -25,7 +25,7 @@ func (c *commandVolumeUnmount) Name() string { func (c *commandVolumeUnmount) Help() string { return `unmount a volume from one volume server - volume.unmount + volume.unmount -node -volumeId This command unmounts a volume from one volume server. @@ -38,16 +38,16 @@ func (c *commandVolumeUnmount) Do(args []string, commandEnv *CommandEnv, writer return } - if len(args) != 2 { - fmt.Fprintf(writer, "received args: %+v\n", args) - return fmt.Errorf("need 2 args of ") + volUnmountCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) + volumeIdInt := volUnmountCommand.Int("volumeId", 0, "the volume id") + nodeStr := volUnmountCommand.String("node", "", "the volume server :") + if err = volUnmountCommand.Parse(args); err != nil { + return nil } - sourceVolumeServer, volumeIdString := args[0], args[1] - volumeId, err := needle.NewVolumeId(volumeIdString) - if err != nil { - return fmt.Errorf("wrong volume id format %s: %v", volumeId, err) - } + sourceVolumeServer := *nodeStr + + volumeId := needle.VolumeId(*volumeIdInt) return unmountVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer)