Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion internal/cmd/branch/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {
return fmt.Errorf("cannot delete branch with the output format %q (run with -force to override)", ch.Printer.Format())
}

_, err := client.DatabaseBranches.Get(ctx, &planetscale.GetDatabaseBranchRequest{
Organization: ch.Config.Organization,
Database: source,
Branch: branch,
})
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("branch %s does not exist in database %s (organization: %s)",
printer.BoldBlue(branch), printer.BoldBlue(source), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
}
}

confirmationName := fmt.Sprintf("%s/%s", source, branch)
if !printer.IsTTY {
return fmt.Errorf("cannot confirm deletion of branch %q (run with -force to override)", confirmationName)
Expand All @@ -50,7 +65,7 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {
}

var userInput string
err := survey.AskOne(prompt, &userInput)
err = survey.AskOne(prompt, &userInput)
if err != nil {
if err == terminal.InterruptErr {
os.Exit(0)
Expand Down
21 changes: 20 additions & 1 deletion internal/cmd/database/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,36 @@ func DeleteCmd(ch *cmdutil.Helper) *cobra.Command {
}

if !force {
if ch.Printer.Format() != printer.Human {
return fmt.Errorf("cannot delete database with the output format %q (run with -force to override)", ch.Printer.Format())
}

if !printer.IsTTY {
return fmt.Errorf("cannot confirm deletion of database %q (run with -force to override)", name)
}

_, err := client.Databases.Get(ctx, &planetscale.GetDatabaseRequest{
Organization: ch.Config.Organization,
Database: name,
})
if err != nil {
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return fmt.Errorf("database %s does not exist in organization %s",
printer.BoldBlue(name), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
}
}

confirmationMessage := fmt.Sprintf("%s %s %s", printer.Bold("Please type"), printer.BoldBlue(name), printer.Bold("to confirm:"))

prompt := &survey.Input{
Message: confirmationMessage,
}

var userInput string
err := survey.AskOne(prompt, &userInput)
err = survey.AskOne(prompt, &userInput)
if err != nil {
if err == terminal.InterruptErr {
os.Exit(0)
Expand Down