Skip to content

Commit

Permalink
feat: provide interactive support for project deletion (#1699)
Browse files Browse the repository at this point in the history
* feat: support create project by config file

* feat: support delete project using interactive mode

* Revert "feat: support create project by config file"

This reverts commit 0ca8e84.

* chore: make delete command interactive by default

* chore: reuse project ref prompt

* fix: handle non-interactive shell

* chore: invert conditional

---------

Co-authored-by: owen <[email protected]>
Co-authored-by: Qiao Han <[email protected]>
Co-authored-by: Han Qiao <[email protected]>
  • Loading branch information
4 people authored Jan 29, 2024
1 parent f3f028c commit 036f9b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
17 changes: 9 additions & 8 deletions cmd/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ var (
RunE: func(cmd *cobra.Command, args []string) error {
ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt)
if len(projectRef) == 0 {
if err := PromptProjectRef(ctx); err != nil {
return err
}
title := "Which project do you want to link?"
cobra.CheckErr(PromptProjectRef(ctx, title))
}
fsys := afero.NewOsFs()
if err := link.PreRun(projectRef, fsys); err != nil {
Expand All @@ -59,8 +58,7 @@ func init() {
rootCmd.AddCommand(linkCmd)
}

func PromptProjectRef(ctx context.Context) error {
title := "Which project do you want to link?"
func PromptProjectRef(ctx context.Context, title string) error {
resp, err := utils.GetSupabase().GetProjectsWithResponse(ctx)
if err != nil {
return err
Expand All @@ -70,13 +68,16 @@ func PromptProjectRef(ctx context.Context) error {
}
items := make([]utils.PromptItem, len(*resp.JSON200))
for i, project := range *resp.JSON200 {
items[i] = utils.PromptItem{Summary: project.Name, Details: project.Id}
items[i] = utils.PromptItem{
Summary: project.Id,
Details: fmt.Sprintf("name: %s, org: %s, region: %s", project.Name, project.OrganizationId, project.Region),
}
}
choice, err := utils.PromptChoice(ctx, title, items)
if err != nil {
return err
}
projectRef = choice.Details
fmt.Fprintln(os.Stderr, "Selected project ref:", projectRef)
projectRef = choice.Summary
fmt.Fprintln(os.Stderr, "Selected project:", projectRef)
return nil
}
19 changes: 16 additions & 3 deletions cmd/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
"golang.org/x/term"
)

var (
Expand Down Expand Up @@ -87,12 +88,24 @@ var (
projectsDeleteCmd = &cobra.Command{
Use: "delete <ref>",
Short: "Delete a Supabase project",
Args: cobra.ExactArgs(1),
Args: cobra.MaximumNArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
return delete.PreRun(args[0])
if !term.IsTerminal(int(os.Stdin.Fd())) {
return cobra.ExactArgs(1)(cmd, args)
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
return delete.Run(cmd.Context(), args[0], afero.NewOsFs())
if len(args) == 0 {
title := "Which project do you want to delete?"
cobra.CheckErr(PromptProjectRef(cmd.Context(), title))
} else {
projectRef = args[0]
}
if err := delete.PreRun(projectRef); err != nil {
return err
}
return delete.Run(cmd.Context(), projectRef, afero.NewOsFs())
},
}
)
Expand Down

0 comments on commit 036f9b4

Please sign in to comment.