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

supabase / cli / 3572813994

04 Dec 2022 06:36PM UTC coverage: 54.923% (-2.8%) from 57.76%
3572813994

Pull #648

github

Kevin Saliou
chore: remove all tabs & trailing spaces from SQL files
Pull Request #648: chore: remove all tabs & trailing spaces from SQL files

3057 of 5566 relevant lines covered (54.92%)

498.14 hits per line

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

18.56
/cmd/projects.go
1
package cmd
2

3
import (
4
        "errors"
5
        "fmt"
6
        "os"
7
        "os/signal"
8
        "strings"
9

10
        "github.com/spf13/afero"
11
        "github.com/spf13/cobra"
12
        "github.com/spf13/viper"
13
        "github.com/supabase/cli/internal/projects/create"
14
        "github.com/supabase/cli/internal/projects/list"
15
        "github.com/supabase/cli/internal/utils"
16
        "github.com/supabase/cli/pkg/api"
17
)
18

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

26
        interactive bool
27
        orgId       string
28
        dbPassword  string
29

30
        region = utils.EnumFlag{
31
                Allowed: make([]string, len(utils.RegionMap)),
32
        }
33
        plan = utils.EnumFlag{
34
                Allowed: []string{string(api.Free), string(api.Pro)},
35
                Value:   string(api.Free),
36
        }
37

38
        projectsCreateCmd = &cobra.Command{
39
                Use:     "create <project name>",
40
                Short:   "Create a project on Supabase",
41
                Args:    cobra.ExactArgs(1),
42
                Example: `supabase projects create my-project --org-id cool-green-pqdr0qc --db-password ******** --region us-east-1`,
43
                PreRun: func(cmd *cobra.Command, args []string) {
×
44
                        if !interactive {
×
45
                                cobra.CheckErr(cmd.MarkFlagRequired("org-id"))
×
46
                                cobra.CheckErr(cmd.MarkFlagRequired("db-password"))
×
47
                                cobra.CheckErr(cmd.MarkFlagRequired("region"))
×
48
                        }
×
49
                },
50
                RunE: func(cmd *cobra.Command, args []string) error {
×
51
                        name := args[0]
×
52
                        if interactive {
×
53
                                fmt.Fprintln(os.Stderr, printKeyValue("Creating project", name))
×
54
                                cobra.CheckErr(PromptCreateFlags(cmd))
×
55
                        }
×
56
                        ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt)
×
57
                        return create.Run(ctx, api.CreateProjectBody{
×
58
                                Name:           name,
×
59
                                OrganizationId: orgId,
×
60
                                DbPass:         dbPassword,
×
61
                                Region:         api.CreateProjectBodyRegion(region.Value),
×
62
                                Plan:           api.CreateProjectBodyPlan(plan.Value),
×
63
                        }, afero.NewOsFs())
×
64
                },
65
        }
66

67
        projectsListCmd = &cobra.Command{
68
                Use:   "list",
69
                Short: "List all Supabase projects",
70
                Long:  "List all Supabase projects the logged-in user can access.",
71
                RunE: func(cmd *cobra.Command, args []string) error {
×
72
                        ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt)
×
73
                        return list.Run(ctx, afero.NewOsFs())
×
74
                },
×
75
        }
76
)
77

78
func init() {
34✔
79
        // Setup enum flags
34✔
80
        i := 0
34✔
81
        for k := range utils.RegionMap {
442✔
82
                region.Allowed[i] = k
408✔
83
                i++
408✔
84
        }
408✔
85
        // Add flags to cobra command
86
        createFlags := projectsCreateCmd.Flags()
34✔
87
        createFlags.BoolVarP(&interactive, "interactive", "i", false, "Enables interactive mode.")
34✔
88
        createFlags.StringVar(&orgId, "org-id", "", "Organization ID to create the project in.")
34✔
89
        createFlags.StringVar(&dbPassword, "db-password", "", "Database password of the project.")
34✔
90
        createFlags.Var(&region, "region", "Select a region close to you for the best performance.")
34✔
91
        createFlags.Var(&plan, "plan", "Select a plan that suits your needs.")
34✔
92
        cobra.CheckErr(viper.BindPFlag("DB_PASSWORD", createFlags.Lookup("db-password")))
34✔
93
        // Add commands to root
34✔
94
        projectsCmd.AddCommand(projectsCreateCmd)
34✔
95
        projectsCmd.AddCommand(projectsListCmd)
34✔
96
        rootCmd.AddCommand(projectsCmd)
34✔
97
}
98

99
func PromptCreateFlags(cmd *cobra.Command) error {
×
100
        ctx := cmd.Context()
×
101
        if !cmd.Flags().Changed("org-id") {
×
102
                title := "Which organisation do you want to create the project for?"
×
103
                resp, err := utils.GetSupabase().GetOrganizationsWithResponse(ctx)
×
104
                if err != nil {
×
105
                        return err
×
106
                }
×
107
                if resp.JSON200 == nil {
×
108
                        return errors.New("Unexpected error retrieving organizations: " + string(resp.Body))
×
109
                }
×
110
                items := make([]utils.PromptItem, len(*resp.JSON200))
×
111
                for i, org := range *resp.JSON200 {
×
112
                        items[i] = utils.PromptItem{Summary: org.Name, Details: org.Id}
×
113
                }
×
114
                choice, err := utils.PromptChoice(ctx, title, items)
×
115
                if err != nil {
×
116
                        return err
×
117
                }
×
118
                orgId = choice.Details
×
119
        }
120
        fmt.Fprintln(os.Stderr, printKeyValue("Selected org-id", orgId))
×
121
        if !cmd.Flags().Changed("region") {
×
122
                title := "Which region do you want to host the project in?"
×
123
                items := make([]utils.PromptItem, len(utils.RegionMap))
×
124
                i := 0
×
125
                for k, v := range utils.RegionMap {
×
126
                        items[i] = utils.PromptItem{Summary: k, Details: v}
×
127
                        i++
×
128
                }
×
129
                choice, err := utils.PromptChoice(ctx, title, items)
×
130
                if err != nil {
×
131
                        return err
×
132
                }
×
133
                region.Value = choice.Summary
×
134
        }
135
        fmt.Fprintln(os.Stderr, printKeyValue("Selected region", region.Value))
×
136
        if !cmd.Flags().Changed("plan") {
×
137
                title := "Do you want a free or pro plan?"
×
138
                choice, err := utils.PromptChoice(ctx, title, []utils.PromptItem{
×
139
                        {Summary: string(api.Free)},
×
140
                        {Summary: string(api.Pro)},
×
141
                })
×
142
                if err != nil {
×
143
                        return err
×
144
                }
×
145
                plan.Value = choice.Summary
×
146
        }
147
        fmt.Fprintln(os.Stderr, printKeyValue("Selected plan", plan.Value))
×
148
        if dbPassword == "" {
×
149
                dbPassword = PromptPassword(os.Stdin)
×
150
        }
×
151
        return nil
×
152
}
153

154
func printKeyValue(key, value string) string {
×
155
        indent := 20 - len(key)
×
156
        spaces := strings.Repeat(" ", indent)
×
157
        return key + ":" + spaces + value
×
158
}
×
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