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 {
|
||||
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,26 +253,15 @@ func (b *Remote) costEstimation(stopCtx, cancelCtx context.Context, op *backend.
|
|||
b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n"))
|
||||
}
|
||||
|
||||
for scanner.Scan() {
|
||||
if b.CLI != nil {
|
||||
for next := true; next; {
|
||||
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 {
|
||||
if err := scanner.Err(); err != nil {
|
||||
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)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ce.Status {
|
||||
case tfe.CostEstimationFinished:
|
||||
|
|
Loading…
Reference in New Issue