github.com/supabase/cli@v1.168.1/cmd/functions.go (about) 1 package cmd 2 3 import ( 4 "github.com/spf13/afero" 5 "github.com/spf13/cobra" 6 "github.com/supabase/cli/internal/functions/delete" 7 "github.com/supabase/cli/internal/functions/deploy" 8 "github.com/supabase/cli/internal/functions/download" 9 "github.com/supabase/cli/internal/functions/list" 10 new_ "github.com/supabase/cli/internal/functions/new" 11 "github.com/supabase/cli/internal/functions/serve" 12 "github.com/supabase/cli/internal/utils/flags" 13 ) 14 15 var ( 16 functionsCmd = &cobra.Command{ 17 GroupID: groupManagementAPI, 18 Use: "functions", 19 Short: "Manage Supabase Edge functions", 20 } 21 22 functionsListCmd = &cobra.Command{ 23 Use: "list", 24 Short: "List all Functions in Supabase", 25 Long: "List all Functions in the linked Supabase project.", 26 RunE: func(cmd *cobra.Command, args []string) error { 27 return list.Run(cmd.Context(), flags.ProjectRef, afero.NewOsFs()) 28 }, 29 } 30 31 functionsDeleteCmd = &cobra.Command{ 32 Use: "delete <Function name>", 33 Short: "Delete a Function from Supabase", 34 Long: "Delete a Function from the linked Supabase project. This does NOT remove the Function locally.", 35 Args: cobra.ExactArgs(1), 36 RunE: func(cmd *cobra.Command, args []string) error { 37 return delete.Run(cmd.Context(), args[0], flags.ProjectRef, afero.NewOsFs()) 38 }, 39 } 40 41 functionsDownloadCmd = &cobra.Command{ 42 Use: "download <Function name>", 43 Short: "Download a Function from Supabase", 44 Long: "Download the source code for a Function from the linked Supabase project.", 45 Args: cobra.ExactArgs(1), 46 RunE: func(cmd *cobra.Command, args []string) error { 47 return download.Run(cmd.Context(), args[0], flags.ProjectRef, useLegacyBundle, afero.NewOsFs()) 48 }, 49 } 50 51 noVerifyJWT = new(bool) 52 useLegacyBundle bool 53 importMapPath string 54 55 functionsDeployCmd = &cobra.Command{ 56 Use: "deploy [Function name]", 57 Short: "Deploy a Function to Supabase", 58 Long: "Deploy a Function to the linked Supabase project.", 59 RunE: func(cmd *cobra.Command, args []string) error { 60 // Fallback to config if user did not set the flag. 61 if !cmd.Flags().Changed("no-verify-jwt") { 62 noVerifyJWT = nil 63 } 64 return deploy.Run(cmd.Context(), args, flags.ProjectRef, noVerifyJWT, importMapPath, afero.NewOsFs()) 65 }, 66 } 67 68 functionsNewCmd = &cobra.Command{ 69 Use: "new <Function name>", 70 Short: "Create a new Function locally", 71 Args: cobra.ExactArgs(1), 72 PersistentPreRunE: func(cmd *cobra.Command, args []string) error { 73 cmd.GroupID = groupLocalDev 74 return cmd.Root().PersistentPreRunE(cmd, args) 75 }, 76 RunE: func(cmd *cobra.Command, args []string) error { 77 return new_.Run(cmd.Context(), args[0], afero.NewOsFs()) 78 }, 79 } 80 81 envFilePath string 82 83 functionsServeCmd = &cobra.Command{ 84 Use: "serve", 85 Short: "Serve all Functions locally", 86 PersistentPreRunE: func(cmd *cobra.Command, args []string) error { 87 cmd.GroupID = groupLocalDev 88 return cmd.Root().PersistentPreRunE(cmd, args) 89 }, 90 RunE: func(cmd *cobra.Command, args []string) error { 91 // Fallback to config if user did not set the flag. 92 if !cmd.Flags().Changed("no-verify-jwt") { 93 noVerifyJWT = nil 94 } 95 return serve.Run(cmd.Context(), envFilePath, noVerifyJWT, importMapPath, afero.NewOsFs()) 96 }, 97 } 98 ) 99 100 func init() { 101 functionsListCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.") 102 functionsDeleteCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.") 103 functionsDeployCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.") 104 functionsDeployCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.") 105 functionsDeployCmd.Flags().BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.") 106 functionsDeployCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.") 107 cobra.CheckErr(functionsDeployCmd.Flags().MarkHidden("legacy-bundle")) 108 functionsServeCmd.Flags().BoolVar(noVerifyJWT, "no-verify-jwt", false, "Disable JWT verification for the Function.") 109 functionsServeCmd.Flags().StringVar(&envFilePath, "env-file", "", "Path to an env file to be populated to the Function environment.") 110 functionsServeCmd.Flags().StringVar(&importMapPath, "import-map", "", "Path to import map file.") 111 functionsServeCmd.Flags().Bool("all", true, "Serve all Functions") 112 cobra.CheckErr(functionsServeCmd.Flags().MarkHidden("all")) 113 functionsDownloadCmd.Flags().StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.") 114 functionsDownloadCmd.Flags().BoolVar(&useLegacyBundle, "legacy-bundle", false, "Use legacy bundling mechanism.") 115 functionsCmd.AddCommand(functionsListCmd) 116 functionsCmd.AddCommand(functionsDeleteCmd) 117 functionsCmd.AddCommand(functionsDeployCmd) 118 functionsCmd.AddCommand(functionsNewCmd) 119 functionsCmd.AddCommand(functionsServeCmd) 120 functionsCmd.AddCommand(functionsDownloadCmd) 121 rootCmd.AddCommand(functionsCmd) 122 }