Skip to content

Commit

Permalink
feat: support size param when creating project
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Aug 19, 2024
1 parent 6f57e72 commit d70e833
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
18 changes: 2 additions & 16 deletions cmd/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ var (
branchRegion = utils.EnumFlag{
Allowed: flyRegions(),
}
branchSize = utils.EnumFlag{
Allowed: []string{
string(api.Micro),
string(api.Small),
string(api.Medium),
string(api.Large),
string(api.Xlarge),
string(api.N2xlarge),
string(api.N4xlarge),
string(api.N8xlarge),
string(api.N12xlarge),
string(api.N16xlarge),
},
}
persistent bool

branchCreateCmd = &cobra.Command{
Expand All @@ -62,7 +48,7 @@ var (
body.Region = &branchRegion.Value
}
if cmdFlags.Changed("size") {
body.DesiredInstanceSize = (*api.DesiredInstanceSize)(&branchSize.Value)
body.DesiredInstanceSize = (*api.DesiredInstanceSize)(&size.Value)
}
if cmdFlags.Changed("persistent") {
body.Persistent = &persistent
Expand Down Expand Up @@ -182,7 +168,7 @@ func init() {
branchFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
createFlags := branchCreateCmd.Flags()
createFlags.Var(&branchRegion, "region", "Select a region to deploy the branch database.")
createFlags.Var(&branchSize, "size", "Select a desired instance size for the branch database.")
createFlags.Var(&size, "size", "Select a desired instance size for the branch database.")
createFlags.BoolVar(&persistent, "persistent", false, "Whether to create a persistent branch.")
branchesCmd.AddCommand(branchCreateCmd)
branchesCmd.AddCommand(branchListCmd)
Expand Down
43 changes: 33 additions & 10 deletions cmd/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,26 @@ var (
dbPassword string

region = utils.EnumFlag{
Allowed: make([]string, len(utils.RegionMap)),
Allowed: awsRegions(),
}
plan = utils.EnumFlag{
Allowed: []string{string(api.V1CreateProjectBodyPlanFree), string(api.V1CreateProjectBodyPlanPro)},
Value: string(api.V1CreateProjectBodyPlanFree),
}
size = utils.EnumFlag{
Allowed: []string{
string(api.Micro),
string(api.Small),
string(api.Medium),
string(api.Large),
string(api.Xlarge),
string(api.N2xlarge),
string(api.N4xlarge),
string(api.N8xlarge),
string(api.N12xlarge),
string(api.N16xlarge),
},
}

projectsCreateCmd = &cobra.Command{
Use: "create [project name]",
Expand All @@ -55,12 +69,16 @@ var (
if len(args) > 0 {
projectName = args[0]
}
return create.Run(cmd.Context(), api.V1CreateProjectBody{
body := api.V1CreateProjectBody{
Name: projectName,
OrganizationId: orgId,
DbPass: dbPassword,
Region: api.V1CreateProjectBodyRegion(region.Value),
}, afero.NewOsFs())
}
if cmd.Flags().Changed("size") {
body.DesiredInstanceSize = (*api.DesiredInstanceSize)(&size.Value)
}
return create.Run(cmd.Context(), body, afero.NewOsFs())
},
}

Expand Down Expand Up @@ -108,13 +126,6 @@ var (
)

func init() {
// Setup enum flags
i := 0
for k := range utils.RegionMap {
region.Allowed[i] = k
i++
}
sort.Strings(region.Allowed)
// Add flags to cobra command
createFlags := projectsCreateCmd.Flags()
createFlags.BoolVarP(&interactive, "interactive", "i", true, "Enables interactive mode.")
Expand All @@ -124,6 +135,7 @@ func init() {
createFlags.Var(&region, "region", "Select a region close to you for the best performance.")
createFlags.Var(&plan, "plan", "Select a plan that suits your needs.")
cobra.CheckErr(createFlags.MarkHidden("plan"))
createFlags.Var(&size, "size", "Select a desired instance size for your project.")
cobra.CheckErr(viper.BindPFlag("DB_PASSWORD", createFlags.Lookup("db-password")))

apiKeysFlags := projectsApiKeysCmd.Flags()
Expand All @@ -136,3 +148,14 @@ func init() {
projectsCmd.AddCommand(projectsApiKeysCmd)
rootCmd.AddCommand(projectsCmd)
}

func awsRegions() []string {
result := make([]string, len(utils.RegionMap))
i := 0
for k := range utils.RegionMap {
result[i] = k
i++
}
sort.Strings(result)
return result
}

0 comments on commit d70e833

Please sign in to comment.