• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / cli / 19088750195

05 Nov 2025 01:56AM UTC coverage: 54.482% (-0.2%) from 54.699%
19088750195

Pull #4381

github

web-flow
Merge b235fb22d into 8f3bf1cde
Pull Request #4381: feat: `functions download foo --use-api`

43 of 126 new or added lines in 2 files covered. (34.13%)

5 existing lines in 1 file now uncovered.

6430 of 11802 relevant lines covered (54.48%)

6.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cmd/functions.go
1
package cmd
2

3
import (
4
        "fmt"
5

6
        "github.com/go-errors/errors"
7
        "github.com/spf13/afero"
8
        "github.com/spf13/cobra"
9
        "github.com/supabase/cli/internal/functions/delete"
10
        "github.com/supabase/cli/internal/functions/deploy"
11
        "github.com/supabase/cli/internal/functions/download"
12
        "github.com/supabase/cli/internal/functions/list"
13
        new_ "github.com/supabase/cli/internal/functions/new"
14
        "github.com/supabase/cli/internal/functions/serve"
15
        "github.com/supabase/cli/internal/utils"
16
        "github.com/supabase/cli/internal/utils/flags"
17
        "github.com/supabase/cli/pkg/cast"
18
)
19

20
var (
21
        functionsCmd = &cobra.Command{
22
                GroupID: groupManagementAPI,
23
                Use:     "functions",
24
                Short:   "Manage Supabase Edge functions",
25
        }
26

27
        functionsListCmd = &cobra.Command{
28
                Use:   "list",
29
                Short: "List all Functions in Supabase",
30
                Long:  "List all Functions in the linked Supabase project.",
31
                RunE: func(cmd *cobra.Command, args []string) error {
×
32
                        return list.Run(cmd.Context(), flags.ProjectRef, afero.NewOsFs())
×
33
                },
×
34
        }
35

36
        functionsDeleteCmd = &cobra.Command{
37
                Use:   "delete <Function name>",
38
                Short: "Delete a Function from Supabase",
39
                Long:  "Delete a Function from the linked Supabase project. This does NOT remove the Function locally.",
40
                Args:  cobra.ExactArgs(1),
41
                RunE: func(cmd *cobra.Command, args []string) error {
×
42
                        return delete.Run(cmd.Context(), args[0], flags.ProjectRef, afero.NewOsFs())
×
43
                },
×
44
        }
45

46
        functionsDownloadCmd = &cobra.Command{
47
                Use:   "download <Function name>",
48
                Short: "Download a Function from Supabase",
49
                Long:  "Download the source code for a Function from the linked Supabase project.",
50
                Args:  cobra.ExactArgs(1),
51
                RunE: func(cmd *cobra.Command, args []string) error {
×
NEW
52
                        if useApi {
×
NEW
53
                                useDocker = false
×
NEW
54
                        }
×
NEW
55
                        return download.Run(cmd.Context(), args[0], flags.ProjectRef, useLegacyBundle, useDocker, afero.NewOsFs())
×
56
                },
57
        }
58

59
        useApi          bool
60
        useDocker       bool
61
        useLegacyBundle bool
62
        noVerifyJWT     = new(bool)
63
        importMapPath   string
64
        prune           bool
65

66
        functionsDeployCmd = &cobra.Command{
67
                Use:   "deploy [Function name]",
68
                Short: "Deploy a Function to Supabase",
69
                Long:  "Deploy a Function to the linked Supabase project.",
70
                RunE: func(cmd *cobra.Command, args []string) error {
×
71
                        // Fallback to config if user did not set the flag.
×
72
                        if !cmd.Flags().Changed("no-verify-jwt") {
×
73
                                noVerifyJWT = nil
×
74
                        }
×
75
                        if useApi {
×
76
                                useDocker = false
×
77
                        } else if maxJobs > 1 {
×
78
                                return errors.New("--jobs must be used together with --use-api")
×
79
                        }
×
80
                        return deploy.Run(cmd.Context(), args, useDocker, noVerifyJWT, importMapPath, maxJobs, prune, afero.NewOsFs())
×
81
                },
82
        }
83

84
        functionsNewCmd = &cobra.Command{
85
                Use:   "new <Function name>",
86
                Short: "Create a new Function locally",
87
                Args:  cobra.ExactArgs(1),
88
                PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
×
89
                        cmd.GroupID = groupLocalDev
×
90
                        return cmd.Root().PersistentPreRunE(cmd, args)
×
91
                },
×
92
                RunE: func(cmd *cobra.Command, args []string) error {
×
93
                        return new_.Run(cmd.Context(), args[0], afero.NewOsFs())
×
94
                },
×
95
        }
96

97
        envFilePath string
98
        inspectBrk  bool
99
        inspectMode = utils.EnumFlag{
100
                Allowed: []string{
101
                        string(serve.InspectModeRun),
102
                        string(serve.InspectModeBrk),
103
                        string(serve.InspectModeWait),
104
                },
105
        }
106
        runtimeOption serve.RuntimeOption
107

108
        functionsServeCmd = &cobra.Command{
109
                Use:   "serve",
110
                Short: "Serve all Functions locally",
111
                PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
×
112
                        cmd.GroupID = groupLocalDev
×
113
                        return cmd.Root().PersistentPreRunE(cmd, args)
×
114
                },
×
115
                RunE: func(cmd *cobra.Command, args []string) error {
×
116
                        // Fallback to config if user did not set the flag.
×
117
                        if !cmd.Flags().Changed("no-verify-jwt") {
×
118
                                noVerifyJWT = nil
×
119
                        }
×
120

121
                        if len(inspectMode.Value) > 0 {
×
122
                                runtimeOption.InspectMode = cast.Ptr(serve.InspectMode(inspectMode.Value))
×
123
                        } else if inspectBrk {
×
124
                                runtimeOption.InspectMode = cast.Ptr(serve.InspectModeBrk)
×
125
                        }
×
126
                        if runtimeOption.InspectMode == nil && runtimeOption.InspectMain {
×
127
                                return fmt.Errorf("--inspect-main must be used together with one of these flags: [inspect inspect-mode]")
×
128
                        }
×
129

130
                        return serve.Run(cmd.Context(), envFilePath, noVerifyJWT, importMapPath, runtimeOption, afero.NewOsFs())
×
131
                },
132
        }
133
)
134

135
func init() {
×
136
        functionsListCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
×
137
        functionsDeleteCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
×
138
        deployFlags := functionsDeployCmd.Flags()
×
139
        deployFlags.BoolVar(&useApi, "use-api", false, "Use Management API to bundle functions.")
×
140
        deployFlags.BoolVar(&useDocker, "use-docker", true, "Use Docker to bundle functions.")
×
141
        deployFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
×
142
        functionsDeployCmd.MarkFlagsMutuallyExclusive("use-api", "use-docker", "legacy-bundle")
×
143
        cobra.CheckErr(deployFlags.MarkHidden("legacy-bundle"))
×
NEW
144
        cobra.CheckErr(deployFlags.MarkHidden("use-docker"))
×
145
        deployFlags.UintVarP(&maxJobs, "jobs", "j", 1, "Maximum number of parallel jobs.")
×
146
        deployFlags.BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
×
147
        deployFlags.BoolVar(&prune, "prune", false, "Delete Functions that exist in Supabase project but not locally.")
×
148
        deployFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
×
149
        deployFlags.StringVar(&importMapPath, "import-map", "", "Path to import map file.")
×
150
        functionsServeCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
×
151
        functionsServeCmd.Flags().StringVar(&envFilePath, "env-file", "", "Path to an env file to be populated to the Function environment.")
×
152
        functionsServeCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.")
×
153
        functionsServeCmd.Flags().BoolVar(&inspectBrk, "inspect", false, "Alias of --inspect-mode brk.")
×
154
        functionsServeCmd.Flags().Var(&inspectMode, "inspect-mode", "Activate inspector capability for debugging.")
×
155
        functionsServeCmd.Flags().BoolVar(&runtimeOption.InspectMain, "inspect-main", false, "Allow inspecting the main worker.")
×
156
        functionsServeCmd.MarkFlagsMutuallyExclusive("inspect", "inspect-mode")
×
157
        functionsServeCmd.Flags().Bool("all", true, "Serve all Functions.")
×
158
        cobra.CheckErr(functionsServeCmd.Flags().MarkHidden("all"))
×
NEW
159
        downloadFlags := functionsDownloadCmd.Flags()
×
NEW
160
        downloadFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
×
NEW
161
        downloadFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
×
NEW
162
        downloadFlags.BoolVar(&useApi, "use-api", false, "Use Management API to unbundle functions server-side.")
×
NEW
163
        downloadFlags.BoolVar(&useDocker, "use-docker", true, "Use Docker to unbundle functions client-side.")
×
NEW
164
        functionsDownloadCmd.MarkFlagsMutuallyExclusive("use-api", "use-docker", "legacy-bundle")
×
NEW
165
        cobra.CheckErr(downloadFlags.MarkHidden("legacy-bundle"))
×
NEW
166
        cobra.CheckErr(downloadFlags.MarkHidden("use-docker"))
×
167
        functionsCmd.AddCommand(functionsListCmd)
×
168
        functionsCmd.AddCommand(functionsDeleteCmd)
×
169
        functionsCmd.AddCommand(functionsDeployCmd)
×
170
        functionsCmd.AddCommand(functionsNewCmd)
×
171
        functionsCmd.AddCommand(functionsServeCmd)
×
172
        functionsCmd.AddCommand(functionsDownloadCmd)
×
173
        rootCmd.AddCommand(functionsCmd)
×
174
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc