Skip to content

Commit

Permalink
cmd: fix human output
Browse files Browse the repository at this point in the history
  • Loading branch information
zegl committed Apr 2, 2022
1 parent 54791e9 commit 6401f9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cmd/kube-score/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ Use "-" as filename to read from STDIN.`, execName(binName))
if err != nil {
termWidth = 80
}
_, err = human.Human(scoreCard, *verboseOutput, termWidth)
return err
r, err = human.Human(scoreCard, *verboseOutput, termWidth)
if err != nil {
return err
}
case *outputFormat == "ci" && version == "v1":
r = ci.CI(scoreCard)
case *outputFormat == "sarif":
Expand Down
20 changes: 12 additions & 8 deletions renderer/human/human.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,28 @@ func Human(scoreCard *scorecard.Scorecard, verboseOutput int, termWidth int) (io
}

// Adjust to termsize
fmt.Fprint(w, safeRepeat(" ", min(80, termWidth)-writtenHeaderChars-2))
_, err := fmt.Fprint(w, safeRepeat(" ", min(80, termWidth)-writtenHeaderChars-2))
if err != nil {
return nil, fmt.Errorf("failed to write terminal padding: %w", err)
}

switch {
case scoredObject.AnyBelowOrEqualToGrade(scorecard.GradeCritical):
fmt.Fprintf(w, "💥\n")
_, err = fmt.Fprintf(w, "💥\n")
case scoredObject.AnyBelowOrEqualToGrade(scorecard.GradeWarning):
fmt.Fprintf(w, "🤔\n")
_, err = fmt.Fprintf(w, "🤔\n")
default:
fmt.Fprintf(w, "✅\n")
_, err = fmt.Fprintf(w, "✅\n")
}
if err != nil {
return nil, fmt.Errorf("failed to write: %w", err)
}

for _, card := range scoredObject.Checks {
r := outputHumanStep(card, verboseOutput, termWidth)
_, err := io.Copy(w, r)
if err != nil {
return nil, err
if _, err := io.Copy(w, r); err != nil {
return nil, fmt.Errorf("failed to copy output: %w", err)
}

}
}

Expand Down

0 comments on commit 6401f9e

Please sign in to comment.