sync: introducing showlines property for vectors

It allows players to know in advance how many items the vector is composed.
This commit is contained in:
nemunaire 2019-11-25 17:45:41 +01:00
parent a545112cb2
commit b4fa57f9c9
4 changed files with 35 additions and 9 deletions

View file

@ -34,7 +34,7 @@ func validatorRegexp(vre string) (validator_regexp *string) {
return
}
func getRawKey(input interface{}, validatorRe string, ordered bool) (raw string, prep string, errs []string) {
func getRawKey(input interface{}, validatorRe string, ordered bool, showLines bool) (raw string, prep string, errs []string) {
separator := ","
// Concatenate array
@ -71,9 +71,19 @@ func getRawKey(input interface{}, validatorRe string, ordered bool) (raw string,
sort.Strings(fitems)
ignord = "t"
}
nbLines := 0
if showLines {
if len(fitems) > 9 {
errs = append(errs, "too much items in vector to use ShowLines features, max 9.")
} else {
nbLines = len(fitems)
}
}
raw = strings.Join(fitems, separator) + separator
prep = "`" + separator + ignord
prep = fmt.Sprintf("`%s%s%d", separator, ignord, nbLines)
} else if f, ok := input.(int64); ok {
raw = fmt.Sprintf("%d", f)
} else if f, ok := input.(string); !ok {
@ -95,7 +105,7 @@ func buildKeyFlag(exercice fic.Exercice, flag ExerciceFlag, flagline int, defaul
flag.Label = flag.Label[1:]
}
raw, prep, terrs := getRawKey(flag.Raw, flag.ValidatorRe, flag.Ordered)
raw, prep, terrs := getRawKey(flag.Raw, flag.ValidatorRe, flag.Ordered, flag.ShowLines)
if len(terrs) > 0 {
for _, err := range terrs {
@ -137,7 +147,7 @@ func buildKeyFlag(exercice fic.Exercice, flag ExerciceFlag, flagline int, defaul
}
for _, choice := range flag.Choice {
val, prep, terrs := getRawKey(choice.Value, "", false)
val, prep, terrs := getRawKey(choice.Value, "", false, false)
if len(terrs) > 0 {
for _, err := range terrs {
errs = append(errs, fmt.Sprintf("%q: flag #%d: %s", path.Base(exercice.Path), flagline, err))