(cmd *cobra.Command, args []string)
| 45 | } |
| 46 | |
| 47 | func runModify(cmd *cobra.Command, args []string) error { |
| 48 | client, err := getAuthenticatedClient() |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | var ( |
| 54 | specs *utils.SpecStore |
| 55 | specsErr error |
| 56 | instances []api.Instance |
| 57 | instErr error |
| 58 | ) |
| 59 | if err := tui.RunWithBusySpinner("Fetching instances...", os.Stdout, func() error { |
| 60 | var wg sync.WaitGroup |
| 61 | wg.Add(2) |
| 62 | go func() { |
| 63 | defer wg.Done() |
| 64 | specs, specsErr = utils.FetchSpecStore(client) |
| 65 | }() |
| 66 | go func() { |
| 67 | defer wg.Done() |
| 68 | instances, instErr = client.ListInstances() |
| 69 | }() |
| 70 | wg.Wait() |
| 71 | if specsErr != nil { |
| 72 | return specsErr |
| 73 | } |
| 74 | if instErr != nil { |
| 75 | return fmt.Errorf("failed to fetch instances: %w", instErr) |
| 76 | } |
| 77 | return nil |
| 78 | }); err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | if len(instances) == 0 { |
| 83 | PrintWarningSimple("No instances found. Use 'tnr create' to create a Thunder Compute instance.") |
| 84 | return nil |
| 85 | } |
| 86 | |
| 87 | interactive := tui.IsInteractive() && !JSONOutput |
| 88 | |
| 89 | var selectedInstance *api.Instance |
| 90 | |
| 91 | // Determine which instance to modify |
| 92 | if len(args) == 0 { |
| 93 | if !interactive { |
| 94 | return usageErr("instance ID required in non-interactive mode") |
| 95 | } |
| 96 | // No argument - show interactive selector |
| 97 | selectedInstance, err = tui.RunModifyInstanceSelector(client, instances) |
| 98 | if err != nil { |
| 99 | if errors.Is(err, tui.ErrCancelled) { |
| 100 | PrintWarningSimple("User cancelled modification process") |
| 101 | return nil |
| 102 | } |
| 103 | return err |
| 104 | } |
no test coverage detected