Handle choices in UCQ (db, sync done)

This commit is contained in:
nemunaire 2018-11-21 04:10:22 +01:00 committed by Pierre-Olivier Mercier
parent 333bb408e1
commit 488a032eba
7 changed files with 202 additions and 1 deletions

View file

@ -90,6 +90,26 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
continue
}
}
// Import choices
hasOne := false
for cid, choice := range flag.Choice {
if len(choice.Label) == 0 {
choice.Label = choice.Value
}
if _, err := k.AddChoice(choice.Label, choice.Value); err != nil {
errs = append(errs, fmt.Sprintf("%q: error in UCQ %d choice %d: %s", path.Base(exercice.Path), nline + 1, cid, err))
continue
}
if choice.Value == flag.Raw {
hasOne = true
}
}
if !hasOne {
errs = append(errs, fmt.Sprintf("%q: error in UCQ %d: no valid answer defined.", path.Base(exercice.Path), nline + 1))
}
}
}