func (e *execError) Details() string { out := &bytes.Buffer{} fmt.Fprintf(out, "Command: %v\n", e.cmd) if len(e.stdOut) > 0 { fmt.Fprintf(out, "Standard output:\n") w := prefixwriter.New(" ", out) w.Write(bytes.TrimSpace(e.stdOut)) fmt.Fprintf(out, "\n") } if len(e.errOut) > 0 { fmt.Fprintf(out, "Error output:\n") w := prefixwriter.New(" ", out) w.Write(bytes.TrimSpace(e.errOut)) fmt.Fprintf(out, "\n") } return out.String() }
func PrintError(err error, out io.Writer) { fmt.Fprintf(out, "Error: %v\n", err) if d, ok := err.(hasDetails); ok && len(d.Details()) > 0 { fmt.Fprintf(out, "Details:\n") w := prefixwriter.New(" ", out) fmt.Fprintf(w, "%s\n", d.Details()) } if s, ok := err.(hasSolution); ok && len(s.Solution()) > 0 { fmt.Fprintf(out, "Solution:\n") w := prefixwriter.New(" ", out) fmt.Fprintf(w, "%s\n", s.Solution()) } if c, ok := err.(hasCause); ok && c.Cause() != nil { fmt.Fprintf(out, "Caused By:\n") w := prefixwriter.New(" ", out) PrintError(c.Cause(), w) } }
func PrintLog(out io.Writer, title string, content []byte) { fmt.Fprintf(out, "%s:\n", title) w := prefixwriter.New(" ", out) w.Write(bytes.TrimSpace(content)) fmt.Fprintf(out, "\n") }
// Failure writes out a failure marker for a task and outputs the error // that caused the failure func (p *TaskPrinter) Failure(err error) { fmt.Fprintf(p.out, "FAIL\n") PrintError(err, prefixwriter.New(taskIndent, p.out)) }
// TaskWriter is a writer that can be used to write task output func (p *TaskPrinter) TaskWriter() io.Writer { p.taskWriter = &taskWriter{w: p.out} return prefixwriter.New(taskIndent, p.taskWriter) }