etcdctlv3: update gRPC, proto interface

release-2.3
Gyu-Ho Lee 2016-01-26 17:41:23 -08:00
parent ad15bdcb07
commit 1145414a08
2 changed files with 59 additions and 22 deletions

View File

@ -155,16 +155,36 @@ func parseRequestUnion(line string) (*pb.RequestUnion, error) {
key := []byte(parts[1])
switch parts[0] {
case "r", "range":
ru.RequestRange = &pb.RangeRequest{Key: key}
if len(parts) == 3 {
ru.RequestRange.RangeEnd = []byte(parts[2])
ru.Request = &pb.RequestUnion_RequestRange{
RequestRange: &pb.RangeRequest{
Key: key,
RangeEnd: []byte(parts[2]),
}}
} else {
ru.Request = &pb.RequestUnion_RequestRange{
RequestRange: &pb.RangeRequest{
Key: key,
}}
}
case "p", "put":
ru.RequestPut = &pb.PutRequest{Key: key, Value: []byte(parts[2])}
ru.Request = &pb.RequestUnion_RequestPut{
RequestPut: &pb.PutRequest{
Key: key,
Value: []byte(parts[2]),
}}
case "d", "deleteRange":
ru.RequestDeleteRange = &pb.DeleteRangeRequest{Key: key}
if len(parts) == 3 {
ru.RequestRange.RangeEnd = []byte(parts[2])
ru.Request = &pb.RequestUnion_RequestDeleteRange{
RequestDeleteRange: &pb.DeleteRangeRequest{
Key: key,
RangeEnd: []byte(parts[2]),
}}
} else {
ru.Request = &pb.RequestUnion_RequestDeleteRange{
RequestDeleteRange: &pb.DeleteRangeRequest{
Key: key,
}}
}
default:
return nil, fmt.Errorf("invalid txn request: %s", line)
@ -183,26 +203,34 @@ func parseCompare(line string) (*pb.Compare, error) {
c.Key = []byte(parts[0])
switch parts[1] {
case "ver", "version":
c.Target = pb.Compare_VERSION
c.Version, err = strconv.ParseInt(parts[3], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid txn compare request: %s", line)
tv, _ := c.TargetUnion.(*pb.Compare_Version)
if tv != nil {
tv.Version, err = strconv.ParseInt(parts[3], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid txn compare request: %s", line)
}
}
case "c", "create":
c.Target = pb.Compare_CREATE
c.CreateRevision, err = strconv.ParseInt(parts[3], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid txn compare request: %s", line)
tv, _ := c.TargetUnion.(*pb.Compare_CreateRevision)
if tv != nil {
tv.CreateRevision, err = strconv.ParseInt(parts[3], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid txn compare request: %s", line)
}
}
case "m", "mod":
c.Target = pb.Compare_MOD
c.ModRevision, err = strconv.ParseInt(parts[3], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid txn compare request: %s", line)
tv, _ := c.TargetUnion.(*pb.Compare_ModRevision)
if tv != nil {
tv.ModRevision, err = strconv.ParseInt(parts[3], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid txn compare request: %s", line)
}
}
case "val", "value":
c.Target = pb.Compare_VALUE
c.Value = []byte(parts[3])
tv, _ := c.TargetUnion.(*pb.Compare_Value)
if tv != nil {
tv.Value = []byte(parts[3])
}
default:
return nil, fmt.Errorf("invalid txn compare request: %s", line)
}

View File

@ -75,16 +75,25 @@ func watchCommandFunc(cmd *cobra.Command, args []string) {
var r *pb.WatchRequest
switch segs[0] {
case "watch":
r = &pb.WatchRequest{CreateRequest: &pb.WatchCreateRequest{Key: []byte(segs[1])}}
r = &pb.WatchRequest{
RequestUnion: &pb.WatchRequest_CreateRequest{
CreateRequest: &pb.WatchCreateRequest{
Key: []byte(segs[1])}}}
case "watchprefix":
r = &pb.WatchRequest{CreateRequest: &pb.WatchCreateRequest{Prefix: []byte(segs[1])}}
r = &pb.WatchRequest{
RequestUnion: &pb.WatchRequest_CreateRequest{
CreateRequest: &pb.WatchCreateRequest{
Prefix: []byte(segs[1])}}}
case "cancel":
id, perr := strconv.ParseInt(segs[1], 10, 64)
if perr != nil {
fmt.Fprintf(os.Stderr, "Invalid cancel ID (%v)\n", perr)
continue
}
r = &pb.WatchRequest{CancelRequest: &pb.WatchCancelRequest{WatchId: id}}
r = &pb.WatchRequest{
RequestUnion: &pb.WatchRequest_CancelRequest{
CancelRequest: &pb.WatchCancelRequest{
WatchId: id}}}
default:
fmt.Fprintf(os.Stderr, "Invalid watch request type: use watch, watchprefix or cancel\n")
continue