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

     1  package resources
     2  
     3  import (
     4  	structureSpec "github.com/taubyte/go-specs/structure"
     5  	"github.com/taubyte/tau-cli/cli/common"
     6  	"github.com/urfave/cli/v2"
     7  )
     8  
     9  type List[T structureSpec.Structure] struct {
    10  	LibListResources func() ([]T, error)
    11  	TableList        func([]T)
    12  }
    13  
    14  func (h *List[T]) Default() common.Command {
    15  	return common.Create(
    16  		&cli.Command{
    17  			Action: h.list,
    18  		},
    19  	)
    20  }
    21  
    22  func (h *List[T]) list(ctx *cli.Context) error {
    23  	resources, err := h.LibListResources()
    24  	if err != nil {
    25  		return err
    26  	}
    27  
    28  	h.TableList(resources)
    29  	return nil
    30  }