Array flags can be non-ordered
This commit is contained in:
parent
dbf1985d25
commit
0e36a850cf
5 changed files with 22 additions and 5 deletions
|
@ -22,6 +22,7 @@ Tous les textes doivent utiliser l'encodage UTF8.
|
|||
* `label = "Intitulé"` : (facultatif, par défaut : `Flag`) intitulé du drapeau ;
|
||||
* `raw = 'MieH2athxuPhai6u'` ou `raw = ['part1', 'part2']` : drapeau exact à trouver ; sous forme de tableau, le participant n'aura pas connaissaance du nombre d'éléments ;
|
||||
* `validator_regexp = "^(?:sudo +)?(.*)$"` : (facultatif) expression rationnelle dont les groupes capturés serviront comme chaîne à valider (notez que `?:` au début d'un groupe ne le capturera pas) ;
|
||||
* `ordered = false` : (facultatif, par défaut : `false`) ignore l'ordre dans lequels les éléments du tableau sont passés ;
|
||||
* `ignorecase = true` : (facultatif, par défaut : `false`) ignore la case de ce drapeau ;
|
||||
* `help = "Indication"` : (facultatif) chaîne de caractères placée sous le champ du formulaire, idéale pour donner une indication de format ;
|
||||
* `[[flag.unlock_file]]` : bloque l'accès à un fichier tant que le flag n'est pas obtenu :
|
||||
|
|
|
@ -31,6 +31,7 @@ type ExerciceFlag struct {
|
|||
Label 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"`
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"math/rand"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
|
@ -70,13 +71,14 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
errs = append(errs, fmt.Sprintf("%q: flag #%d: separator truncated to %q", path.Base(exercice.Path), nline + 1, flag.Separator))
|
||||
}
|
||||
|
||||
var fitems []string
|
||||
for i, v := range f {
|
||||
if g, ok := v.(string); ok {
|
||||
if strings.Index(g, flag.Separator) != -1 {
|
||||
errs = append(errs, fmt.Sprintf("%q: flag #%d: flag items cannot contain %q character as it is used as separator. Change the separator attribute for this flag.", path.Base(exercice.Path), nline + 1, flag.Separator))
|
||||
continue flags
|
||||
} else {
|
||||
raw += g + flag.Separator
|
||||
fitems = append(fitems, g)
|
||||
}
|
||||
} else {
|
||||
errs = append(errs, fmt.Sprintf("%q: flag #%d, item %d has an invalid type: can only be string, is %T.", path.Base(exercice.Path), nline + 1, i, v))
|
||||
|
@ -84,7 +86,15 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
}
|
||||
}
|
||||
|
||||
flag.Label = "`" + flag.Separator + flag.Label
|
||||
ignord := "t"
|
||||
if flag.Ordered {
|
||||
sort.Strings(fitems)
|
||||
ignord = "f"
|
||||
}
|
||||
|
||||
raw = strings.Join(fitems, flag.Separator) + flag.Separator
|
||||
|
||||
flag.Label = "`" + flag.Separator + ignord + flag.Label
|
||||
} else if f, ok := flag.Raw.(int64); ok {
|
||||
raw = fmt.Sprintf("%d", f)
|
||||
} else if f, ok := flag.Raw.(string); !ok {
|
||||
|
|
Reference in a new issue