use scanner for reading logs
Signed-off-by: Paul Thrasher <pthrasher@hashicorp.com>
This commit is contained in:
parent
0e27a8862f
commit
151c91ffda
|
@ -240,7 +240,7 @@ func (b *Remote) costEstimation(stopCtx, cancelCtx context.Context, op *backend.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return generalError("Failed to retrieve cost estimation logs", err)
|
return generalError("Failed to retrieve cost estimation logs", err)
|
||||||
}
|
}
|
||||||
reader := bufio.NewReaderSize(logs, 64*1024)
|
scanner := bufio.NewScanner(logs)
|
||||||
|
|
||||||
// Retrieve the cost estimation to get its current status.
|
// Retrieve the cost estimation to get its current status.
|
||||||
ce, err := b.client.CostEstimations.Read(stopCtx, r.CostEstimation.ID)
|
ce, err := b.client.CostEstimations.Read(stopCtx, r.CostEstimation.ID)
|
||||||
|
@ -253,27 +253,16 @@ func (b *Remote) costEstimation(stopCtx, cancelCtx context.Context, op *backend.
|
||||||
b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n"))
|
b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.CLI != nil {
|
for scanner.Scan() {
|
||||||
for next := true; next; {
|
if b.CLI != nil {
|
||||||
var l, line []byte
|
b.CLI.Output(b.Colorize().Color(scanner.Text()))
|
||||||
|
|
||||||
for isPrefix := true; isPrefix; {
|
|
||||||
l, isPrefix, err = reader.ReadLine()
|
|
||||||
if err != nil {
|
|
||||||
if err != io.EOF {
|
|
||||||
return generalError("Failed to read logs", err)
|
|
||||||
}
|
|
||||||
next = false
|
|
||||||
}
|
|
||||||
line = append(line, l...)
|
|
||||||
}
|
|
||||||
|
|
||||||
if next || len(line) > 0 {
|
|
||||||
b.CLI.Output(b.Colorize().Color(string(line)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return generalError("Failed to read logs", err)
|
||||||
|
}
|
||||||
|
|
||||||
switch ce.Status {
|
switch ce.Status {
|
||||||
case tfe.CostEstimationFinished:
|
case tfe.CostEstimationFinished:
|
||||||
if len(r.PolicyChecks) == 0 && r.HasChanges && op.Type == backend.OperationTypeApply && b.CLI != nil {
|
if len(r.PolicyChecks) == 0 && r.HasChanges && op.Type == backend.OperationTypeApply && b.CLI != nil {
|
||||||
|
|
Loading…
Reference in New Issue