本文整理汇总了Golang中github.com/coreos/etcdctl/third_party/github.com/codegangsta/cli.Context.Bool方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Bool方法的具体用法?Golang Context.Bool怎么用?Golang Context.Bool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/etcdctl/third_party/github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.Bool方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: lsCommandFunc
// lsCommandFunc executes the "ls" command.
func lsCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
key := "/"
if len(c.Args()) != 0 {
key = c.Args()[0]
}
recursive := c.Bool("recursive")
// Retrieve the value from the server.
return client.Get(key, false, recursive)
}
示例2: rPrint
// rPrint recursively prints out the nodes in the node structure.
func rPrint(c *cli.Context, n *etcd.Node) {
if n.Dir && c.Bool("p") {
fmt.Println(fmt.Sprintf("%v/", n.Key))
} else {
fmt.Println(n.Key)
}
for _, node := range n.Nodes {
rPrint(c, &node)
}
}
示例3: getCommandFunc
// getCommandFunc executes the "get" command.
func getCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
if len(c.Args()) == 0 {
return nil, errors.New("Key required")
}
key := c.Args()[0]
consistent := c.Bool("consistent")
sorted := c.Bool("sort")
// Setup consistency on the client.
if consistent {
client.SetConsistency(etcd.STRONG_CONSISTENCY)
} else {
client.SetConsistency(etcd.WEAK_CONSISTENCY)
}
// Retrieve the value from the server.
return client.Get(key, sorted, false)
}
示例4: execWatchCommandFunc
// execWatchCommandFunc executes the "exec-watch" command.
func execWatchCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, error) {
_ = io.Copy
_ = exec.Command
args := c.Args()
argsLen := len(args)
if argsLen < 2 {
return nil, errors.New("Key and command to exec required")
}
key := args[argsLen-1]
cmdArgs := args[:argsLen-1]
index := 0
if c.Int("after-index") != 0 {
index = c.Int("after-index") + 1
key = args[0]
cmdArgs = args[2:]
}
recursive := c.Bool("recursive")
if recursive != false {
key = args[0]
cmdArgs = args[2:]
}
sigch := make(chan os.Signal, 1)
signal.Notify(sigch, os.Interrupt)
stop := make(chan bool)
go func() {
<-sigch
stop <- true
os.Exit(0)
}()
receiver := make(chan *etcd.Response)
client.SetConsistency(etcd.WEAK_CONSISTENCY)
go client.Watch(key, uint64(index), recursive, receiver, stop)
for {
resp := <-receiver
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
cmd.Env = environResponse(resp, os.Environ())
stdout, err := cmd.StdoutPipe()
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
stderr, err := cmd.StderrPipe()
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
err = cmd.Start()
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
go io.Copy(os.Stdout, stdout)
go io.Copy(os.Stderr, stderr)
cmd.Wait()
}
return nil, nil
}