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

View File

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

View File

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

View File

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