github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/table/service/list.go (about) 1 package serviceTable 2 3 import ( 4 "os" 5 6 "github.com/jedib0t/go-pretty/v6/table" 7 structureSpec "github.com/taubyte/go-specs/structure" 8 ) 9 10 func List(services []*structureSpec.Service) { 11 t := table.NewWriter() 12 t.SetOutputMirror(os.Stdout) 13 t.SetAllowedRowLength(79) 14 15 colConfigs := make([]table.ColumnConfig, 0) 16 colConfigs = append(colConfigs, table.ColumnConfig{ 17 Name: "ID", 18 }) 19 colConfigs = append(colConfigs, table.ColumnConfig{ 20 Name: "Name", 21 }) 22 colConfigs = append(colConfigs, table.ColumnConfig{ 23 Name: "Protocol", 24 WidthMax: 40, 25 }) 26 27 t.SetColumnConfigs(colConfigs) 28 t.AppendHeader(table.Row{"ID", "Name", "Protocol"}) 29 for _, service := range services { 30 id := service.Id 31 if len(service.Id) >= 12 { 32 id = id[:6] + "..." + id[len(id)-6:] 33 } 34 35 t.AppendRow(table.Row{id, service.Name, service.Protocol}) 36 t.AppendSeparator() 37 } 38 t.SetStyle(table.StyleLight) 39 t.Render() 40 }