sync: Extract function that import flags from importer
This commit is contained in:
parent
3f55845374
commit
4039a394b5
8 changed files with 438 additions and 294 deletions
|
|
@ -1,9 +1,11 @@
|
|||
package sync
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
// ExerciceHintParams holds EHint definition infomation.
|
||||
|
|
@ -35,15 +37,15 @@ type ExerciceFlagChoice struct {
|
|||
// ExerciceFlag holds informations about one flag.
|
||||
type ExerciceFlag struct {
|
||||
Id int64
|
||||
Label string `toml:",omitempty"`
|
||||
Type string `toml:",omitempty"`
|
||||
Label string `toml:",omitempty"`
|
||||
Type string `toml:",omitempty"`
|
||||
Raw interface{}
|
||||
Separator string `toml:",omitempty"`
|
||||
Ordered bool `toml:",omitempty"`
|
||||
IgnoreCase bool `toml:",omitempty"`
|
||||
ValidatorRe string `toml:"validator_regexp,omitempty"`
|
||||
Help string `toml:",omitempty"`
|
||||
ChoicesCost int64 `toml:"choices_cost,omitempty"`
|
||||
Separator string `toml:",omitempty"`
|
||||
Ordered bool `toml:",omitempty"`
|
||||
IgnoreCase bool `toml:",omitempty"`
|
||||
ValidatorRe string `toml:"validator_regexp,omitempty"`
|
||||
Help string `toml:",omitempty"`
|
||||
ChoicesCost int64 `toml:"choices_cost,omitempty"`
|
||||
Choice []ExerciceFlagChoice
|
||||
LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"`
|
||||
NeedFlag []ExerciceDependency `toml:"need_flag,omitempty"`
|
||||
|
|
@ -70,3 +72,45 @@ func parseExerciceParams(i Importer, exPath string) (p ExerciceParams, err error
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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)))
|
||||
} else {
|
||||
// Treat legacy UCQ flags as ExerciceFlag
|
||||
for _, flag := range params.FlagsUCQ {
|
||||
params.Flags = append(params.Flags, ExerciceFlag{
|
||||
Id: flag.Id,
|
||||
Label: flag.Label,
|
||||
Type: "ucq",
|
||||
Raw: flag.Raw,
|
||||
ValidatorRe: flag.ValidatorRe,
|
||||
Help: flag.Help,
|
||||
ChoicesCost: flag.ChoicesCost,
|
||||
Choice: flag.Choice,
|
||||
LockedFile: flag.LockedFile,
|
||||
NeedFlag: flag.NeedFlag,
|
||||
})
|
||||
}
|
||||
params.FlagsUCQ = []ExerciceFlag{}
|
||||
|
||||
// Treat legacy MCQ flags as ExerciceFlag
|
||||
for _, flag := range params.FlagsMCQ {
|
||||
params.Flags = append(params.Flags, ExerciceFlag{
|
||||
Id: flag.Id,
|
||||
Label: flag.Label,
|
||||
Type: "mcq",
|
||||
ChoicesCost: flag.ChoicesCost,
|
||||
Choice: flag.Choice,
|
||||
LockedFile: flag.LockedFile,
|
||||
NeedFlag: flag.NeedFlag,
|
||||
})
|
||||
}
|
||||
params.FlagsMCQ = []ExerciceFlag{}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue