-
Notifications
You must be signed in to change notification settings - Fork 443
Expand file tree
/
Copy pathlist.go
More file actions
52 lines (47 loc) · 1.35 KB
/
list.go
File metadata and controls
52 lines (47 loc) · 1.35 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
48
49
50
51
52
package list
import (
"context"
"fmt"
"os"
"time"
"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/pkg/api"
)
func Run(ctx context.Context, projectRef string, fsys afero.Fs) error {
resp, err := utils.GetSupabase().V1ListAllFunctionsWithResponse(ctx, projectRef)
if err != nil {
return errors.Errorf("failed to list functions: %w", err)
} else if resp.JSON200 == nil {
return errors.Errorf("unexpected list functions status %d: %s", resp.StatusCode(), string(resp.Body))
}
switch utils.OutputFormat.Value {
case utils.OutputPretty:
table := `|ID|NAME|SLUG|STATUS|VERSION|UPDATED_AT (UTC)|
|-|-|-|-|-|-|
`
for _, function := range *resp.JSON200 {
t := time.UnixMilli(function.UpdatedAt)
table += fmt.Sprintf(
"|`%s`|`%s`|`%s`|`%s`|`%d`|`%s`|\n",
function.Id,
function.Name,
function.Slug,
function.Status,
function.Version,
t.UTC().Format("2006-01-02 15:04:05"),
)
}
return utils.RenderTable(table)
case utils.OutputToml:
return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, struct {
Functions []api.FunctionResponse `toml:"functions"`
}{
Functions: *resp.JSON200,
})
case utils.OutputEnv:
return errors.New(utils.ErrEnvNotSupported)
}
return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, *resp.JSON200)
}