use scanner for reading logs

Signed-off-by: Paul Thrasher <pthrasher@hashicorp.com>
This commit is contained in:
Paul Thrasher 2019-04-25 11:17:08 -07:00
parent 0e27a8862f
commit 151c91ffda
No known key found for this signature in database
GPG Key ID: D4765F9CA4D82951
1 changed files with 8 additions and 19 deletions

View File

@ -240,7 +240,7 @@ func (b *Remote) costEstimation(stopCtx, cancelCtx context.Context, op *backend.
if err != nil {
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.
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"))
}
if b.CLI != nil {
for next := true; next; {
var l, line []byte
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)))
}
for scanner.Scan() {
if b.CLI != nil {
b.CLI.Output(b.Colorize().Color(scanner.Text()))
}
}
if err := scanner.Err(); err != nil {
return generalError("Failed to read logs", err)
}
switch ce.Status {
case tfe.CostEstimationFinished:
if len(r.PolicyChecks) == 0 && r.HasChanges && op.Type == backend.OperationTypeApply && b.CLI != nil {