func()

in astro/cli/astro/cmd/display.go [33:117]


func (cli *AstroCLI) printExecStatus(status <-chan string, results <-chan *astro.Result) (errors error) {
	// Print status updates to stdout as they arrive
	if status != nil {
		go func() {
			var out io.Writer

			if cli.flags.verbose {
				out = cli.stdout
			} else {
				out = ioutil.Discard
			}

			for update := range status {
				fmt.Fprintln(out, update)
			}
		}()
	}

	for result := range results {
		var resultType, changesInfo, runtimeInfo string
		var out = cli.stdout

		// If this was an error, append it to the list of errors to
		// return.
		if result.Err() != nil {
			errors = multierror.Append(errors, result.Err())
		}

		terraformResult := result.TerraformResult()

		// Check to see if this result is from a plan
		planResult, _ := terraformResult.(*terraform.PlanResult)

		if result.Err() == nil {
			resultType = aurora.Green("OK").String()
		} else {
			resultType = aurora.Red("ERROR").String()
			out = cli.stderr
		}

		// If this is a plan, show whether it has changes or not
		if planResult != nil {
			if planResult.HasChanges() {
				changesInfo = aurora.Brown(" Changes").String()
			} else {
				changesInfo = aurora.Gray(" No changes").String()
			}
		}

		if terraformResult != nil {
			runtimeInfo = terraformResult.Runtime()
			runtimeInfo = aurora.Sprintf(aurora.Gray(" (%s)"), result.TerraformResult().Runtime())
		}

		// Print status line
		fmt.Fprintf(out, "%s: %s%s%s\n",
			result.ID(),
			resultType,
			changesInfo,
			runtimeInfo,
		)

		// If this was a plan, print the plan
		if planResult != nil && planResult.HasChanges() {
			planOutput := planResult.Changes()
			if terraform.CanDisplayReadableTerraformPolicyChanges() {
				var err error
				planOutput, err = terraform.ReadableTerraformPolicyChanges(planOutput)
				if err != nil {
					fmt.Fprintf(out, "\n%s", err)
				}
			}
			fmt.Fprintf(out, "\n%s", planOutput)
		}

		// If there is a stderr, print it
		if terraformResult != nil {
			fmt.Fprintf(out, terraformResult.Stderr())
		} else if result.Err() != nil {
			fmt.Fprintln(out, result.Err())
		}
	}

	return errors
}