-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstance_delete.go
More file actions
70 lines (58 loc) · 1.72 KB
/
instance_delete.go
File metadata and controls
70 lines (58 loc) · 1.72 KB
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
64
65
66
67
68
69
70
package cmd
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"cloudamqp-cli/client"
"github.com/spf13/cobra"
)
var (
deleteInstanceID string
forceDelete bool
)
var instanceDeleteCmd = &cobra.Command{
Use: "delete --id <id>",
Short: "Delete a CloudAMQP instance",
Long: `Delete a CloudAMQP instance permanently.
WARNING: This action cannot be undone. All data will be lost.`,
Example: ` cloudamqp instance delete --id 1234
cloudamqp instance delete --id 1234 --force`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
var err error
apiKey, err = getAPIKey()
if err != nil {
return fmt.Errorf("failed to get API key: %w", err)
}
if deleteInstanceID == "" {
return fmt.Errorf("--id is required")
}
instanceID, err := strconv.Atoi(deleteInstanceID)
if err != nil {
return fmt.Errorf("invalid instance ID: %v", err)
}
if !forceDelete {
fmt.Printf("Are you sure you want to delete instance %d? This action cannot be undone. (y/N): ", instanceID)
reader := bufio.NewReader(os.Stdin)
response, err := reader.ReadString('\n')
if err != nil {
return fmt.Errorf("failed to read confirmation: %v", err)
}
response = strings.TrimSpace(strings.ToLower(response))
if response != "y" && response != "yes" {
fmt.Println("Delete operation cancelled.")
return nil
}
}
c := client.New(apiKey)
return c.DeleteInstance(instanceID)
},
}
func init() {
instanceDeleteCmd.Flags().StringVar(&deleteInstanceID, "id", "", "Instance ID (required)")
instanceDeleteCmd.Flags().BoolVar(&forceDelete, "force", false, "Skip confirmation prompt")
instanceDeleteCmd.MarkFlagRequired("id")
instanceDeleteCmd.RegisterFlagCompletionFunc("id", completeInstances)
}