Add support for toml

This commit is contained in:
Herkermer Sherwood 2016-12-08 17:07:08 -08:00
parent 4fae23fe25
commit c4b0efecc9

24
util.go
View file

@ -164,31 +164,37 @@ func userHomeDir() string {
return os.Getenv("HOME") return os.Getenv("HOME")
} }
func marshalConfigWriter(out afero.File, c map[string]interface{}, configType string) error { func marshalConfigWriter(f afero.File, c map[string]interface{}, configType string) error {
switch configType { switch configType {
case "json": case "json":
b, err := json.MarshalIndent(v.AllSettings(), "", " ") b, err := json.MarshalIndent(v.AllSettings(), "", " ")
if err != nil { if err != nil {
return ConfigMarshalError{err} return ConfigMarshalError{err}
} }
_, err = out.WriteString(string(b)) _, err = f.WriteString(string(b))
if err != nil { if err != nil {
return ConfigMarshalError{err} return ConfigMarshalError{err}
} }
// case "toml": case "hcl":
// w := bufio.NewWriter(out) // TODO: How to convert map to hcl???
// if err := toml.NewEncoder(w).Encode(v.AllSettings()); err != nil {
// return ConfigMarshalError{err} case "prop", "props", "properties":
// }
// w.Flush() case "toml":
t := toml.TreeFromMap(v.AllSettings())
s := t.String()
_, err := f.WriteString(s)
if err != nil {
return ConfigMarshalError{err}
}
case "yaml", "yml": case "yaml", "yml":
b, err := yaml.Marshal(v.AllSettings()) b, err := yaml.Marshal(v.AllSettings())
if err != nil { if err != nil {
return ConfigMarshalError{err} return ConfigMarshalError{err}
} }
_, err = out.WriteString(string(b)) _, err = f.WriteString(string(b))
if err != nil { if err != nil {
return ConfigMarshalError{err} return ConfigMarshalError{err}
} }