| 8 | ) |
| 9 | |
| 10 | func WaitForResult(stream chan v7action.PollJobEvent, ui command.UI, waitForCompletion bool) (bool, error) { |
| 11 | if stream == nil { |
| 12 | return true, nil |
| 13 | } |
| 14 | |
| 15 | if waitForCompletion { |
| 16 | fmt.Fprint(ui.Writer(), "Waiting for the operation to complete") |
| 17 | |
| 18 | defer func() { |
| 19 | ui.DisplayNewline() |
| 20 | ui.DisplayNewline() |
| 21 | }() |
| 22 | } |
| 23 | |
| 24 | for event := range stream { |
| 25 | ui.DisplayWarnings(event.Warnings) |
| 26 | if waitForCompletion { |
| 27 | fmt.Fprint(ui.Writer(), ".") |
| 28 | } |
| 29 | if event.Err != nil { |
| 30 | return false, event.Err |
| 31 | } |
| 32 | if event.State == v7action.JobPolling && !waitForCompletion { |
| 33 | return false, nil |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return true, nil |
| 38 | } |