Build error formatting on fission spec apply --wait (#1403)

The character `\n` in buildlog stores in package status
are escaped and so when we have to replace them with
actual line breaker.
This commit is contained in:
Ta-Ching Chen
2019-11-12 21:00:55 +08:00
committed by GitHub
parent a645a1e197
commit 1cda7e051b
5 changed files with 58 additions and 21 deletions
+13
View File
@@ -25,6 +25,7 @@ import (
"os"
"path/filepath"
"strings"
"text/tabwriter"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
@@ -175,3 +176,15 @@ func DownloadStoragesvcURL(client *client.Client, fileUrl string) (io.ReadCloser
return reader, nil
}
// PrintPackageSummary prints package information and build logs.
func PrintPackageSummary(writer io.Writer, pkg *fv1.Package) {
// replace escaped line breaker character
buildlog := strings.ReplaceAll(pkg.Status.BuildLog, `\n`, "\n")
w := tabwriter.NewWriter(writer, 0, 0, 1, ' ', 0)
fmt.Fprintf(w, "%v\t%v\n", "Name:", pkg.Metadata.Name)
fmt.Fprintf(w, "%v\t%v\n", "Environment:", pkg.Spec.Environment.Name)
fmt.Fprintf(w, "%v\t%v\n", "Status:", pkg.Status.BuildStatus)
fmt.Fprintf(w, "%v\n%v", "Build Logs:", buildlog)
w.Flush()
}