This repository has been archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from derekchiang/0.2
A set of changes to update etcdctl to use go-etcd 0.2
- Loading branch information
Showing
36 changed files
with
1,645 additions
and
865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
) | ||
|
||
const CompareAndSwapUsage = `usage: etcdctl [etcd flags] compareAndSwap <key> <value> [testAndSet flags] | ||
either prevvalue or previndex needs to be given | ||
special flags: --ttl to set a key with ttl | ||
--prevvalue to set the previous value | ||
--previndex to set the previous index` | ||
|
||
var ( | ||
compareAndSwapFlag = flag.NewFlagSet("testAndSet", flag.ExitOnError) | ||
compareAndSwapTtl = compareAndSwapFlag.Uint64("ttl", 0, "ttl of the key") | ||
compareAndSwapPvalue = compareAndSwapFlag.String("prevvalue", "", "previous value") | ||
compareAndSwapPindex = compareAndSwapFlag.Uint64("previndex", 0, "previous index") | ||
) | ||
|
||
func init() { | ||
// The minimum number of arguments is 3 because | ||
// there needs to be either pvalue or pindex | ||
registerCommand("compareAndSwap", CompareAndSwapUsage, 3, 6, compareAndSwap) | ||
} | ||
|
||
func compareAndSwap(args []string) error { | ||
key := args[0] | ||
value := args[1] | ||
compareAndSwapFlag.Parse(args[2:]) | ||
resp, err := client.CompareAndSwap(key, value, | ||
*compareAndSwapTtl, *compareAndSwapPvalue, *compareAndSwapPindex) | ||
if debug { | ||
fmt.Println(<-curlChan) | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
|
||
output(resp) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/coreos/go-etcd/etcd" | ||
) | ||
|
||
const GetUsage = `usage: etcdctl [etcd flags] get <key>` | ||
const GetUsage = `usage: etcdctl [etcd flags] get <key> [get flags] | ||
special flags: --sort to return the result in sorted order | ||
--consistent to send request to the leader, thereby guranteeing that any earlier writes will be seen by the read` | ||
|
||
const GetAllUsage = `usage: etcdctl [etcd flags] getAll <key> [getAll flags] | ||
special flags: --sort set to true to return the result in sorted order | ||
--consistent to send request to the leader, thereby guranteeing that any earlier writes will be seen by the read` | ||
|
||
var ( | ||
getFlag = flag.NewFlagSet("get", flag.ExitOnError) | ||
sorted = getFlag.Bool("sort", false, | ||
"Return the results in sorted order or not (default to false)") | ||
consistent = getFlag.Bool("consistent", false, | ||
"Send the request to the leader or not (default to false)") | ||
) | ||
|
||
func init() { | ||
registerCommand("get", GetUsage, 2, 2, get) | ||
registerCommand("get", GetUsage, 1, 2, get) | ||
registerCommand("getAll", GetAllUsage, 1, 2, getAll) | ||
} | ||
|
||
func get(args []string) error { | ||
key := args[1] | ||
resps, err := client.Get(key) | ||
if *consistent { | ||
client.SetConsistency(etcd.STRONG_CONSISTENCY) | ||
} else { | ||
client.SetConsistency(etcd.WEAK_CONSISTENCY) | ||
} | ||
|
||
key := args[0] | ||
getFlag.Parse(args[1:]) | ||
resp, err := client.Get(key, *sorted) | ||
if debug { | ||
fmt.Println(<-curlChan) | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
for _, resp := range resps { | ||
if resp.Value != "" { | ||
fmt.Println(resp.Value) | ||
} | ||
|
||
output(resp) | ||
|
||
return nil | ||
} | ||
|
||
func getAll(args []string) error { | ||
if *consistent { | ||
client.SetConsistency(etcd.STRONG_CONSISTENCY) | ||
} else { | ||
client.SetConsistency(etcd.WEAK_CONSISTENCY) | ||
} | ||
|
||
key := args[0] | ||
getFlag.Parse(args[1:]) | ||
resp, err := client.GetAll(key, *sorted) | ||
if debug { | ||
fmt.Println(<-curlChan) | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
output(resp) | ||
|
||
return nil | ||
} |
Oops, something went wrong.