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,14 +17,13 @@ import (
const ( const (
appVersion = "1.3" appVersion = "1.3"
config = "realize.yaml"
config = "realize.yaml" outputs = "outputs.log"
outputs = "outputs.log" errs = "errors.log"
errs = "errors.log" logs = "logs.log"
logs = "logs.log" host = "localhost"
host = "localhost" port = 5001
port = 5001 interval = 200
interval = 200
) )
// Cli commands // Cli commands
@ -195,7 +194,7 @@ func main() {
Questions: []*interact.Question{ Questions: []*interact.Question{
{ {
Before: func(d interact.Context) error { 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.Skip()
} }
d.SetDef(false, style.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
@ -462,7 +461,25 @@ func main() {
if err != nil { if err != nil {
return d.Err() 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 return nil
}, },
}, },
@ -480,7 +497,7 @@ func main() {
if err != nil { if err != nil {
return d.Err() 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 return nil
}, },
}, },
@ -498,7 +515,7 @@ func main() {
if err != nil { if err != nil {
return d.Err() 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 return nil
}, },
}, },
@ -516,7 +533,7 @@ func main() {
if err != nil { if err != nil {
return d.Err() 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 return nil
}, },
}, },
@ -534,7 +551,7 @@ func main() {
if err != nil { if err != nil {
return d.Err() 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 return nil
}, },
}, },
@ -552,7 +569,7 @@ func main() {
if err != nil { if err != nil {
return d.Err() 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 return nil
}, },
}, },
@ -674,7 +691,7 @@ func main() {
if err != nil { if err != nil {
return d.Err() 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() d.Reload()
return nil 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 // Create a new file and return its pointer
func (s Settings) Create(path string, name string) *os.File { func (s Settings) Create(path string, name string) *os.File {
var file string var file string
if _, err := os.Stat(".realize/"); err == nil { if _, err := os.Stat(Dir); err == nil {
file = filepath.Join(path, ".realize/", name) file = filepath.Join(path, Dir, name)
} else { } else {
file = filepath.Join(path, name) file = filepath.Join(path, name)
} }

View File

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