libfic/flag: add validatorRegexp field

This commit is contained in:
nemunaire 2018-11-16 20:46:19 +01:00 committed by Pierre-Olivier Mercier
parent c2558fe0ec
commit ff56ec9fe3
8 changed files with 111 additions and 35 deletions

View file

@ -189,11 +189,12 @@ func deleteExerciceHint(hint fic.EHint, _ []byte) (interface{}, error) {
}
type uploadedFlag struct {
Label string
Help string
ICase bool
Flag string
Hash []byte
Label string
Help string
IgnoreCase bool
ValidatorRe *string `json:"validator_regexp"`
Flag string
Value []byte
}
func createExerciceFlag(exercice fic.Exercice, body []byte) (interface{}, error) {
@ -206,7 +207,12 @@ func createExerciceFlag(exercice fic.Exercice, body []byte) (interface{}, error)
return nil, errors.New("Flag not filled")
}
return exercice.AddRawFlag(uk.Label, uk.Help, uk.ICase, uk.Flag)
var vre *string = nil
if uk.ValidatorRe != nil && len(*uk.ValidatorRe) > 0 {
vre = uk.ValidatorRe
}
return exercice.AddRawFlag(uk.Label, uk.Help, uk.IgnoreCase, vre, []byte(uk.Flag))
}
func showExerciceFlag(flag fic.Flag, _ fic.Exercice, body []byte) (interface{}, error) {
@ -226,8 +232,14 @@ func updateExerciceFlag(flag fic.Flag, exercice fic.Exercice, body []byte) (inte
}
flag.Help = uk.Help
flag.IgnoreCase = uk.ICase
flag.Checksum = uk.Hash
flag.IgnoreCase = uk.IgnoreCase
flag.Checksum = uk.Value
if uk.ValidatorRe != nil && len(*uk.ValidatorRe) > 0 {
flag.ValidatorRegexp = uk.ValidatorRe
} else {
flag.ValidatorRegexp = nil
}
if _, err := flag.Update(); err != nil {
return nil, err