本文整理匯總了Golang中github.com/hashicorp/serf/cli.Ui.Output方法的典型用法代碼示例。如果您正苦於以下問題:Golang Ui.Output方法的具體用法?Golang Ui.Output怎麽用?Golang Ui.Output使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/serf/cli.Ui
的用法示例。
在下文中一共展示了Ui.Output方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (c *MembersCommand) Run(args []string, ui cli.Ui) int {
cmdFlags := flag.NewFlagSet("members", flag.ContinueOnError)
cmdFlags.Usage = func() { ui.Output(c.Help()) }
rpcAddr := RPCAddrFlag(cmdFlags)
if err := cmdFlags.Parse(args); err != nil {
return 1
}
client, err := RPCClient(*rpcAddr)
if err != nil {
ui.Error(fmt.Sprintf("Error connecting to Serf agent: %s", err))
return 1
}
defer client.Close()
members, err := client.Members()
if err != nil {
ui.Error(fmt.Sprintf("Error retrieving members: %s", err))
return 1
}
for _, member := range members {
ui.Output(fmt.Sprintf("%s %s %s",
member.Name, member.Addr, member.Status))
}
return 0
}
示例2: Run
func (c *JoinCommand) Run(args []string, ui cli.Ui) int {
cmdFlags := flag.NewFlagSet("join", flag.ContinueOnError)
cmdFlags.Usage = func() { ui.Output(c.Help()) }
rpcAddr := RPCAddrFlag(cmdFlags)
if err := cmdFlags.Parse(args); err != nil {
return 1
}
addrs := cmdFlags.Args()
if len(addrs) == 0 {
ui.Error("At least one address to join must be specified.")
ui.Error("")
ui.Error(c.Help())
return 1
}
client, err := RPCClient(*rpcAddr)
if err != nil {
ui.Error(fmt.Sprintf("Error connecting to Serf agent: %s", err))
return 1
}
defer client.Close()
n, err := client.Join(addrs)
if err != nil {
ui.Error(fmt.Sprintf("Error joining the cluster: %s", err))
return 1
}
ui.Output(fmt.Sprintf(
"Successfully joined cluster by contacting %d nodes.", n))
return 0
}
示例3: startShutdownWatcher
func (c *Command) startShutdownWatcher(agent *Agent, ui cli.Ui) (graceful <-chan struct{}, forceful <-chan struct{}) {
g := make(chan struct{})
f := make(chan struct{})
graceful = g
forceful = f
go func() {
<-c.ShutdownCh
c.lock.Lock()
c.shuttingDown = true
c.lock.Unlock()
ui.Output("Gracefully shutting down agent...")
go func() {
if err := agent.Shutdown(); err != nil {
ui.Error(fmt.Sprintf("Error: %s", err))
return
}
close(g)
}()
select {
case <-g:
// Gracefully shut down properly
case <-c.ShutdownCh:
close(f)
}
}()
return
}
示例4: Run
func (c *ForceLeaveCommand) Run(args []string, ui cli.Ui) int {
cmdFlags := flag.NewFlagSet("join", flag.ContinueOnError)
cmdFlags.Usage = func() { ui.Output(c.Help()) }
rpcAddr := RPCAddrFlag(cmdFlags)
if err := cmdFlags.Parse(args); err != nil {
return 1
}
nodes := cmdFlags.Args()
if len(nodes) != 1 {
ui.Error("A node name must be specified to force leave.")
ui.Error("")
ui.Error(c.Help())
return 1
}
client, err := RPCClient(*rpcAddr)
if err != nil {
ui.Error(fmt.Sprintf("Error connecting to Serf agent: %s", err))
return 1
}
defer client.Close()
err = client.ForceLeave(nodes[0])
if err != nil {
ui.Error(fmt.Sprintf("Error force leaving: %s", err))
return 1
}
return 0
}
示例5: Run
func (c *MonitorCommand) Run(args []string, ui cli.Ui) int {
var logLevel string
cmdFlags := flag.NewFlagSet("monitor", flag.ContinueOnError)
cmdFlags.Usage = func() { ui.Output(c.Help()) }
cmdFlags.StringVar(&logLevel, "log-level", "INFO", "log level")
rpcAddr := RPCAddrFlag(cmdFlags)
if err := cmdFlags.Parse(args); err != nil {
return 1
}
client, err := RPCClient(*rpcAddr)
if err != nil {
ui.Error(fmt.Sprintf("Error connecting to Serf agent: %s", err))
return 1
}
defer client.Close()
eventCh := make(chan string)
doneCh := make(chan struct{})
if err := client.Monitor(logutils.LogLevel(logLevel), eventCh, doneCh); err != nil {
ui.Error(fmt.Sprintf("Error starting monitor: %s", err))
return 1
}
eventDoneCh := make(chan struct{})
go func() {
defer close(eventDoneCh)
for e := range eventCh {
ui.Info(e)
}
c.lock.Lock()
defer c.lock.Unlock()
if !c.quitting {
ui.Info("")
ui.Output("Remote side ended the monitor! This usually means that the\n" +
"remote side has exited or crashed.")
}
}()
select {
case <-eventDoneCh:
return 1
case <-c.ShutdownCh:
c.lock.Lock()
c.quitting = true
c.lock.Unlock()
}
close(doneCh)
return 0
}
示例6: Run
func (c *VersionCommand) Run(_ []string, ui cli.Ui) int {
var versionString bytes.Buffer
fmt.Fprintf(&versionString, "Serf v%s", c.Version)
if c.VersionPrerelease != "" {
fmt.Fprintf(&versionString, ".%s", c.VersionPrerelease)
if c.Revision != "" {
fmt.Fprintf(&versionString, " (%s)", c.Revision)
}
}
ui.Output(versionString.String())
return 0
}
示例7: Run
func (c *EventCommand) Run(args []string, ui cli.Ui) int {
cmdFlags := flag.NewFlagSet("event", flag.ContinueOnError)
cmdFlags.Usage = func() { ui.Output(c.Help()) }
rpcAddr := RPCAddrFlag(cmdFlags)
if err := cmdFlags.Parse(args); err != nil {
return 1
}
args = cmdFlags.Args()
if len(args) < 1 {
ui.Error("An event name must be specified.")
ui.Error("")
ui.Error(c.Help())
return 1
} else if len(args) > 2 {
ui.Error("Too many command line arguments. Only a name and payload must be specified.")
ui.Error("")
ui.Error(c.Help())
return 1
}
event := args[0]
var payload []byte
if len(args) == 2 {
payload = []byte(args[1])
}
client, err := RPCClient(*rpcAddr)
if err != nil {
ui.Error(fmt.Sprintf("Error connecting to Serf agent: %s", err))
return 1
}
defer client.Close()
if err := client.UserEvent(event, payload); err != nil {
ui.Error(fmt.Sprintf("Error sending event: %s", err))
return 1
}
return 0
}