sync: Allow using challenge.toml instead of challenge.txt

This commit is contained in:
nemunaire 2023-05-05 15:25:20 +02:00
parent 20c41ec573
commit 2140939364
4 changed files with 12 additions and 6 deletions

View File

@ -112,7 +112,13 @@ func (p ExerciceParams) GetRawFlags() (ret []string) {
// parseExerciceParams reads challenge definitions from defines.txt and extract usefull data to set up the challenge.
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 i.Exists(path.Join(exPath, "challenge.toml")) {
defs, err = GetFileContent(i, path.Join(exPath, "challenge.toml"))
} else {
defs, err = GetFileContent(i, path.Join(exPath, "challenge.txt"))
}
if err != nil {
return
}

View File

@ -120,7 +120,7 @@ func buildExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExc
// CheckExerciceHints checks if all hints are corrects..
func CheckExerciceHints(i Importer, exercice *fic.Exercice, exceptions *CheckExceptions) ([]importHint, []error) {
exceptions = exceptions.GetFileExceptions("challenge.txt")
exceptions = exceptions.GetFileExceptions("challenge.txt", "challenge.toml")
return buildExerciceHints(i, exercice, exceptions)
}
@ -130,7 +130,7 @@ func SyncExerciceHints(i Importer, exercice *fic.Exercice, flagsBindings map[int
if _, err := exercice.WipeHints(); err != nil {
errs = append(errs, err)
} else {
exceptions = exceptions.GetFileExceptions("challenge.txt")
exceptions = exceptions.GetFileExceptions("challenge.txt", "challenge.toml")
hints, berrs := buildExerciceHints(i, exercice, exceptions)
errs = append(errs, berrs...)

View File

@ -513,7 +513,7 @@ func buildExerciceFlags(i Importer, exercice *fic.Exercice, exceptions *CheckExc
// CheckExerciceFlags checks if all flags for the given challenge are correct.
func CheckExerciceFlags(i Importer, exercice *fic.Exercice, files []string, exceptions *CheckExceptions) (rf []fic.Flag, errs []error) {
exceptions = exceptions.GetFileExceptions("challenge.txt")
exceptions = exceptions.GetFileExceptions("challenge.txt", "challenge.toml")
flags, flagsids, berrs := buildExerciceFlags(i, exercice, exceptions)
errs = append(errs, berrs...)
@ -591,7 +591,7 @@ func SyncExerciceFlags(i Importer, exercice *fic.Exercice, exceptions *CheckExce
} else if _, err := exercice.WipeMCQs(); err != nil {
errs = append(errs, err)
} else {
exceptions = exceptions.GetFileExceptions("challenge.txt")
exceptions = exceptions.GetFileExceptions("challenge.txt", "challenge.toml")
flags, flagids, berrs := buildExerciceFlags(i, exercice, exceptions)
errs = append(errs, berrs...)

View File

@ -247,7 +247,7 @@ func main() {
nberr := 0
theme, exceptions, errs := sync.BuildTheme(sync.GlobalImporter, p)
if theme != nil && !sync.GlobalImporter.Exists(path.Join(p, "challenge.txt")) {
if theme != nil && !sync.GlobalImporter.Exists(path.Join(p, "challenge.txt")) && !sync.GlobalImporter.Exists(path.Join(p, "challenge.toml")) {
nberr += len(errs)
for _, err := range errs {
log.Println(err)