etcdctl: add lease comparison to txn command

This commit is contained in:
Anthony Romano 2017-07-28 15:42:27 -07:00
parent 52b031cfa2
commit 79660db61b
2 changed files with 6 additions and 1 deletions

View File

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

View File

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