本文整理汇总了Golang中github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra.Command.Usage方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Usage方法的具体用法?Golang Command.Usage怎么用?Golang Command.Usage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra.Command
的用法示例。
在下文中一共展示了Command.Usage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: rangeFunc
func rangeFunc(cmd *cobra.Command, args []string) {
if len(args) == 0 || len(args) > 2 {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
k := args[0]
end := ""
if len(args) == 2 {
end = args[1]
}
if rangeConsistency == "l" {
fmt.Println("bench with linearizable range")
} else if rangeConsistency == "s" {
fmt.Println("bench with serializable range")
} else {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
results = make(chan result)
requests := make(chan v3.Op, totalClients)
bar = pb.New(rangeTotal)
clients := mustCreateClients(totalClients, totalConns)
bar.Format("Bom !")
bar.Start()
for i := range clients {
wg.Add(1)
go doRange(clients[i].KV, requests)
}
pdoneC := printReport(results)
go func() {
for i := 0; i < rangeTotal; i++ {
opts := []v3.OpOption{v3.WithRange(end)}
if rangeConsistency == "s" {
opts = append(opts, v3.WithSerializable())
}
op := v3.OpGet(k, opts...)
requests <- op
}
close(requests)
}()
wg.Wait()
bar.Finish()
close(results)
<-pdoneC
}
示例2: rangeFunc
func rangeFunc(cmd *cobra.Command, args []string) {
if len(args) == 0 || len(args) > 2 {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
k := []byte(args[0])
var end []byte
if len(args) == 2 {
end = []byte(args[1])
}
if rangeConsistency == "l" {
fmt.Println("bench with linearizable range")
} else if rangeConsistency == "s" {
fmt.Println("bench with serializable range")
} else {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
results = make(chan result)
requests := make(chan etcdserverpb.RangeRequest, totalClients)
bar = pb.New(rangeTotal)
clients := mustCreateClients(totalClients, totalConns)
bar.Format("Bom !")
bar.Start()
for i := range clients {
wg.Add(1)
go doRange(clients[i].KV, requests)
}
pdoneC := printReport(results)
go func() {
for i := 0; i < rangeTotal; i++ {
r := etcdserverpb.RangeRequest{Key: k, RangeEnd: end}
if rangeConsistency == "s" {
r.Serializable = true
}
requests <- r
}
close(requests)
}()
wg.Wait()
bar.Finish()
close(results)
<-pdoneC
}
示例3: rangeFunc
func rangeFunc(cmd *cobra.Command, args []string) {
if len(args) == 0 || len(args) > 2 {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
k := []byte(args[0])
var end []byte
if len(args) == 1 {
end = []byte(args[1])
}
results = make(chan *result, rangeTotal)
requests := make(chan *etcdserverpb.RangeRequest, rangeTotal)
bar = pb.New(rangeTotal)
conns := make([]*grpc.ClientConn, totalConns)
for i := range conns {
conns[i] = mustCreateConn()
}
clients := make([]etcdserverpb.KVClient, totalClients)
for i := range clients {
clients[i] = etcdserverpb.NewKVClient(conns[i%int(totalConns)])
}
bar.Format("Bom !")
bar.Start()
for i := range clients {
wg.Add(1)
go doRange(clients[i], requests)
}
start := time.Now()
for i := 0; i < rangeTotal; i++ {
r := &etcdserverpb.RangeRequest{
Key: k,
RangeEnd: end,
}
requests <- r
}
close(requests)
wg.Wait()
bar.Finish()
printReport(rangeTotal, results, time.Now().Sub(start))
}
示例4: rangeFunc
func rangeFunc(cmd *cobra.Command, args []string) {
if len(args) == 0 || len(args) > 2 {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
k := []byte(args[0])
var end []byte
if len(args) == 1 {
end = []byte(args[1])
}
results = make(chan result)
requests := make(chan etcdserverpb.RangeRequest, totalClients)
bar = pb.New(rangeTotal)
clients := mustCreateClients(totalClients, totalConns)
bar.Format("Bom !")
bar.Start()
for i := range clients {
wg.Add(1)
go doRange(clients[i].KV, requests)
}
pdoneC := printReport(results)
go func() {
for i := 0; i < rangeTotal; i++ {
requests <- etcdserverpb.RangeRequest{
Key: k,
RangeEnd: end}
}
close(requests)
}()
wg.Wait()
bar.Finish()
close(results)
<-pdoneC
}
示例5: stmFunc
func stmFunc(cmd *cobra.Command, args []string) {
if stmKeyCount <= 0 {
fmt.Fprintf(os.Stderr, "expected positive --keys, got (%v)", stmKeyCount)
os.Exit(1)
}
if stmWritePercent < 0 || stmWritePercent > 100 {
fmt.Fprintf(os.Stderr, "expected [0, 100] --txn-wr-percent, got (%v)", stmWritePercent)
os.Exit(1)
}
if stmKeysPerTxn < 0 || stmKeysPerTxn > stmKeyCount {
fmt.Fprintf(os.Stderr, "expected --keys-per-txn between 0 and %v, got (%v)", stmKeyCount, stmKeysPerTxn)
os.Exit(1)
}
switch stmIsolation {
case "r":
mkSTM = v3sync.NewSTMRepeatable
case "l":
mkSTM = v3sync.NewSTMSerializable
default:
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
results = make(chan result)
requests := make(chan stmApply, totalClients)
bar = pb.New(stmTotal)
clients := mustCreateClients(totalClients, totalConns)
bar.Format("Bom !")
bar.Start()
for i := range clients {
wg.Add(1)
go doSTM(context.Background(), clients[i], requests)
}
pdoneC := printReport(results)
go func() {
for i := 0; i < stmTotal; i++ {
kset := make(map[string]struct{})
for len(kset) != stmKeysPerTxn {
k := make([]byte, 16)
binary.PutVarint(k, int64(rand.Intn(stmKeyCount)))
s := string(k)
kset[s] = struct{}{}
}
applyf := func(s v3sync.STM) error {
wrs := int(float32(len(kset)*stmWritePercent) / 100.0)
for k := range kset {
s.Get(k)
if wrs > 0 {
s.Put(k, string(mustRandBytes(stmValSize)))
wrs--
}
}
return nil
}
requests <- applyf
}
close(requests)
}()
wg.Wait()
bar.Finish()
close(results)
<-pdoneC
}