Dependancy between flags
This commit is contained in:
parent
711db60a4c
commit
f9abdd23c6
8 changed files with 111 additions and 1 deletions
|
|
@ -40,6 +40,8 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
} else if len(params.Flags) == 0 && len(params.FlagsUCQ) == 0 && len(params.FlagsMCQ) == 0 {
|
||||
errs = append(errs, fmt.Sprintf("%q: has no flag", path.Base(exercice.Path)))
|
||||
} else {
|
||||
kmap := map[int64]fic.Flag{}
|
||||
|
||||
// Import normal flags
|
||||
for nline, flag := range params.Flags {
|
||||
if len(flag.Label) == 0 {
|
||||
|
|
@ -54,6 +56,21 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
errs = append(errs, fmt.Sprintf("%q: error flag #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||
continue
|
||||
} else {
|
||||
if flag.Id != 0 {
|
||||
kmap[flag.Id] = k
|
||||
}
|
||||
|
||||
// Import dependency to flag
|
||||
for _, nf := range flag.NeedFlag {
|
||||
if rf, ok := kmap[nf.Id]; !ok {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag #%d dependency to flag id=%s: id not defined, perhaps not available at time of processing", path.Base(exercice.Path), nline + 1, nf.Id))
|
||||
continue
|
||||
} else if err := k.AddDepend(rf); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag #%d dependency to %s: %s", path.Base(exercice.Path), nline + 1, nf.Id, err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Import dependency to file
|
||||
for _, lf := range flag.LockedFile {
|
||||
if rf, err := exercice.GetFileByFilename(lf.Filename); err != nil {
|
||||
|
|
@ -81,6 +98,22 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
errs = append(errs, fmt.Sprintf("%q: error flag UCQ #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||
continue
|
||||
} else {
|
||||
// Import dependency to file
|
||||
if flag.Id != 0 {
|
||||
kmap[flag.Id] = k
|
||||
}
|
||||
|
||||
// Import dependency to flag
|
||||
for _, nf := range flag.NeedFlag {
|
||||
if rf, ok := kmap[nf.Id]; !ok {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag #%d dependency to flag id=%s: id not defined, perhaps not available at time of processing", path.Base(exercice.Path), nline + 1, nf.Id))
|
||||
continue
|
||||
} else if err := k.AddDepend(rf); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag #%d dependency to %s: %s", path.Base(exercice.Path), nline + 1, nf.Id, err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Import dependency to file
|
||||
for _, lf := range flag.LockedFile {
|
||||
if rf, err := exercice.GetFileByFilename(lf.Filename); err != nil {
|
||||
|
|
|
|||
Reference in a new issue