github.com/pluralsh/plural-cli@v0.9.5/pkg/executor/output.go (about)

     1  package executor
     2  
     3  import (
     4  	"io"
     5  	"strings"
     6  
     7  	"github.com/pluralsh/plural-cli/pkg/utils"
     8  )
     9  
    10  type OutputWriter struct {
    11  	delegate    io.WriteCloser
    12  	useDelegate bool
    13  	lines       []string
    14  }
    15  
    16  func (out *OutputWriter) Write(line []byte) (int, error) {
    17  	if out.useDelegate {
    18  		return out.delegate.Write(line)
    19  	}
    20  
    21  	out.lines = append(out.lines, string(line))
    22  	utils.LogInfo().Println(string(line))
    23  	if !utils.EnableDebug {
    24  		_, err := out.delegate.Write([]byte("."))
    25  		if err != nil {
    26  			return 0, err
    27  		}
    28  	}
    29  
    30  	return len(line), nil
    31  }
    32  
    33  func (out *OutputWriter) Close() error {
    34  	return out.delegate.Close()
    35  }
    36  
    37  func (out *OutputWriter) Format() string {
    38  	return strings.Join(out.lines, "")
    39  }