realize dir as const

This commit is contained in:
alessio 2017-04-16 12:02:47 +02:00
parent 8c73080db1
commit 01e3ee95b5
3 changed files with 44 additions and 25 deletions

View File

@ -17,7 +17,6 @@ import (
const (
appVersion = "1.3"
config = "realize.yaml"
outputs = "outputs.log"
errs = "errors.log"
@ -195,7 +194,7 @@ func main() {
Questions: []*interact.Question{
{
Before: func(d interact.Context) error {
if _, err := os.Stat(".realize/" + config); err != nil {
if _, err := os.Stat(settings.Dir + config); err != nil {
d.Skip()
}
d.SetDef(false, style.Green.Regular("(n)"))
@ -462,7 +461,25 @@ func main() {
if err != nil {
return d.Err()
}
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Fmt = val
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Cmds.Fmt = val
return nil
},
},
{
Before: func(d interact.Context) error {
d.SetDef(true, style.Green.Regular("(y)"))
return nil
},
Quest: interact.Quest{
Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable go vet",
},
Action: func(d interact.Context) interface{} {
val, err := d.Ans().Bool()
if err != nil {
return d.Err()
}
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Cmds.Vet = val
return nil
},
},
@ -480,7 +497,7 @@ func main() {
if err != nil {
return d.Err()
}
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Test = val
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Cmds.Test = val
return nil
},
},
@ -498,7 +515,7 @@ func main() {
if err != nil {
return d.Err()
}
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Generate = val
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Cmds.Generate = val
return nil
},
},
@ -516,7 +533,7 @@ func main() {
if err != nil {
return d.Err()
}
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Bin = val
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Cmds.Bin.Status = val
return nil
},
},
@ -534,7 +551,7 @@ func main() {
if err != nil {
return d.Err()
}
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Build = val
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Cmds.Build.Status = val
return nil
},
},
@ -552,7 +569,7 @@ func main() {
if err != nil {
return d.Err()
}
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Run = val
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Cmds.Run = val
return nil
},
},
@ -674,7 +691,7 @@ func main() {
if err != nil {
return d.Err()
}
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Params = append(r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Params, val)
r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Args = append(r.Blueprint.Projects[len(r.Blueprint.Projects)-1].Args, val)
d.Reload()
return nil
},

View File

@ -26,8 +26,8 @@ func (s Settings) Write(name string, data []byte) error {
// Create a new file and return its pointer
func (s Settings) Create(path string, name string) *os.File {
var file string
if _, err := os.Stat(".realize/"); err == nil {
file = filepath.Join(path, ".realize/", name)
if _, err := os.Stat(Dir); err == nil {
file = filepath.Join(path, Dir, name)
} else {
file = filepath.Join(path, name)
}

View File

@ -7,6 +7,8 @@ import (
yaml "gopkg.in/yaml.v2"
)
var Dir = ".realize/"
// Settings defines a group of general settings
type Settings struct {
Config `yaml:",inline" json:"config"`
@ -46,8 +48,8 @@ type Resources struct {
// Read from config file
func (s *Settings) Read(out interface{}) error {
localConfigPath := s.Resources.Config
if _, err := os.Stat(".realize/" + s.Resources.Config); err == nil {
localConfigPath = ".realize/" + s.Resources.Config
if _, err := os.Stat(Dir + s.Resources.Config); err == nil {
localConfigPath = Dir + s.Resources.Config
}
content, err := s.Stream(localConfigPath)
if err == nil {
@ -64,20 +66,20 @@ func (s *Settings) Record(out interface{}) error {
if err != nil {
return err
}
if _, err := os.Stat(".realize/"); os.IsNotExist(err) {
if err = os.Mkdir(".realize/", 0770); err != nil {
if _, err := os.Stat(Dir); os.IsNotExist(err) {
if err = os.Mkdir(Dir, 0770); err != nil {
return s.Write(s.Resources.Config, y)
}
}
return s.Write(".realize/"+s.Resources.Config, y)
return s.Write(Dir+s.Resources.Config, y)
}
return nil
}
// Remove realize folder
func (s *Settings) Remove() error {
if _, err := os.Stat(".realize/"); !os.IsNotExist(err) {
return os.RemoveAll(".realize/")
if _, err := os.Stat(Dir); !os.IsNotExist(err) {
return os.RemoveAll(Dir)
}
return nil
}