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")
}
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 {
case "json":
b, err := json.MarshalIndent(v.AllSettings(), "", " ")
if err != nil {
return ConfigMarshalError{err}
}
_, err = out.WriteString(string(b))
_, err = f.WriteString(string(b))
if err != nil {
return ConfigMarshalError{err}
}
// case "toml":
// w := bufio.NewWriter(out)
// if err := toml.NewEncoder(w).Encode(v.AllSettings()); err != nil {
// return ConfigMarshalError{err}
// }
// w.Flush()
case "hcl":
// TODO: How to convert map to hcl???
case "prop", "props", "properties":
case "toml":
t := toml.TreeFromMap(v.AllSettings())
s := t.String()
_, err := f.WriteString(s)
if err != nil {
return ConfigMarshalError{err}
}
case "yaml", "yml":
b, err := yaml.Marshal(v.AllSettings())
if err != nil {
return ConfigMarshalError{err}
}
_, err = out.WriteString(string(b))
_, err = f.WriteString(string(b))
if err != nil {
return ConfigMarshalError{err}
}