Archived
1
0

Use map structure to allow for multiple compile targets

This commit is contained in:
Jip J. Dekker 2016-09-25 14:35:17 +02:00
parent aaa87a06e4
commit 9c7f2f503d
3 changed files with 18 additions and 11 deletions

View File

@ -26,12 +26,13 @@ import (
var (
settingsFile = "ponder.json"
settingsTemplate = []byte(`{
"Name": "",
"Author": "",
"IgnoreDirs": [".git"],
"LilypondIncludes": [],
"OutputDir": "out"
settingsTemplate = []byte(`{ "default" : {
"Name": "",
"Author": "",
"IgnoreDirs": [".git"],
"LilypondIncludes": [],
"OutputDir": "out"
}
}`)
gitIgnoreTemplate = []byte(`# Output Folder
out/`)

View File

@ -77,5 +77,7 @@ func getSettings() (string, *settings.Settings) {
opts, err := settings.FromFile(filepath.Join(path, settingsFile))
helpers.Check(err, "unable to parse settings file")
return path, opts
set := opts["default"]
return path, &set
}

View File

@ -44,19 +44,23 @@ type Settings struct {
}
// FromFile reads a settings file in json format and returns the Settings struct
func FromFile(path string) (*Settings, error) {
func FromFile(path string) (map[string]Settings, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
var s Settings
s := make(map[string]Settings)
err = json.Unmarshal(data, &s)
if err != nil {
return nil, err
}
s.AbsolutePaths(filepath.Dir(path))
return &s, nil
for i := range s {
set := s[i]
set.AbsolutePaths(filepath.Dir(path))
s[i] = set
}
return s, nil
}
// AbsolutePaths makes all paths in settings absolute using the given