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

supabase / cli / 19699968033

26 Nov 2025 10:07AM UTC coverage: 54.995% (-0.4%) from 55.403%
19699968033

Pull #4368

github

web-flow
Merge b6a3e01eb into 6558d59e6
Pull Request #4368: feat: add deploy command to push all changes to linked project

45 of 181 new or added lines in 10 files covered. (24.86%)

15 existing lines in 2 files now uncovered.

6705 of 12192 relevant lines covered (55.0%)

6.2 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
        "os"
6

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

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

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

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

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

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

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

93
        functionsNewCmd = &cobra.Command{
94
                Use:   "new <Function name>",
95
                Short: "Create a new Function locally",
96
                Args:  cobra.ExactArgs(1),
97
                PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
×
98
                        cmd.GroupID = groupLocalDev
×
99
                        return cmd.Root().PersistentPreRunE(cmd, args)
×
100
                },
×
101
                RunE: func(cmd *cobra.Command, args []string) error {
×
102
                        return new_.Run(cmd.Context(), args[0], afero.NewOsFs())
×
103
                },
×
104
        }
105

106
        envFilePath string
107
        inspectBrk  bool
108
        inspectMode = utils.EnumFlag{
109
                Allowed: []string{
110
                        string(serve.InspectModeRun),
111
                        string(serve.InspectModeBrk),
112
                        string(serve.InspectModeWait),
113
                },
114
        }
115
        runtimeOption serve.RuntimeOption
116

117
        functionsServeCmd = &cobra.Command{
118
                Use:   "serve",
119
                Short: "Serve all Functions locally",
120
                PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
×
121
                        cmd.GroupID = groupLocalDev
×
122
                        return cmd.Root().PersistentPreRunE(cmd, args)
×
123
                },
×
124
                RunE: func(cmd *cobra.Command, args []string) error {
×
125
                        // Fallback to config if user did not set the flag.
×
126
                        if !cmd.Flags().Changed("no-verify-jwt") {
×
127
                                noVerifyJWT = nil
×
128
                        }
×
129

130
                        if len(inspectMode.Value) > 0 {
×
131
                                runtimeOption.InspectMode = cast.Ptr(serve.InspectMode(inspectMode.Value))
×
132
                        } else if inspectBrk {
×
133
                                runtimeOption.InspectMode = cast.Ptr(serve.InspectModeBrk)
×
134
                        }
×
135
                        if runtimeOption.InspectMode == nil && runtimeOption.InspectMain {
×
136
                                return fmt.Errorf("--inspect-main must be used together with one of these flags: [inspect inspect-mode]")
×
137
                        }
×
138

139
                        return serve.Run(cmd.Context(), envFilePath, noVerifyJWT, importMapPath, runtimeOption, afero.NewOsFs())
×
140
                },
141
        }
142
)
143

144
func init() {
×
145
        functionsListCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
×
146
        functionsDeleteCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
×
147
        deployFlags := functionsDeployCmd.Flags()
×
148
        deployFlags.BoolVar(&useApi, "use-api", false, "Bundle functions server-side without using Docker.")
×
149
        deployFlags.BoolVar(&useDocker, "use-docker", true, "Use Docker to bundle functions.")
×
150
        deployFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
×
151
        functionsDeployCmd.MarkFlagsMutuallyExclusive("use-api", "use-docker", "legacy-bundle")
×
152
        cobra.CheckErr(deployFlags.MarkHidden("legacy-bundle"))
×
153
        cobra.CheckErr(deployFlags.MarkHidden("use-docker"))
×
154
        deployFlags.UintVarP(&maxJobs, "jobs", "j", 1, "Maximum number of parallel jobs.")
×
155
        deployFlags.BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
×
156
        deployFlags.BoolVar(&prune, "prune", false, "Delete Functions that exist in Supabase project but not locally.")
×
NEW
157
        deployFlags.BoolVar(&functionsDryRun, "dry-run", false, "Print operations that would be performed without executing them.")
×
158
        deployFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
×
159
        deployFlags.StringVar(&importMapPath, "import-map", "", "Path to import map file.")
×
160
        functionsServeCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
×
161
        functionsServeCmd.Flags().StringVar(&envFilePath, "env-file", "", "Path to an env file to be populated to the Function environment.")
×
162
        functionsServeCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.")
×
163
        functionsServeCmd.Flags().BoolVar(&inspectBrk, "inspect", false, "Alias of --inspect-mode brk.")
×
164
        functionsServeCmd.Flags().Var(&inspectMode, "inspect-mode", "Activate inspector capability for debugging.")
×
165
        functionsServeCmd.Flags().BoolVar(&runtimeOption.InspectMain, "inspect-main", false, "Allow inspecting the main worker.")
×
166
        functionsServeCmd.MarkFlagsMutuallyExclusive("inspect", "inspect-mode")
×
167
        functionsServeCmd.Flags().Bool("all", true, "Serve all Functions.")
×
168
        cobra.CheckErr(functionsServeCmd.Flags().MarkHidden("all"))
×
169
        downloadFlags := functionsDownloadCmd.Flags()
×
170
        downloadFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
×
171
        downloadFlags.BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
×
172
        downloadFlags.BoolVar(&useApi, "use-api", false, "Unbundle functions server-side without using Docker.")
×
173
        downloadFlags.BoolVar(&useDocker, "use-docker", true, "Use Docker to unbundle functions client-side.")
×
174
        functionsDownloadCmd.MarkFlagsMutuallyExclusive("use-api", "use-docker", "legacy-bundle")
×
175
        cobra.CheckErr(downloadFlags.MarkHidden("legacy-bundle"))
×
176
        cobra.CheckErr(downloadFlags.MarkHidden("use-docker"))
×
177
        functionsCmd.AddCommand(functionsListCmd)
×
178
        functionsCmd.AddCommand(functionsDeleteCmd)
×
179
        functionsCmd.AddCommand(functionsDeployCmd)
×
180
        functionsCmd.AddCommand(functionsNewCmd)
×
181
        functionsCmd.AddCommand(functionsServeCmd)
×
182
        functionsCmd.AddCommand(functionsDownloadCmd)
×
183
        rootCmd.AddCommand(functionsCmd)
×
184
}
×
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