本文整理汇总了Golang中github.com/tsuru/tsuru/cmd.Table.LineSeparator方法的典型用法代码示例。如果您正苦于以下问题:Golang Table.LineSeparator方法的具体用法?Golang Table.LineSeparator怎么用?Golang Table.LineSeparator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/tsuru/cmd.Table
的用法示例。
在下文中一共展示了Table.LineSeparator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (c *keyList) Run(context *cmd.Context, client *cmd.Client) error {
url, err := cmd.GetURL("/users/keys")
if err != nil {
return err
}
request, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
resp, err := client.Do(request)
if err != nil {
return err
}
defer resp.Body.Close()
var keys map[string]string
err = json.NewDecoder(resp.Body).Decode(&keys)
if err != nil {
return err
}
var table cmd.Table
table.Headers = cmd.Row{"Name", "Content"}
table.LineSeparator = c.notrunc
for name, content := range keys {
row := []string{name, content}
if !c.notrunc && len(row[1]) > keyTruncate {
row[1] = row[1][:keyTruncate] + "..."
}
table.AddRow(cmd.Row(row))
}
table.SortByColumn(0)
context.Stdout.Write(table.Bytes())
return nil
}
示例2: renderHistoryTable
func renderHistoryTable(history []healingEvent, filter string, ctx *cmd.Context) {
fmt.Fprintln(ctx.Stdout, strings.ToUpper(filter[:1])+filter[1:]+":")
headers := cmd.Row([]string{"Start", "Finish", "Success", "Failing", "Created", "Error"})
t := cmd.Table{Headers: headers}
for i := len(history) - 1; i >= 0; i-- {
event := history[i]
if event.Action != filter+"-healing" {
continue
}
data := make([]string, 2)
if filter == "node" {
data[0] = event.FailingNode.Address
data[1] = event.CreatedNode.Address
} else {
data[0] = event.FailingContainer.ID
data[1] = event.CreatedContainer.ID
if len(data[0]) > 10 {
data[0] = data[0][:10]
}
if len(data[1]) > 10 {
data[1] = data[1][:10]
}
}
t.AddRow(cmd.Row([]string{
event.StartTime.Local().Format(time.Stamp),
event.EndTime.Local().Format(time.Stamp),
fmt.Sprintf("%t", event.Successful),
data[0],
data[1],
event.Error,
}))
}
t.LineSeparator = true
ctx.Stdout.Write(t.Bytes())
}
示例3: Run
func (c *listAutoScaleHistoryCmd) Run(ctx *cmd.Context, client *cmd.Client) error {
if c.page < 1 {
c.page = 1
}
limit := 20
skip := (c.page - 1) * limit
u, err := cmd.GetURL(fmt.Sprintf("/docker/autoscale?skip=%d&limit=%d", skip, limit))
if err != nil {
return err
}
req, err := http.NewRequest("GET", u, nil)
if err != nil {
return err
}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
var history []autoScaleEvent
if resp.StatusCode == 204 {
ctx.Stdout.Write([]byte("There is no auto scales yet.\n"))
return nil
}
err = json.NewDecoder(resp.Body).Decode(&history)
if err != nil {
return err
}
headers := cmd.Row([]string{"Start", "Finish", "Success", "Metadata", "Action", "Reason", "Error"})
t := cmd.Table{Headers: headers}
for i := range history {
event := &history[i]
t.AddRow(cmd.Row([]string{
event.StartTime.Local().Format(time.Stamp),
checkEndOfEvent(event),
fmt.Sprintf("%t", event.Successful),
event.MetadataValue,
event.Action,
event.Reason,
event.Error,
}))
}
t.LineSeparator = true
ctx.Stdout.Write(t.Bytes())
return nil
}