dir removed

This commit is contained in:
asoseil 2017-12-02 18:38:17 +01:00
parent 578d0bcbae
commit 894493584e
4 changed files with 15 additions and 31 deletions

View File

@ -113,9 +113,9 @@ func version() {
log.Println(r.Prefix(realize.Green.Bold(realize.RVersion))) log.Println(r.Prefix(realize.Green.Bold(realize.RVersion)))
} }
// Clean remove realize folder // Clean remove realize file
func clean() (err error) { func clean() (err error) {
if err := r.Settings.Remove(realize.RDir); err != nil { if err := r.Settings.Remove(realize.RFile); err != nil {
return err return err
} }
log.Println(r.Prefix(realize.Green.Bold("folder successfully removed"))) log.Println(r.Prefix(realize.Green.Bold("folder successfully removed")))
@ -156,7 +156,7 @@ func setup(c *cli.Context) (err error) {
Questions: []*interact.Question{ Questions: []*interact.Question{
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
if _, err := os.Stat(realize.RDir + "/" + realize.RFile); err != nil { if _, err := os.Stat(realize.RFile); err != nil {
d.Skip() d.Skip()
} }
d.SetDef(false, realize.Green.Regular("(n)")) d.SetDef(false, realize.Green.Regular("(n)"))
@ -1139,7 +1139,7 @@ func setup(c *cli.Context) (err error) {
}, },
After: func(d interact.Context) error { After: func(d interact.Context) error {
if val, _ := d.Qns().Get(0).Ans().Bool(); val { if val, _ := d.Qns().Get(0).Ans().Bool(); val {
err := r.Settings.Remove(realize.RDir) err := r.Settings.Remove(realize.RFile)
if err != nil { if err != nil {
return err return err
} }

View File

@ -20,9 +20,7 @@ const (
// RExt file extension // RExt file extension
RExt = ".yaml" RExt = ".yaml"
// RFile config file name // RFile config file name
RFile = RPrefix + RExt RFile = "." + RPrefix + RExt
// RDir config dir
RDir = "." + RPrefix
//RExtWin windows extension //RExtWin windows extension
RExtWin = ".exe" RExtWin = ".exe"
) )

View File

@ -12,7 +12,7 @@ import (
"time" "time"
) )
func TestProject_After(t *testing.T) { func TestProject_After(t *testing.T) /**/{
var buf bytes.Buffer var buf bytes.Buffer
log.SetOutput(&buf) log.SetOutput(&buf)
r := Realize{} r := Realize{}

View File

@ -13,10 +13,10 @@ import (
// settings const // settings const
const ( const (
Permission = 0775 Permission = 0775
File = "realize.yaml" File = ".realize.yaml"
FileOut = "outputs.log" FileOut = ".r.outputs.log"
FileErr = "errors.log" FileErr = ".r.errors.log"
FileLog = "logs.log" FileLog = ".r.logs.log"
) )
// random string preference // random string preference
@ -84,15 +84,11 @@ func (s *Settings) Remove(d string) error {
// Read config file // Read config file
func (s *Settings) Read(out interface{}) error { func (s *Settings) Read(out interface{}) error {
localConfigPath := RFile
// backward compatibility // backward compatibility
path := filepath.Join(RDir, RFile) if _, err := os.Stat(RFile); err != nil {
if _, err := os.Stat(path); err == nil { return err
localConfigPath = path
} else {
return nil
} }
content, err := s.Stream(localConfigPath) content, err := s.Stream(RFile)
if err == nil { if err == nil {
err = yaml.Unmarshal(content, out) err = yaml.Unmarshal(content, out)
return err return err
@ -106,12 +102,7 @@ func (s *Settings) Write(out interface{}) error {
if err != nil { if err != nil {
return err return err
} }
if _, err := os.Stat(RDir); os.IsNotExist(err) { s.Fatal(ioutil.WriteFile(RFile, y, Permission))
if err = os.Mkdir(RDir, Permission); err != nil {
s.Fatal(ioutil.WriteFile(RFile, y, Permission))
}
}
s.Fatal(ioutil.WriteFile(filepath.Join(RDir, RFile), y, Permission))
return nil return nil
} }
@ -139,12 +130,7 @@ func (s Settings) Fatal(err error, msg ...interface{}) {
// 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 file := filepath.Join(path, name)
if _, err := os.Stat(RDir); err == nil {
file = filepath.Join(path, RDir, name)
} else {
file = filepath.Join(path, name)
}
out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_SYNC, Permission) out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_SYNC, Permission)
s.Fatal(err) s.Fatal(err)
return out return out