|
8 | 8 | "path/filepath" |
9 | 9 | "time" |
10 | 10 |
|
11 | | - "github.com/briandowns/spinner" |
12 | 11 | "github.com/runware/runware-cli/internal/api" |
13 | 12 | "github.com/runware/runware-cli/internal/config" |
14 | 13 | "github.com/runware/runware-cli/internal/output" |
@@ -191,37 +190,29 @@ func runVideoInference(cmd *cobra.Command, args []string) error { |
191 | 190 | } |
192 | 191 |
|
193 | 192 | // Submit the video generation task |
194 | | - var s *spinner.Spinner |
195 | | - if output.IsTTY() { |
196 | | - s = spinner.New(spinner.CharSets[14], 100*time.Millisecond, spinner.WithWriter(os.Stderr)) |
197 | | - s.Suffix = " Submitting video generation task..." |
198 | | - s.Start() |
199 | | - } |
| 193 | + s := output.NewSpinner(" Submitting video generation task...") |
| 194 | + s.Start() |
| 195 | + defer s.Stop() |
200 | 196 |
|
201 | 197 | client := api.NewClient(key, config.GetBaseURL(), flagVerbose) |
202 | | - submitResults, err := client.VideoInference(context.Background(), req) |
203 | 198 |
|
| 199 | + submitResults, err := client.VideoInference(context.Background(), req) |
204 | 200 | if err != nil { |
205 | | - if s != nil { |
206 | | - s.Stop() |
207 | | - } |
208 | 201 | if api.IsAuthError(err) { |
209 | 202 | output.Error("Authentication failed. Run 'runware auth login' to set your API key.") |
210 | 203 | return err |
211 | 204 | } |
212 | 205 | return err |
213 | 206 | } |
214 | 207 |
|
| 208 | + s.Suffix(" Generating video (this may take a few minutes)...") |
| 209 | + |
215 | 210 | // Poll for completion |
216 | 211 | taskUUID := req.TaskUUID |
217 | 212 | if len(submitResults) > 0 && submitResults[0].TaskUUID != "" { |
218 | 213 | taskUUID = submitResults[0].TaskUUID |
219 | 214 | } |
220 | 215 |
|
221 | | - if s != nil { |
222 | | - s.Suffix = " Generating video (this may take a few minutes)..." |
223 | | - } |
224 | | - |
225 | 216 | deadline := time.Now().Add(time.Duration(timeout) * time.Second) |
226 | 217 | interval := time.Duration(pollInterval) * time.Second |
227 | 218 | var results []api.VideoInferenceResult |
@@ -256,10 +247,6 @@ func runVideoInference(cmd *cobra.Command, args []string) error { |
256 | 247 | time.Sleep(interval) |
257 | 248 | } |
258 | 249 |
|
259 | | - if s != nil { |
260 | | - s.Stop() |
261 | | - } |
262 | | - |
263 | 250 | if len(results) == 0 { |
264 | 251 | output.Error("Video generation timed out or returned no results") |
265 | 252 | return fmt.Errorf("no video results after %ds", timeout) |
@@ -289,9 +276,15 @@ func runVideoInference(cmd *cobra.Command, args []string) error { |
289 | 276 | if includeCost { |
290 | 277 | headers = append(headers, tableHeaderCost) |
291 | 278 | } |
| 279 | + |
| 280 | + // Manually stop the spinner to ensure clean output of results. |
| 281 | + s.Stop() |
| 282 | + |
292 | 283 | return output.Print(format, results, headers, rows) |
293 | 284 | } |
294 | 285 |
|
| 286 | + s.Suffix(" Downloading video results...") |
| 287 | + |
295 | 288 | // Download videos |
296 | 289 | if err := os.MkdirAll(outputDir, 0755); err != nil { |
297 | 290 | return fmt.Errorf("failed to create output directory: %w", err) |
@@ -335,6 +328,9 @@ func runVideoInference(cmd *cobra.Command, args []string) error { |
335 | 328 | return fmt.Errorf("all %d video downloads failed", len(results)) |
336 | 329 | } |
337 | 330 |
|
| 331 | + // Manually stop the spinner to ensure clean output of results. |
| 332 | + s.Stop() |
| 333 | + |
338 | 334 | if err := output.Print(format, results, headers, rows); err != nil { |
339 | 335 | return err |
340 | 336 | } |
|
0 commit comments