From c85ef3c8a03281f443470c7cd48ebc40aa466281 Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Thu, 15 Dec 2016 07:06:24 +0100 Subject: [PATCH 1/2] Store configuration in a .relaize subdirecotry --- settings/settings.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/settings/settings.go b/settings/settings.go index d956e21..68691d9 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -1,6 +1,8 @@ package settings import ( + "os" + "gopkg.in/yaml.v2" ) @@ -30,7 +32,11 @@ type Resources struct { // Read from the configuration file func (s *Settings) Read(out interface{}) error { - content, err := s.Stream(s.Resources.Config) + localConfigPath := s.Resources.Config + if _, err := os.Stat(".realize/"); err == nil { + localConfigPath = ".realize/" + s.Resources.Config + } + content, err := s.Stream(localConfigPath) if err == nil { err = yaml.Unmarshal(content, out) return err @@ -39,10 +45,13 @@ func (s *Settings) Read(out interface{}) error { } // 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) if err != nil { 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) } From b60885c42928304fba36c5f534dc72474f80448d Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Thu, 15 Dec 2016 07:11:20 +0100 Subject: [PATCH 2/2] Checking for full path of new config file location --- settings/settings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings/settings.go b/settings/settings.go index 68691d9..7b2e2e3 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -33,7 +33,7 @@ type Resources struct { // Read from the configuration file func (s *Settings) Read(out interface{}) error { localConfigPath := s.Resources.Config - if _, err := os.Stat(".realize/"); err == nil { + if _, err := os.Stat(".realize/" + s.Resources.Config); err == nil { localConfigPath = ".realize/" + s.Resources.Config } content, err := s.Stream(localConfigPath)