admin/sync: tiny refactor
This commit is contained in:
parent
5edccf21cd
commit
494ccb740b
2 changed files with 14 additions and 9 deletions
|
@ -60,9 +60,7 @@ func SyncExerciceKeys(i Importer, exercice fic.Exercice) []string {
|
|||
return errs
|
||||
}
|
||||
|
||||
func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
|
||||
var errs []string
|
||||
|
||||
func SyncExerciceMCQ(i Importer, exercice fic.Exercice) (errs []string) {
|
||||
if _, err := exercice.WipeMCQs(); err != nil {
|
||||
errs = append(errs, err.Error())
|
||||
return errs
|
||||
|
@ -70,7 +68,9 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
|
|||
|
||||
// Unique Choice Questions (checkbox)
|
||||
if ucq, err := getFileContent(i, path.Join(exercice.Path, "flags-ucq.txt")); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: unable to read ucq: %s", path.Base(exercice.Path), err))
|
||||
if i.exists(path.Join(exercice.Path, "flags-ucq.txt")) {
|
||||
errs = append(errs, fmt.Sprintf("%q: unable to read ucq: %s", path.Base(exercice.Path), err))
|
||||
}
|
||||
} else if flag, err := exercice.AddMCQ(""); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: unable to add ucq: %s", path.Base(exercice.Path), err))
|
||||
} else {
|
||||
|
@ -98,7 +98,9 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
|
|||
|
||||
// Multiple Choice Questions (radio)
|
||||
if mcq, err := getFileContent(i, path.Join(exercice.Path, "flags-mcq.txt")); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: unable to read mcq: %s", path.Base(exercice.Path), err))
|
||||
if i.exists(path.Join(exercice.Path, "flags-mcq.txt")) {
|
||||
errs = append(errs, fmt.Sprintf("%q: unable to read mcq: %s", path.Base(exercice.Path), err))
|
||||
}
|
||||
} else {
|
||||
for nline, quest := range strings.Split(mcq, "\n") {
|
||||
quest_splt := strings.Split(string(quest), "\t")
|
||||
|
|
Reference in a new issue