libfic/flag: add validatorRegexp field
This commit is contained in:
parent
c2558fe0ec
commit
ff56ec9fe3
8 changed files with 111 additions and 35 deletions
|
|
@ -19,6 +19,15 @@ func isFullGraphic(s string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func validatorRegexp(vre string) (validator_regexp *string) {
|
||||
if len(vre) > 0 {
|
||||
validator_regexp = &vre
|
||||
} else {
|
||||
validator_regexp = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// SyncExerciceFlags reads the content of challenge.txt and import "classic" flags as Key for the given challenge.
|
||||
func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
||||
if _, err := exercice.WipeFlags(); err != nil {
|
||||
|
|
@ -40,7 +49,7 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
errs = append(errs, fmt.Sprintf("%q: WARNING flag #%d: non-printable characters in flag, is this really expected?", path.Base(exercice.Path), nline + 1))
|
||||
}
|
||||
|
||||
if k, err := exercice.AddRawFlag(flag.Label, flag.Help, flag.IgnoreCase, flag.Raw); err != nil {
|
||||
if k, err := exercice.AddRawFlag(flag.Label, flag.Help, flag.IgnoreCase, validatorRegexp(flag.ValidatorRe), []byte(flag.Raw)); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||
continue
|
||||
} else {
|
||||
|
|
@ -67,7 +76,7 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
errs = append(errs, fmt.Sprintf("%q: WARNING flag UCQ #%d: non-printable characters in flag, is this really expected?", path.Base(exercice.Path), nline + 1))
|
||||
}
|
||||
|
||||
if k, err := exercice.AddRawFlag(flag.Label, flag.Help, flag.IgnoreCase, flag.Raw); err != nil {
|
||||
if k, err := exercice.AddRawFlag(flag.Label, flag.Help, flag.IgnoreCase, validatorRegexp(flag.ValidatorRe), []byte(flag.Raw)); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag UCQ #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||
continue
|
||||
} else {
|
||||
|
|
|
|||
Reference in a new issue