本文整理匯總了Golang中github.com/coreos/etcdctl/third_party/github.com/codegangsta/cli.Context.GlobalString方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.GlobalString方法的具體用法?Golang Context.GlobalString怎麽用?Golang Context.GlobalString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coreos/etcdctl/third_party/github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.GlobalString方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleContextualPrint
// Just like handlePrint but also passed the context of the command
func handleContextualPrint(c *cli.Context, fn handlerFunc, pFn contextualPrintFunc) {
resp, err := rawhandle(c, fn)
if err != nil {
handleError(ErrorFromEtcd, err)
}
if resp != nil && pFn != nil {
pFn(c, resp, c.GlobalString("output"))
}
}
示例2: handlePrint
// handlePrint wraps the command function handlers to parse global flags
// into a client and to properly format the response objects.
func handlePrint(c *cli.Context, fn handlerFunc, pFn printFunc) {
resp, err := rawhandle(c, fn)
// Print error and exit, if necessary.
if err != nil {
handleError(ErrorFromEtcd, err)
}
if resp != nil && pFn != nil {
pFn(resp, c.GlobalString("output"))
}
}
示例3: rawhandle
// rawhandle wraps the command function handlers and sets up the
// environment but performs no output formatting.
func rawhandle(c *cli.Context, fn handlerFunc) (*etcd.Response, error) {
sync := !c.GlobalBool("no-sync")
peerstr := c.GlobalString("peers")
// Use an environment variable if nothing was supplied on the
// command line
if peerstr == "" {
peerstr = os.Getenv("ETCDCTL_PEERS")
}
// If we still don't have peers, use a default
if peerstr == "" {
peerstr = "127.0.0.1:4001"
}
peers := strings.Split(peerstr, ",")
// If no sync, create http path for each peer address
if !sync {
revisedPeers := make([]string, 0)
for _, peer := range peers {
if revisedPeer, err := createHttpPath(peer); err != nil {
fmt.Fprintf(os.Stderr, "Unsupported url %v: %v\n", peer, err)
} else {
revisedPeers = append(revisedPeers, revisedPeer)
}
}
peers = revisedPeers
}
client := etcd.NewClient(peers)
if c.GlobalBool("debug") {
go dumpCURL(client)
}
// Sync cluster.
if sync {
if ok := client.SyncCluster(); !ok {
handleError(FailedToConnectToHost, errors.New("Cannot sync with the cluster using peers "+strings.Join(peers, ", ")))
}
}
if c.GlobalBool("debug") {
fmt.Fprintf(os.Stderr, "Cluster-Peers: %s\n",
strings.Join(client.GetCluster(), " "))
}
// Execute handler function.
return fn(c, client)
}