MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / runDelete

Function runDelete

cmd/delete.go:35–138  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

33}
34
35func runDelete(args []string) error {
36 client, err := getAuthenticatedClient()
37 if err != nil {
38 return err
39 }
40
41 interactive := tui.IsInteractive() && !JSONOutput
42
43 var instanceID string
44 var selectedInstance *api.Instance
45
46 if len(args) == 0 {
47 if !interactive {
48 return usageErr("instance ID required in non-interactive mode")
49 }
50 var instances []api.Instance
51 if err := tui.RunWithBusySpinner("Fetching instances...", os.Stdout, func() error {
52 var e error
53 instances, e = client.ListInstances()
54 return e
55 }); err != nil {
56 return fmt.Errorf("failed to fetch instances: %w", err)
57 }
58
59 if len(instances) == 0 {
60 PrintWarningSimple("No instances found. Use 'tnr create' to create a Thunder Compute instance.")
61 return nil
62 }
63
64 selectedInstance, err = tui.RunDeleteInteractive(client, instances)
65 if err != nil {
66 if errors.Is(err, tui.ErrCancelled) {
67 PrintWarningSimple("User cancelled delete process")
68 return nil
69 }
70 return err
71 }
72 instanceID = selectedInstance.ID
73 } else {
74 instanceID = args[0]
75
76 var instances []api.Instance
77 if err := tui.RunWithBusySpinner("Fetching instances...", os.Stdout, func() error {
78 var e error
79 instances, e = client.ListInstances()
80 return e
81 }); err != nil {
82 return fmt.Errorf("failed to fetch instances: %w", err)
83 }
84
85 selectedInstance = findInstance(instances, instanceID)
86
87 if selectedInstance == nil {
88 return usageErr("instance '%s' not found", instanceID)
89 }
90 }
91
92 if selectedInstance.Status == "DELETING" {

Callers 1

delete.goFile · 0.85

Calls 15

IsInteractiveFunction · 0.92
RunWithBusySpinnerFunction · 0.92
RunDeleteInteractiveFunction · 0.92
RunDeleteProgressFunction · 0.92
getAuthenticatedClientFunction · 0.85
usageErrFunction · 0.85
PrintWarningSimpleFunction · 0.85
findInstanceFunction · 0.85
printJSONFunction · 0.85
cleanupSSHConfigFunction · 0.85
isUserErrorFunction · 0.85
PrintSuccessSimpleFunction · 0.85

Tested by

no test coverage detected