github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/table/smartops/list.go (about)

     1  package smartopsTable
     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(smartops []*structureSpec.SmartOp) {
    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:     "Call",
    24  		WidthMax: 40,
    25  	})
    26  
    27  	t.SetColumnConfigs(colConfigs)
    28  	t.AppendHeader(table.Row{"ID", "Name", "Call"})
    29  	for _, smartops := range smartops {
    30  		id := smartops.Id
    31  		if len(smartops.Id) >= 12 {
    32  			id = id[:6] + "..." + id[len(id)-6:]
    33  		}
    34  
    35  		t.AppendRow(table.Row{id, smartops.Name, smartops.Call})
    36  		t.AppendSeparator()
    37  	}
    38  	t.SetStyle(table.StyleLight)
    39  	t.Render()
    40  }