-
Notifications
You must be signed in to change notification settings - Fork 234
/
destroy.go
72 lines (57 loc) · 1.75 KB
/
destroy.go
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
71
72
package vector
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/gql"
"github.com/superfly/flyctl/internal/command"
extensions_core "github.com/superfly/flyctl/internal/command/extensions/core"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/flyutil"
"github.com/superfly/flyctl/internal/prompt"
"github.com/superfly/flyctl/iostreams"
)
func destroy() (cmd *cobra.Command) {
const (
long = `Permanently destroy an Upstash Vector index`
short = long
usage = "destroy [name]"
)
cmd = command.New(usage, short, long, runDestroy, command.RequireSession, command.LoadAppNameIfPresent)
cmd.Args = cobra.MaximumNArgs(1)
flag.Add(cmd,
flag.App(),
flag.AppConfig(),
extensions_core.SharedFlags,
)
return cmd
}
func runDestroy(ctx context.Context) (err error) {
io := iostreams.FromContext(ctx)
colorize := io.ColorScheme()
extension, _, err := extensions_core.Discover(ctx, gql.AddOnTypeUpstashVector)
if err != nil {
return err
}
if !flag.GetYes(ctx) {
const msg = "Destroying an Upstash Vector index is not reversible."
fmt.Fprintln(io.ErrOut, colorize.Red(msg))
switch confirmed, err := prompt.Confirmf(ctx, "Do you want to destroy the index named %s?", extension.Name); {
case err == nil:
if !confirmed {
return nil
}
case prompt.IsNonInteractive(err):
return prompt.NonInteractiveError("yes flag must be specified when not running interactively")
default:
return err
}
}
client := flyutil.ClientFromContext(ctx).GenqClient()
if _, err := gql.DeleteAddOn(ctx, client, extension.Name); err != nil {
return err
}
out := iostreams.FromContext(ctx).Out
fmt.Fprintf(out, "Your Upstash Vector index %s was destroyed\n", extension.Name)
return nil
}