Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hints for failing conditions #172

Merged
merged 7 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Mobmaker55 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading