浏览代码

etcdctl: add lease comparison to txn command

Anthony Romano 8 年之前
父节点
当前提交
79660db61b
共有 2 个文件被更改,包括 6 次插入1 次删除
  1. 3 1
      etcdctl/README.md
  2. 3 0
      etcdctl/ctlv3/command/txn_command.go

+ 3 - 1
etcdctl/README.md

@@ -223,12 +223,13 @@ RPC: Txn
 #### Input Format
 #### Input Format
 ```ebnf
 ```ebnf
 <Txn> ::= <CMP>* "\n" <THEN> "\n" <ELSE> "\n"
 <Txn> ::= <CMP>* "\n" <THEN> "\n" <ELSE> "\n"
-<CMP> ::= (<CMPCREATE>|<CMPMOD>|<CMPVAL>|<CMPVER>) "\n"
+<CMP> ::= (<CMPCREATE>|<CMPMOD>|<CMPVAL>|<CMPVER>|<CMPLEASE>) "\n"
 <CMPOP> ::= "<" | "=" | ">"
 <CMPOP> ::= "<" | "=" | ">"
 <CMPCREATE> := ("c"|"create")"("<KEY>")" <REVISION>
 <CMPCREATE> := ("c"|"create")"("<KEY>")" <REVISION>
 <CMPMOD> ::= ("m"|"mod")"("<KEY>")" <CMPOP> <REVISION>
 <CMPMOD> ::= ("m"|"mod")"("<KEY>")" <CMPOP> <REVISION>
 <CMPVAL> ::= ("val"|"value")"("<KEY>")" <CMPOP> <VALUE>
 <CMPVAL> ::= ("val"|"value")"("<KEY>")" <CMPOP> <VALUE>
 <CMPVER> ::= ("ver"|"version")"("<KEY>")" <CMPOP> <VERSION>
 <CMPVER> ::= ("ver"|"version")"("<KEY>")" <CMPOP> <VERSION>
+<CMPLEASE> ::= "lease("<KEY>")" <CMPOP> <LEASE>
 <THEN> ::= <OP>*
 <THEN> ::= <OP>*
 <ELSE> ::= <OP>*
 <ELSE> ::= <OP>*
 <OP> ::= ((see put, get, del etcdctl command syntax)) "\n"
 <OP> ::= ((see put, get, del etcdctl command syntax)) "\n"
@@ -236,6 +237,7 @@ RPC: Txn
 <VALUE> ::= (%q formatted string)
 <VALUE> ::= (%q formatted string)
 <REVISION> ::= "\""[0-9]+"\""
 <REVISION> ::= "\""[0-9]+"\""
 <VERSION> ::= "\""[0-9]+"\""
 <VERSION> ::= "\""[0-9]+"\""
+<LEASE> ::= "\""[0-9]+\""
 ```
 ```
 
 
 #### Output
 #### Output

+ 3 - 0
etcdctl/ctlv3/command/txn_command.go

@@ -22,6 +22,7 @@ import (
 	"strings"
 	"strings"
 
 
 	"github.com/coreos/etcd/clientv3"
 	"github.com/coreos/etcd/clientv3"
+	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
 	"github.com/spf13/cobra"
 	"github.com/spf13/cobra"
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
 )
 )
@@ -193,6 +194,8 @@ func parseCompare(line string) (*clientv3.Cmp, error) {
 		}
 		}
 	case "val", "value":
 	case "val", "value":
 		cmp = clientv3.Compare(clientv3.Value(key), op, val)
 		cmp = clientv3.Compare(clientv3.Value(key), op, val)
+	case "lease":
+		cmp = clientv3.Compare(clientv3.Cmp{Target: pb.Compare_LEASE}, op, val)
 	default:
 	default:
 		return nil, fmt.Errorf("malformed comparison: %s (unknown target %s)", line, target)
 		return nil, fmt.Errorf("malformed comparison: %s (unknown target %s)", line, target)
 	}
 	}