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