Merge branch 'dev' of https://github.com/tockins/realize
This commit is contained in:
commit
dc26db7317
|
@ -1,6 +1,8 @@
|
||||||
package settings
|
package settings
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,7 +32,11 @@ type Resources struct {
|
||||||
|
|
||||||
// Read from the configuration file
|
// Read from the configuration file
|
||||||
func (s *Settings) Read(out interface{}) error {
|
func (s *Settings) Read(out interface{}) error {
|
||||||
content, err := s.Stream(s.Resources.Config)
|
localConfigPath := s.Resources.Config
|
||||||
|
if _, err := os.Stat(".realize/" + s.Resources.Config); err == nil {
|
||||||
|
localConfigPath = ".realize/" + s.Resources.Config
|
||||||
|
}
|
||||||
|
content, err := s.Stream(localConfigPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = yaml.Unmarshal(content, out)
|
err = yaml.Unmarshal(content, out)
|
||||||
return err
|
return err
|
||||||
|
@ -39,10 +45,13 @@ func (s *Settings) Read(out interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record create and unmarshal the yaml config file
|
// Record create and unmarshal the yaml config file
|
||||||
func (h *Settings) Record(out interface{}) error {
|
func (s *Settings) Record(out interface{}) error {
|
||||||
y, err := yaml.Marshal(out)
|
y, err := yaml.Marshal(out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return h.Write(h.Resources.Config, y)
|
if _, err := os.Stat(".realize/"); os.IsNotExist(err) {
|
||||||
|
os.Mkdir(".realize", 0770)
|
||||||
|
}
|
||||||
|
return s.Write(".realize/"+s.Resources.Config, y)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue