func PrintTableReport(typ string, existing, all bool) (string, error) { log.WithField("type", typ).Debug("Table report initialized") var conts []*util.ContainerName if !all { conts = util.ErisContainersByType(typ, existing) } // "MACHINE" is placeholder header := []string{"NAME", "MACHINE", "RUNNING", "CONTAINER NAME", "PORTS"} if err := util.CheckParts(header); err != nil { log.Error(err) // err is silenced by some funcs return "", err } buf := new(bytes.Buffer) table := tablewriter.NewWriter(buf) //name set by logger instead table.SetHeader(header) if all { //get all the things parts, _ := AssembleTable(typ) for _, p := range parts { table.Append(formatLine(p)) } } else { for _, c := range conts { n, _ := PrintLineByContainerName(c.FullName, existing) if typ == "chain" { head, _ := util.GetHead() if n[0] == head { n[0] = fmt.Sprintf("** %s", n[0]) } } table.Append(n) } } // Styling table.SetBorder(false) table.SetCenterSeparator(" ") table.SetColumnSeparator(" ") table.SetRowSeparator("-") table.SetAlignment(tablewriter.ALIGN_LEFT) table.Render() return buf.String(), nil }
func formatLine(p Parts) []string { var running string if p.Running { running = "Yes" } else { running = "No" } //must match header part := []string{p.ShortName, "", running, p.FullName, p.PortsOutput} if err := util.CheckParts(part); err != nil { log.Error(err) return []string{} } return part }