From f22108809004ea08f962cc0ad19ef1fa8051bd0c Mon Sep 17 00:00:00 2001 From: Joop Kiefte Date: Sat, 12 Jan 2019 18:09:14 +0100 Subject: Beginning implementation TOML settings --- rules/toml.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 rules/toml.go (limited to 'rules/toml.go') diff --git a/rules/toml.go b/rules/toml.go new file mode 100644 index 0000000..4bb5946 --- /dev/null +++ b/rules/toml.go @@ -0,0 +1,51 @@ +package rules + +import ( + "github.com/BurntSushi/toml" + "os" +) + +type TOMLConf struct{ + Elements map[string]Set + Scenes map[string][]string + metadata toml.MetaData +} + +func ReadFile(file string) (TOMLConf, error) { + var r TOMLConf + m, err := toml.DecodeFile(file, &r) + r.metadata = m + return r, err +} + +func MustReadFile(file string) TOMLConf { + c, err := ReadFile(file) + if err != nil { + panic(err) + } + return c +} + +func DefaultConf() TOMLConf { + return TOMLConf{ + Elements: map[string]Set{ + "default": Default, + }, + Scenes: map[string][]string{ + "en": []string{"INT", "EXT", "EST", "INT./EXT", "INT/EXT", "EXT/INT", "EXT./INT", "I/E"}, + "nl": []string{"BIN", "BUI", "BI", "BU", "OPEN", "BIN./BUI", "BUI./BIN", "BIN/BUI", "BI/BU"}, + "de": []string{"INT", "EXT", "ETABL", "INT./EXT", "INT/EXT", "EXT/INT", "EXT./INT", "I/E"}, + "fr": []string{"INT", "EXT", "INT./EXT", "INT/EXT", "EXT/INT", "EXT./INT", "I/E"}, + "eo": []string{"EN", "ENE", "EKST", "EK", "EN/EKST", "EKST/EN", "EKST./EN", "EN./EKST"}, + "ru": []string{"ИНТ", "НАТ", "ИНТ/НАТ", "ИНТ./НАТ", "НАТ/ИНТ", "НАТ./ИНТ", "ЭКСТ", "И/Н", "Н/И"}, + }, + } +} + +func Dump(file string) error { + f, err := os.Create(file) + if err != nil { + return err + } + return toml.NewEncoder(f).Encode(DefaultConf()) +} -- cgit v1.2.3-70-g09d2