From d96c90b6af36648b434cfe206a2d6ef1a163efc3 Mon Sep 17 00:00:00 2001 From: Omar Ismail Date: Wed, 10 Feb 2021 11:17:05 -0500 Subject: [PATCH 1/2] Cost Estimation CLI output unnecessary --- backend/remote/backend_common.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/remote/backend_common.go b/backend/remote/backend_common.go index ad658e93c..179588f5f 100644 --- a/backend/remote/backend_common.go +++ b/backend/remote/backend_common.go @@ -250,15 +250,7 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op return nil } - if b.CLI != nil { - b.CLI.Output("\n------------------------------------------------------------------------\n") - } - msgPrefix := "Cost estimation" - if b.CLI != nil { - b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n")) - } - started := time.Now() updated := started for i := 0; ; i++ { @@ -284,6 +276,10 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op } } + if b.CLI != nil { + b.CLI.Output("\n------------------------------------------------------------------------\n") + } + switch ce.Status { case tfe.CostEstimateFinished: delta, err := strconv.ParseFloat(ce.DeltaMonthlyCost, 64) @@ -299,6 +295,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(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))) @@ -320,10 +317,12 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op 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("Waiting for cost estimate to complete..." + elapsed + "\n")) } continue case tfe.CostEstimateSkippedDueToTargeting: + b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n")) b.CLI.Output("Not available for this plan, because it was created with the -target option.") b.CLI.Output("\n------------------------------------------------------------------------") return nil From 4ac095b63ff01c1682ef0d987f3f50822717a5f6 Mon Sep 17 00:00:00 2001 From: Omar Ismail Date: Wed, 10 Feb 2021 20:47:50 -0500 Subject: [PATCH 2/2] only print horizontal rule at first attempt --- backend/remote/backend_common.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/remote/backend_common.go b/backend/remote/backend_common.go index 179588f5f..fb390acad 100644 --- a/backend/remote/backend_common.go +++ b/backend/remote/backend_common.go @@ -276,7 +276,9 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op } } - if b.CLI != nil { + // checking if i == 0 so as to avoid printing this starting horizontal-rule + // every retry, and that it only prints it on the first (i=0) attempt. + if b.CLI != nil && i == 0 { b.CLI.Output("\n------------------------------------------------------------------------\n") }