github.com/supabase/cli@v1.168.1/cmd/init.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/afero" 7 "github.com/spf13/cobra" 8 "github.com/spf13/viper" 9 _init "github.com/supabase/cli/internal/init" 10 "github.com/supabase/cli/internal/utils" 11 ) 12 13 var ( 14 createVscodeSettings = new(bool) 15 createIntellijSettings = new(bool) 16 initParams = utils.InitParams{} 17 18 initCmd = &cobra.Command{ 19 GroupID: groupLocalDev, 20 Use: "init", 21 Short: "Initialize a local project", 22 PersistentPreRunE: func(cmd *cobra.Command, args []string) error { 23 if !viper.IsSet("WORKDIR") { 24 // Prevents recursing to parent directory 25 viper.Set("WORKDIR", ".") 26 } 27 return cmd.Root().PersistentPreRunE(cmd, args) 28 }, 29 PreRun: func(cmd *cobra.Command, args []string) { 30 if initParams.UseOrioleDB { 31 cobra.CheckErr(cmd.MarkFlagRequired("experimental")) 32 } 33 }, 34 RunE: func(cmd *cobra.Command, args []string) error { 35 fsys := afero.NewOsFs() 36 if !cmd.Flags().Changed("with-vscode-settings") && !cmd.Flags().Changed("with-vscode-workspace") { 37 createVscodeSettings = nil 38 } 39 40 if !cmd.Flags().Changed("with-intellij-settings") { 41 createIntellijSettings = nil 42 } 43 44 return _init.Run(fsys, createVscodeSettings, createIntellijSettings, initParams) 45 }, 46 PostRun: func(cmd *cobra.Command, args []string) { 47 fmt.Println("Finished " + utils.Aqua("supabase init") + ".") 48 }, 49 } 50 ) 51 52 func init() { 53 flags := initCmd.Flags() 54 flags.BoolVar(createVscodeSettings, "with-vscode-workspace", false, "Generate VS Code workspace.") 55 cobra.CheckErr(flags.MarkHidden("with-vscode-workspace")) 56 flags.BoolVar(createVscodeSettings, "with-vscode-settings", false, "Generate VS Code settings for Deno.") 57 flags.BoolVar(createIntellijSettings, "with-intellij-settings", false, "Generate IntelliJ IDEA settings for Deno.") 58 flags.BoolVar(&initParams.UseOrioleDB, "use-orioledb", false, "Use OrioleDB storage engine for Postgres.") 59 flags.BoolVar(&initParams.Overwrite, "force", false, "Overwrite existing "+utils.ConfigPath+".") 60 rootCmd.AddCommand(initCmd) 61 }