sync: alert about unknown keys in challenge.txt
This commit is contained in:
parent
936ef09e33
commit
c8ece39cb2
3 changed files with 19 additions and 6 deletions
|
@ -64,11 +64,14 @@ type ExerciceParams struct {
|
|||
}
|
||||
|
||||
// parseExerciceParams reads challenge definitions from defines.txt and extract usefull data to set up the challenge.
|
||||
func parseExerciceParams(i Importer, exPath string) (p ExerciceParams, err error) {
|
||||
func parseExerciceParams(i Importer, exPath string) (p ExerciceParams, md toml.MetaData, err error) {
|
||||
var defs string
|
||||
defs, err = getFileContent(i, path.Join(exPath, "challenge.txt"))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = toml.Decode(defs, &p)
|
||||
md, err = toml.Decode(defs, &p)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -76,7 +79,7 @@ func parseExerciceParams(i Importer, exPath string) (p ExerciceParams, err error
|
|||
// getExerciceParams returns normalized
|
||||
func getExerciceParams(i Importer, exercice fic.Exercice) (params ExerciceParams, errs []string) {
|
||||
var err error
|
||||
if params, err = parseExerciceParams(i, exercice.Path); err != nil {
|
||||
if params, _, err = parseExerciceParams(i, exercice.Path); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: challenge.txt: %s", path.Base(exercice.Path), err))
|
||||
} else if len(params.Flags) == 0 && len(params.FlagsUCQ) == 0 && len(params.FlagsMCQ) == 0 {
|
||||
errs = append(errs, fmt.Sprintf("%q: has no flag", path.Base(exercice.Path)))
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
)
|
||||
|
||||
func buildExerciceHints(i Importer, exercice fic.Exercice) (hints []fic.EHint, errs []string) {
|
||||
params, err := parseExerciceParams(i, exercice.Path)
|
||||
params, _, err := parseExerciceParams(i, exercice.Path)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: challenge.txt: %s", path.Base(exercice.Path), err))
|
||||
return
|
||||
|
|
|
@ -7,7 +7,9 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
|
@ -133,12 +135,20 @@ func BuildExercice(i Importer, theme fic.Theme, epath string, dmap *map[int64]fi
|
|||
}
|
||||
|
||||
// Parse challenge.txt
|
||||
p, err = parseExerciceParams(i, epath)
|
||||
var md toml.MetaData
|
||||
p, md, err = parseExerciceParams(i, epath)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: challenge.txt: %s", edir, err))
|
||||
errs = append(errs, fmt.Sprintf("%q: %s", edir, err))
|
||||
return
|
||||
}
|
||||
|
||||
// Alert about unknown keys in challenge.txt
|
||||
if len(md.Undecoded()) > 0 {
|
||||
for _, k := range md.Undecoded() {
|
||||
errs = append(errs, fmt.Sprintf("%q: challenge.txt: unknown key %q found, check https://srs.nemunai.re/fic/files/challenge.html", edir, k))
|
||||
}
|
||||
}
|
||||
|
||||
if p.Gain == 0 {
|
||||
errs = append(errs, fmt.Sprintf("%q: challenge.txt: Undefined gain for challenge", edir))
|
||||
} else {
|
||||
|
|
Reference in a new issue