(args []string)
| 33 | } |
| 34 | |
| 35 | func 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" { |
no test coverage detected