Skip to content

Commit

Permalink
Add check-wide hints
Browse files Browse the repository at this point in the history
  • Loading branch information
sourque committed Aug 13, 2023
1 parent c4965eb commit 3344ae9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
11 changes: 7 additions & 4 deletions checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ import (
// the conditions for a check, and its message and points (autogenerated or
// otherwise).
type check struct {
Message string
Points int
Message string
Hint string
Points int

Fail []cond
Pass []cond
PassOverride []cond
}

// cond, or condition, is the parameters for a given test within a check.
type cond struct {
Type string
Hint string
Hint string
Type string

Path string
Cmd string
User string
Expand Down
9 changes: 7 additions & 2 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func parseConfig(configContent string) {

// Print warnings for impossible checks and undefined check types.
for i, check := range conf.Check {
allConditions := append(append(append([]cond{}, check.Pass[:]...), check.Fail[:]...), check.PassOverride[:]...)
if len(allConditions) == 0 {
if len(check.Pass) == 0 && len(check.PassOverride) == 0 {
warn("Check " + fmt.Sprintf("%d", i+1) + " does not define any possible ways to pass!")
}
allConditions := append(append(append([]cond{}, check.Pass[:]...), check.Fail[:]...), check.PassOverride[:]...)
for j, cond := range allConditions {
if cond.Type == "" {
warn("Check " + fmt.Sprintf("%d condition %d", i+1, j+1) + " does not have a check type!")
Expand Down Expand Up @@ -169,6 +169,11 @@ func obfuscateConfig() {
if err := obfuscateData(&conf.Check[i].Message); err != nil {
fail(err.Error())
}
if conf.Check[i].Hint != "" {
if err := obfuscateData(&conf.Check[i].Hint); err != nil {
fail(err.Error())
}
}
for j := range check.Pass {
if err := obfuscateCond(&conf.Check[i].Pass[j]); err != nil {
fail(err.Error())
Expand Down
7 changes: 7 additions & 0 deletions score.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ func scoreCheck(check check) {
}
image.Score += check.Points
} else {
// If there is a check-wide hint, add to start of hint messages.
if check.Hint != "" {
hints := []string{check.Hint}
hints = append(hints, hint.Messages...)
hint.Messages = hints
}

// If the check failed, and there are hints, see if we should display them.
// All hints triggered (based on which conditions ran) are displayed in sequential order.
if len(hint.Messages) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion web.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func genReport(img *imageData) {
obfuscateData(&point.Message)
}

htmlFile.WriteString("<br>")
htmlFile.WriteString("</p>")
// for each hint:
for _, hint := range img.Hints {
if len(hint.Messages) == 1 {
Expand Down

0 comments on commit 3344ae9

Please sign in to comment.