package sync import ( "path" "github.com/BurntSushi/toml" ) // ExerciceHintParams holds EHint definition infomation. type ExerciceHintParams struct { Filename string Content string Cost int64 Title string } // ExerciceDependency holds dependency definitions information. type ExerciceDependency struct { Id int64 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 { Id int64 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"` LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"` NeedFlag []ExerciceDependency `toml:"need_flag,omitempty"` } // ExerciceFlagMCQChoice holds a choice for an MCQ flag. type ExerciceFlagMCQChoice struct { Label string Value interface{} `toml:",omitempty"` Help string `toml:",omitempty"` } // ExerciceFlagMCQ holds information about a MCQ flag. type ExerciceFlagMCQ struct { Label string `toml:",omitempty"` Choice []ExerciceFlagMCQChoice NoShuffle bool } // ExerciceFlagUCQChoice holds a choice for an UCQ flag. type ExerciceFlagUCQChoice struct { Label string `toml:",omitempty"` Value string } // ExerciceFlagUCQ holds information about a UCQ flag. type ExerciceFlagUCQ struct { Id int64 Label string `toml:",omitempty"` Raw string IgnoreCase bool `toml:",omitempty"` ValidatorRe string `toml:"validator_regexp,omitempty"` Help string `toml:",omitempty"` DisplayAs string `toml:",omitempty"` ChoicesCost int64 `toml:"choices_cost,omitempty"` Choice []ExerciceFlagUCQChoice LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"` NeedFlag []ExerciceDependency `toml:"need_flag,omitempty"` NoShuffle bool } // ExerciceParams contains values parsed from defines.txt. type ExerciceParams struct { Gain int64 Tags []string Hints []ExerciceHintParams `toml:"hint"` Dependencies []ExerciceDependency `toml:"depend"` Flags []ExerciceFlag `toml:"flag"` FlagsMCQ []ExerciceFlagMCQ `toml:"flag_mcq"` FlagsUCQ []ExerciceFlagUCQ `toml:"flag_ucq"` } // parseExerciceParams reads challenge definitions from defines.txt and extract usefull data to set up the challenge. func parseExerciceParams(i Importer, exPath string) (p ExerciceParams, err error) { var defs string defs, err = getFileContent(i, path.Join(exPath, "challenge.txt")) _, err = toml.Decode(defs, &p) return }