Skip to content

Commit

Permalink
[cloud] run tasks output formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
uturunku1 authored and brandonc committed Dec 15, 2021
1 parent 9250e9a commit 5ef0bfb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/backend/remote/backend_common.go
Expand Up @@ -299,7 +299,7 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op
deltaRepr := strings.Replace(ce.DeltaMonthlyCost, "-", "", 1)

if b.CLI != nil {
b.CLI.Output(b.Colorize().Color("[bold]" + msgPrefix + ":\n"))
b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n"))
b.CLI.Output(b.Colorize().Color(fmt.Sprintf("Resources: %d of %d estimated", ce.MatchedResourcesCount, ce.ResourcesCount)))
b.CLI.Output(b.Colorize().Color(fmt.Sprintf(" $%s/mo %s$%s", ce.ProposedMonthlyCost, sign, deltaRepr)))

Expand Down
14 changes: 7 additions & 7 deletions internal/cloud/backend_common.go
Expand Up @@ -213,7 +213,7 @@ func (b *Cloud) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Ope
return nil
}

msgPrefix := "Cost estimation"
msgPrefix := "Cost Estimation"
started := time.Now()
updated := started
for i := 0; ; i++ {
Expand Down Expand Up @@ -260,7 +260,7 @@ func (b *Cloud) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Ope
deltaRepr := strings.Replace(ce.DeltaMonthlyCost, "-", "", 1)

if b.CLI != nil {
b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n"))
b.CLI.Output(b.Colorize().Color("[bold]" + msgPrefix + ":\n"))
b.CLI.Output(b.Colorize().Color(fmt.Sprintf("Resources: %d of %d estimated", ce.MatchedResourcesCount, ce.ResourcesCount)))
b.CLI.Output(b.Colorize().Color(fmt.Sprintf(" $%s/mo %s$%s", ce.ProposedMonthlyCost, sign, deltaRepr)))

Expand All @@ -282,12 +282,12 @@ func (b *Cloud) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Ope
elapsed = fmt.Sprintf(
" (%s elapsed)", current.Sub(started).Truncate(30*time.Second))
}
b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n"))
b.CLI.Output(b.Colorize().Color("[bold]" + msgPrefix + ":\n"))
b.CLI.Output(b.Colorize().Color("Waiting for cost estimate to complete..." + elapsed + "\n"))
}
continue
case tfe.CostEstimateSkippedDueToTargeting:
b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n"))
b.CLI.Output(b.Colorize().Color("[bold]" + msgPrefix + ":\n"))
b.CLI.Output("Not available for this plan, because it was created with the -target option.")
b.CLI.Output("\n------------------------------------------------------------------------")
return nil
Expand Down Expand Up @@ -334,15 +334,15 @@ func (b *Cloud) checkPolicy(stopCtx, cancelCtx context.Context, op *backend.Oper
var msgPrefix string
switch pc.Scope {
case tfe.PolicyScopeOrganization:
msgPrefix = "Organization policy check"
msgPrefix = "Organization Policy Check"
case tfe.PolicyScopeWorkspace:
msgPrefix = "Workspace policy check"
msgPrefix = "Workspace Policy Check"
default:
msgPrefix = fmt.Sprintf("Unknown policy check (%s)", pc.Scope)
}

if b.CLI != nil {
b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n"))
b.CLI.Output(b.Colorize().Color("[bold]" + msgPrefix + ":\n"))
}

if b.CLI != nil {
Expand Down
6 changes: 5 additions & 1 deletion internal/cloud/backend_runTasks.go
Expand Up @@ -116,7 +116,11 @@ func (b *Cloud) runTasksWithTaskResults(context *IntegrationContext, output Inte
var overall string = "[green]Passed"
if firstMandatoryTaskFailed != nil {
overall = "[red]Failed"
taskErr = fmt.Errorf("the run failed because the run task, %s, is required to succeed", *firstMandatoryTaskFailed)
if summary.failedMandatory > 1 {
taskErr = fmt.Errorf("the run failed because %d mandatory tasks are required to succeed", summary.failedMandatory)
} else {
taskErr = fmt.Errorf("the run failed because the run task, %s, is required to succeed", *firstMandatoryTaskFailed)
}
} else if summary.failed > 0 { // we have failures but none of them mandatory
overall = "[green]Passed with advisory failures"
}
Expand Down

0 comments on commit 5ef0bfb

Please sign in to comment.