github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/cli/commands/resources/library/query.go (about) 1 package library 2 3 import ( 4 "github.com/taubyte/tau-cli/cli/common" 5 "github.com/taubyte/tau-cli/flags" 6 libraryLib "github.com/taubyte/tau-cli/lib/library" 7 libraryPrompts "github.com/taubyte/tau-cli/prompts/library" 8 libraryTable "github.com/taubyte/tau-cli/table/library" 9 "github.com/urfave/cli/v2" 10 ) 11 12 func (link) Query() common.Command { 13 return common.Create( 14 &cli.Command{ 15 Flags: []cli.Flag{ 16 flags.List, 17 }, 18 Action: query, 19 }, 20 ) 21 } 22 23 func (link) List() common.Command { 24 return common.Create( 25 &cli.Command{ 26 Action: list, 27 }, 28 ) 29 } 30 31 func query(ctx *cli.Context) error { 32 if ctx.Bool(flags.List.Name) { 33 return list(ctx) 34 } 35 36 library, err := libraryPrompts.GetOrSelect(ctx) 37 if err != nil { 38 return err 39 } 40 libraryTable.Query(library) 41 42 return nil 43 } 44 45 func list(ctx *cli.Context) error { 46 libraries, err := libraryLib.ListResources() 47 if err != nil { 48 return err 49 } 50 51 libraryTable.List(libraries) 52 return nil 53 }