github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/shared/result_waiter.go (about)

     1  package shared
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/LukasHeimann/cloudfoundrycli/v8/actor/v7action"
     7  	"github.com/LukasHeimann/cloudfoundrycli/v8/command"
     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  }