implement choices_cost
This commit is contained in:
parent
f9abdd23c6
commit
476f0f553c
18 changed files with 180 additions and 24 deletions
|
|
@ -270,6 +270,7 @@ type uploadedFlag struct {
|
|||
ValidatorRe *string `json:"validator_regexp"`
|
||||
Flag string
|
||||
Value []byte
|
||||
ChoicesCost int64
|
||||
}
|
||||
|
||||
func createExerciceFlag(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||
|
|
@ -287,7 +288,7 @@ func createExerciceFlag(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
vre = uk.ValidatorRe
|
||||
}
|
||||
|
||||
return exercice.AddRawFlag(uk.Label, uk.Help, uk.IgnoreCase, vre, []byte(uk.Flag))
|
||||
return exercice.AddRawFlag(uk.Label, uk.Help, uk.IgnoreCase, vre, []byte(uk.Flag), uk.ChoicesCost)
|
||||
}
|
||||
|
||||
func showExerciceFlag(flag fic.Flag, _ fic.Exercice, body []byte) (interface{}, error) {
|
||||
|
|
@ -309,6 +310,7 @@ func updateExerciceFlag(flag fic.Flag, exercice fic.Exercice, body []byte) (inte
|
|||
flag.Help = uk.Help
|
||||
flag.IgnoreCase = uk.IgnoreCase
|
||||
flag.Checksum = uk.Value
|
||||
flag.ChoicesCost = uk.ChoicesCost
|
||||
|
||||
if uk.ValidatorRe != nil && len(*uk.ValidatorRe) > 0 {
|
||||
flag.ValidatorRegexp = uk.ValidatorRe
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ type ExerciceFlagUCQ struct {
|
|||
ValidatorRe string `toml:"validator_regexp,omitempty"`
|
||||
Help string `toml:",omitempty"`
|
||||
DisplayAs string `toml:",omitempty"`
|
||||
Choices_Cost int64 `toml:",omitempty"`
|
||||
ChoicesCost int64 `toml:"choices_cost,omitempty"`
|
||||
Choice []ExerciceFlagUCQChoice
|
||||
LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"`
|
||||
NeedFlag []ExerciceDependency `toml:"need_flag,omitempty"`
|
||||
|
|
|
|||
|
|
@ -52,7 +52,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, validatorRegexp(flag.ValidatorRe), []byte(flag.Raw)); err != nil {
|
||||
if k, err := exercice.AddRawFlag(flag.Label, flag.Help, flag.IgnoreCase, validatorRegexp(flag.ValidatorRe), []byte(flag.Raw), 0); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||
continue
|
||||
} else {
|
||||
|
|
@ -94,7 +94,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, validatorRegexp(flag.ValidatorRe), []byte(flag.Raw)); err != nil {
|
||||
if k, err := exercice.AddRawFlag(flag.Label, flag.Help, flag.IgnoreCase, validatorRegexp(flag.ValidatorRe), []byte(flag.Raw), flag.ChoicesCost); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag UCQ #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||
continue
|
||||
} else {
|
||||
|
|
@ -205,7 +205,7 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
errs = append(errs, fmt.Sprintf("%q: error in MCQ %d choice %d: %s", path.Base(exercice.Path), nline + 1, cid, err))
|
||||
continue
|
||||
} else if len(justify) > 0 {
|
||||
if _, err := exercice.AddRawFlag(fmt.Sprintf("%%%d%%%s", e.Id, choice.Help), "", false, nil, []byte(justify)); err != nil {
|
||||
if _, err := exercice.AddRawFlag(fmt.Sprintf("%%%d%%%s", e.Id, choice.Help), "", false, nil, []byte(justify), 0); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error MCQ #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue