sync: add dependency on flag to download file
This commit is contained in:
parent
dcfb34c6fd
commit
1e2a74f3ca
9 changed files with 112 additions and 16 deletions
|
@ -20,18 +20,18 @@ type ExerciceDependency struct {
|
|||
Theme string `toml:",omitempty"`
|
||||
}
|
||||
|
||||
// ExerciceUnlockFile holds parameters related to a locked file.
|
||||
type ExerciceUnlockFile struct {
|
||||
Filename string `toml:",omitempty"`
|
||||
}
|
||||
|
||||
// ExerciceFlag holds informations about a "classic" flag.
|
||||
type ExerciceFlag struct {
|
||||
Label string `toml:",omitempty"`
|
||||
Raw string
|
||||
IgnoreCase bool `toml:",omitempty"`
|
||||
Help string `toml:",omitempty"`
|
||||
LockedFile []ExerciceFlag `toml:unlock_file",omitempty"`
|
||||
}
|
||||
|
||||
// ExerciceUnlockFile holds parameters related to a locked file.
|
||||
type ExerciceFlag struct {
|
||||
Filename string `toml:",omitempty"`
|
||||
IgnoreCase bool `toml:",omitempty"`
|
||||
Help string `toml:",omitempty"`
|
||||
LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"`
|
||||
}
|
||||
|
||||
// ExerciceFlagMCQChoice holds a choice for an MCQ flag.
|
||||
|
@ -60,7 +60,7 @@ type ExerciceFlagUCQ struct {
|
|||
DisplayAs string `toml:",omitempty"`
|
||||
Choices_Cost int64 `toml:",omitempty"`
|
||||
Choice []ExerciceFlagUCQChoice
|
||||
LockedFile []ExerciceFlag `toml:unlock_file",omitempty"`
|
||||
LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"`
|
||||
}
|
||||
|
||||
// ExerciceParams contains values parsed from defines.txt.
|
||||
|
|
|
@ -40,9 +40,20 @@ func SyncExerciceKeys(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 _, err := exercice.AddRawKey(flag.Label, flag.Raw); err != nil {
|
||||
if k, err := exercice.AddRawKey(flag.Label, flag.Raw); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||
continue
|
||||
} else {
|
||||
// Import dependency to file
|
||||
for _, lf := range flag.LockedFile {
|
||||
if rf, err := exercice.GetFileByFilename(lf.Filename); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag #%d dependency to %s: %s", path.Base(exercice.Path), nline + 1, lf.Filename, err))
|
||||
continue
|
||||
} else if err := rf.AddDepend(k); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag #%d dependency to %s: %s", path.Base(exercice.Path), nline + 1, lf.Filename, err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,9 +67,20 @@ func SyncExerciceKeys(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 _, err := exercice.AddRawKey(flag.Label, flag.Raw); err != nil {
|
||||
if k, err := exercice.AddRawKey(flag.Label, flag.Raw); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag UCQ #%d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||
continue
|
||||
} else {
|
||||
// Import dependency to file
|
||||
for _, lf := range flag.LockedFile {
|
||||
if rf, err := exercice.GetFileByFilename(lf.Filename); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag UCQ #%d dependency to %s: %s", path.Base(exercice.Path), nline + 1, lf.Filename, err))
|
||||
continue
|
||||
} else if err := rf.AddDepend(k); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%q: error flag UCQ #%d dependency to %s: %s", path.Base(exercice.Path), nline + 1, lf.Filename, err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ func SyncDeep(i Importer) (errs map[string][]string) {
|
|||
|
||||
if exercices, err := theme.GetExercices(); err == nil {
|
||||
for _, exercice := range exercices {
|
||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceKeys(i, exercice)...)
|
||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceFiles(i, exercice)...)
|
||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceHints(i, exercice)...)
|
||||
errs[theme.Name] = append(errs[theme.Name], SyncExerciceKeys(i, exercice)...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue