-
Notifications
You must be signed in to change notification settings - Fork 445
Expand file tree
/
Copy pathlist.go
More file actions
47 lines (42 loc) · 1.37 KB
/
list.go
File metadata and controls
47 lines (42 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package list
import (
"context"
"fmt"
"os"
"strings"
"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
)
func Run(ctx context.Context, fsys afero.Fs) error {
opts := api.V1ListAllSnippetsParams{ProjectRef: &flags.ProjectRef}
resp, err := utils.GetSupabase().V1ListAllSnippetsWithResponse(ctx, &opts)
if err != nil {
return errors.Errorf("failed to list snippets: %w", err)
} else if resp.JSON200 == nil {
return errors.Errorf("unexpected list snippets status %d: %s", resp.StatusCode(), string(resp.Body))
}
switch utils.OutputFormat.Value {
case utils.OutputPretty:
table := `|ID|NAME|VISIBILITY|OWNER|CREATED AT (UTC)|UPDATED AT (UTC)|
|-|-|-|-|-|-|
`
for _, snippet := range resp.JSON200.Data {
table += fmt.Sprintf(
"|`%s`|`%s`|`%s`|`%s`|`%s`|`%s`|\n",
snippet.Id,
strings.ReplaceAll(snippet.Name, "|", "\\|"),
strings.ReplaceAll(string(snippet.Visibility), "|", "\\|"),
strings.ReplaceAll(snippet.Owner.Username, "|", "\\|"),
utils.FormatTimestamp(snippet.InsertedAt),
utils.FormatTimestamp(snippet.UpdatedAt),
)
}
return utils.RenderTable(table)
case utils.OutputEnv:
return errors.New(utils.ErrEnvNotSupported)
}
return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, *resp.JSON200)
}