github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/cli/commands/resources/builds/build/query.go (about)

     1  package build
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/jedib0t/go-pretty/v6/table"
     7  	"github.com/taubyte/go-interfaces/services/patrick"
     8  	"github.com/taubyte/tau-cli/cli/common"
     9  	patrickClient "github.com/taubyte/tau-cli/singletons/patrick_client"
    10  	buildsTable "github.com/taubyte/tau-cli/table/builds"
    11  	"github.com/urfave/cli/v2"
    12  )
    13  
    14  func (link) Query() common.Command {
    15  	return common.Create(
    16  		&cli.Command{
    17  			Flags: []cli.Flag{
    18  				&cli.StringFlag{
    19  					Name:    "jid",
    20  					Aliases: []string{"id"},
    21  					Usage:   "job id to query",
    22  				},
    23  			},
    24  			Action: query,
    25  		},
    26  	)
    27  }
    28  
    29  func query(ctx *cli.Context) error {
    30  	patrickC, err := patrickClient.Load()
    31  	if err != nil {
    32  		return err
    33  	}
    34  
    35  	jobId := ctx.String("jid")
    36  	if len(jobId) < 1 {
    37  		return errors.New("job id not set")
    38  	}
    39  
    40  	job, err := patrickC.Job(jobId)
    41  	if err != nil {
    42  		return err
    43  	}
    44  
    45  	t, err := buildsTable.ListNoRender([]*patrick.Job{job}, true)
    46  	if err != nil {
    47  		return err
    48  	}
    49  
    50  	t.SetStyle(table.StyleLight)
    51  	t.Render()
    52  
    53  	return nil
    54  }