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

supabase / cli / 11476703679

23 Oct 2024 09:06AM UTC coverage: 59.761% (-0.04%) from 59.801%
11476703679

Pull #2793

github

avallete
chore: refactor use cast.Ptr
Pull Request #2793: chore: refactor use cast ptr

4 of 6 new or added lines in 4 files covered. (66.67%)

5 existing lines in 1 file now uncovered.

6361 of 10644 relevant lines covered (59.76%)

5.98 hits per line

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

40.3
/cmd/functions.go
1
package cmd
2

3
import (
4
        "fmt"
5

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

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

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

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

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

55
        noVerifyJWT     = new(bool)
56
        useLegacyBundle bool
57
        importMapPath   string
58

59
        functionsDeployCmd = &cobra.Command{
60
                Use:   "deploy [Function name]",
61
                Short: "Deploy a Function to Supabase",
62
                Long:  "Deploy a Function to the linked Supabase project.",
63
                RunE: func(cmd *cobra.Command, args []string) error {
×
64
                        // Fallback to config if user did not set the flag.
×
65
                        if !cmd.Flags().Changed("no-verify-jwt") {
×
66
                                noVerifyJWT = nil
×
67
                        }
×
68
                        return deploy.Run(cmd.Context(), args, flags.ProjectRef, noVerifyJWT, importMapPath, afero.NewOsFs())
×
69
                },
70
        }
71

72
        functionsNewCmd = &cobra.Command{
73
                Use:   "new <Function name>",
74
                Short: "Create a new Function locally",
75
                Args:  cobra.ExactArgs(1),
76
                PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
×
77
                        cmd.GroupID = groupLocalDev
×
78
                        return cmd.Root().PersistentPreRunE(cmd, args)
×
79
                },
×
80
                RunE: func(cmd *cobra.Command, args []string) error {
×
81
                        return new_.Run(cmd.Context(), args[0], afero.NewOsFs())
×
82
                },
×
83
        }
84

85
        envFilePath string
86
        inspectBrk  bool
87
        inspectMode = utils.EnumFlag{
88
                Allowed: []string{
89
                        string(serve.InspectModeRun),
90
                        string(serve.InspectModeBrk),
91
                        string(serve.InspectModeWait),
92
                },
93
        }
94
        runtimeOption serve.RuntimeOption
95

96
        functionsServeCmd = &cobra.Command{
97
                Use:   "serve",
98
                Short: "Serve all Functions locally",
99
                PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
×
100
                        cmd.GroupID = groupLocalDev
×
101
                        return cmd.Root().PersistentPreRunE(cmd, args)
×
102
                },
×
103
                RunE: func(cmd *cobra.Command, args []string) error {
×
104
                        // Fallback to config if user did not set the flag.
×
105
                        if !cmd.Flags().Changed("no-verify-jwt") {
×
106
                                noVerifyJWT = nil
×
107
                        }
×
108

109
                        if len(inspectMode.Value) > 0 {
×
NEW
110
                                runtimeOption.InspectMode = cast.Ptr(serve.InspectMode(inspectMode.Value))
×
111
                        } else if inspectBrk {
×
NEW
112
                                runtimeOption.InspectMode = cast.Ptr(serve.InspectModeBrk)
×
113
                        }
×
114
                        if runtimeOption.InspectMode == nil && runtimeOption.InspectMain {
×
115
                                return fmt.Errorf("--inspect-main must be used together with one of these flags: [inspect inspect-mode]")
×
116
                        }
×
117

118
                        return serve.Run(cmd.Context(), envFilePath, noVerifyJWT, importMapPath, runtimeOption, afero.NewOsFs())
×
119
                },
120
        }
121
)
122

123
func init() {
1✔
124
        functionsListCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
1✔
125
        functionsDeleteCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
1✔
126
        functionsDeployCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
1✔
127
        functionsDeployCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
1✔
128
        functionsDeployCmd.Flags().BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
1✔
129
        functionsDeployCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.")
1✔
130
        cobra.CheckErr(functionsDeployCmd.Flags().MarkHidden("legacy-bundle"))
1✔
131
        functionsServeCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.")
1✔
132
        functionsServeCmd.Flags().StringVar(&envFilePath, "env-file", "", "Path to an env file to be populated to the Function environment.")
1✔
133
        functionsServeCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.")
1✔
134
        functionsServeCmd.Flags().BoolVar(&inspectBrk, "inspect", false, "Alias of --inspect-mode brk.")
1✔
135
        functionsServeCmd.Flags().Var(&inspectMode, "inspect-mode", "Activate inspector capability for debugging.")
1✔
136
        functionsServeCmd.Flags().BoolVar(&runtimeOption.InspectMain, "inspect-main", false, "Allow inspecting the main worker.")
1✔
137
        functionsServeCmd.MarkFlagsMutuallyExclusive("inspect", "inspect-mode")
1✔
138
        functionsServeCmd.Flags().Bool("all", true, "Serve all Functions.")
1✔
139
        cobra.CheckErr(functionsServeCmd.Flags().MarkHidden("all"))
1✔
140
        functionsDownloadCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
1✔
141
        functionsDownloadCmd.Flags().BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.")
1✔
142
        functionsCmd.AddCommand(functionsListCmd)
1✔
143
        functionsCmd.AddCommand(functionsDeleteCmd)
1✔
144
        functionsCmd.AddCommand(functionsDeployCmd)
1✔
145
        functionsCmd.AddCommand(functionsNewCmd)
1✔
146
        functionsCmd.AddCommand(functionsServeCmd)
1✔
147
        functionsCmd.AddCommand(functionsDownloadCmd)
1✔
148
        rootCmd.AddCommand(functionsCmd)
1✔
149
}
1✔
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