[cloud] run tasks output formatting

This commit is contained in:
uturunku1 2021-12-15 09:09:07 -08:00 committed by Sebastian Rivera
parent 2938ec43fa
commit 6b5da4d43c
3 changed files with 13 additions and 9 deletions

View File

@ -299,7 +299,7 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op
deltaRepr := strings.Replace(ce.DeltaMonthlyCost, "-", "", 1) deltaRepr := strings.Replace(ce.DeltaMonthlyCost, "-", "", 1)
if b.CLI != nil { 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("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))) b.CLI.Output(b.Colorize().Color(fmt.Sprintf(" $%s/mo %s$%s", ce.ProposedMonthlyCost, sign, deltaRepr)))

View File

@ -213,7 +213,7 @@ func (b *Cloud) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Ope
return nil return nil
} }
msgPrefix := "Cost estimation" msgPrefix := "Cost Estimation"
started := time.Now() started := time.Now()
updated := started updated := started
for i := 0; ; i++ { for i := 0; ; i++ {
@ -260,7 +260,7 @@ func (b *Cloud) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Ope
deltaRepr := strings.Replace(ce.DeltaMonthlyCost, "-", "", 1) deltaRepr := strings.Replace(ce.DeltaMonthlyCost, "-", "", 1)
if b.CLI != nil { 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("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))) b.CLI.Output(b.Colorize().Color(fmt.Sprintf(" $%s/mo %s$%s", ce.ProposedMonthlyCost, sign, deltaRepr)))
@ -282,12 +282,12 @@ func (b *Cloud) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Ope
elapsed = fmt.Sprintf( elapsed = fmt.Sprintf(
" (%s elapsed)", current.Sub(started).Truncate(30*time.Second)) " (%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")) b.CLI.Output(b.Colorize().Color("Waiting for cost estimate to complete..." + elapsed + "\n"))
} }
continue continue
case tfe.CostEstimateSkippedDueToTargeting: 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("Not available for this plan, because it was created with the -target option.")
b.CLI.Output("\n------------------------------------------------------------------------") b.CLI.Output("\n------------------------------------------------------------------------")
return nil return nil
@ -334,15 +334,15 @@ func (b *Cloud) checkPolicy(stopCtx, cancelCtx context.Context, op *backend.Oper
var msgPrefix string var msgPrefix string
switch pc.Scope { switch pc.Scope {
case tfe.PolicyScopeOrganization: case tfe.PolicyScopeOrganization:
msgPrefix = "Organization policy check" msgPrefix = "Organization Policy Check"
case tfe.PolicyScopeWorkspace: case tfe.PolicyScopeWorkspace:
msgPrefix = "Workspace policy check" msgPrefix = "Workspace Policy Check"
default: default:
msgPrefix = fmt.Sprintf("Unknown policy check (%s)", pc.Scope) msgPrefix = fmt.Sprintf("Unknown policy check (%s)", pc.Scope)
} }
if b.CLI != nil { 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 { if b.CLI != nil {

View File

@ -116,7 +116,11 @@ func (b *Cloud) runTasksWithTaskResults(context *IntegrationContext, output Inte
var overall string = "[green]Passed" var overall string = "[green]Passed"
if firstMandatoryTaskFailed != nil { if firstMandatoryTaskFailed != nil {
overall = "[red]Failed" 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 } else if summary.failed > 0 { // we have failures but none of them mandatory
overall = "[green]Passed with advisory failures" overall = "[green]Passed with advisory failures"
} }