(cmd *cobra.Command)
| 153 | } |
| 154 | |
| 155 | func runCreate(cmd *cobra.Command) error { |
| 156 | if err := resolveTemplateAlias(cmd); err != nil { |
| 157 | return err |
| 158 | } |
| 159 | |
| 160 | client, err := getAuthenticatedClient() |
| 161 | if err != nil { |
| 162 | return err |
| 163 | } |
| 164 | |
| 165 | presets := buildCreatePresets(cmd) |
| 166 | interactive := tui.IsInteractive() && !JSONOutput |
| 167 | |
| 168 | var createConfig *tui.CreateConfig |
| 169 | |
| 170 | deferSpecsToTUI := presets.IsEmpty() && interactive |
| 171 | var specs *utils.SpecStore |
| 172 | if !deferSpecsToTUI { |
| 173 | specs, err = utils.FetchSpecStore(client) |
| 174 | if err != nil { |
| 175 | return err |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | if presets.IsEmpty() { |
| 180 | if !interactive { |
| 181 | return usageErr("missing required flag(s) for non-interactive mode: %s", strings.Join(missingCreateFlags(cmd), ", ")) |
| 182 | } |
| 183 | // No flags set — full interactive TUI |
| 184 | createConfig, err = tui.RunCreateInteractive(client, specs) |
| 185 | if err != nil { |
| 186 | if errors.Is(err, tui.ErrCancelled) { |
| 187 | PrintWarningSimple("User cancelled creation process") |
| 188 | return nil |
| 189 | } |
| 190 | return err |
| 191 | } |
| 192 | } else if hasAllCreateFlags(cmd) { |
| 193 | // All flags explicitly provided → non-interactive (skip confirmation) |
| 194 | var templates []api.TemplateEntry |
| 195 | var snapshots []api.Snapshot |
| 196 | if fetchErr := tui.RunWithBusySpinner("Fetching templates and snapshots...", os.Stdout, func() error { |
| 197 | var e error |
| 198 | templates, e = client.ListTemplates() |
| 199 | if e != nil { |
| 200 | return e |
| 201 | } |
| 202 | snapshots, _ = client.ListSnapshots() |
| 203 | readySnapshots := make([]api.Snapshot, 0) |
| 204 | for _, s := range snapshots { |
| 205 | if s.Status == "READY" { |
| 206 | readySnapshots = append(readySnapshots, s) |
| 207 | } |
| 208 | } |
| 209 | snapshots = readySnapshots |
| 210 | return nil |
| 211 | }); fetchErr != nil { |
| 212 | return fmt.Errorf("failed to fetch templates: %w", fetchErr) |
no test coverage detected