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

     1  package buildsTable
     2  
     3  import (
     4  	"os"
     5  	"sort"
     6  	"time"
     7  
     8  	"github.com/jedib0t/go-pretty/v6/table"
     9  	"github.com/jedib0t/go-pretty/v6/text"
    10  	"github.com/taubyte/go-interfaces/services/patrick"
    11  	authClient "github.com/taubyte/tau-cli/singletons/auth_client"
    12  )
    13  
    14  func ListNoRender(jobs []*patrick.Job, showCommit bool) (table.Writer, error) {
    15  	t := table.NewWriter()
    16  	t.SetOutputMirror(os.Stdout)
    17  	t.SetAllowedRowLength(79)
    18  	lastColumn := "Job ID"
    19  	if showCommit {
    20  		lastColumn = "Commit"
    21  	}
    22  
    23  	_jobs := jobArray(jobs)
    24  	sort.Sort(_jobs)
    25  
    26  	t.SetColumnConfigs([]table.ColumnConfig{
    27  		{Align: text.AlignCenter},
    28  		{Name: "Time"},
    29  		{Name: "Type"},
    30  		{Name: lastColumn},
    31  	})
    32  
    33  	t.AppendHeader(table.Row{"", "Time", "Type", lastColumn})
    34  
    35  	auth, err := authClient.Load()
    36  	if err != nil {
    37  		return nil, err
    38  	}
    39  
    40  	timeZone, _ := time.LoadLocation("Local")
    41  	for _, job := range _jobs {
    42  		row, err := row(auth, job, timeZone, showCommit)
    43  		if err != nil {
    44  			return nil, err
    45  		}
    46  
    47  		t.AppendRow(row)
    48  		t.AppendSeparator()
    49  	}
    50  
    51  	return t, nil
    52  }