github.com/supabase/cli@v1.168.1/internal/snippets/list/list.go (about) 1 package list 2 3 import ( 4 "context" 5 "fmt" 6 "strings" 7 8 "github.com/go-errors/errors" 9 "github.com/spf13/afero" 10 "github.com/supabase/cli/internal/migration/list" 11 "github.com/supabase/cli/internal/utils" 12 "github.com/supabase/cli/internal/utils/flags" 13 "github.com/supabase/cli/pkg/api" 14 ) 15 16 func Run(ctx context.Context, fsys afero.Fs) error { 17 ref, err := flags.LoadProjectRef(fsys) 18 if err != nil { 19 return err 20 } 21 resp, err := utils.GetSupabase().ListSnippetsWithResponse(ctx, &api.ListSnippetsParams{ProjectRef: &ref}) 22 if err != nil { 23 return errors.Errorf("failed to list snippets: %w", err) 24 } 25 26 if resp.JSON200 == nil { 27 return errors.New("Unexpected error listing SQL snippets: " + string(resp.Body)) 28 } 29 30 table := `|ID|NAME|VISIBILITY|OWNER|CREATED AT (UTC)|UPDATED AT (UTC)| 31 |-|-|-|-|-|-| 32 ` 33 for _, snippet := range resp.JSON200.Data { 34 table += fmt.Sprintf( 35 "|`%s`|`%s`|`%s`|`%s`|`%s`|`%s`|\n", 36 snippet.Id, 37 strings.ReplaceAll(snippet.Name, "|", "\\|"), 38 strings.ReplaceAll(string(snippet.Visibility), "|", "\\|"), 39 strings.ReplaceAll(snippet.Owner.Username, "|", "\\|"), 40 utils.FormatTimestamp(snippet.InsertedAt), 41 utils.FormatTimestamp(snippet.UpdatedAt), 42 ) 43 } 44 45 return list.RenderTable(table) 46 }