Skip to content

Commit

Permalink
Merge pull request #31 from lpxxn/refact_code
Browse files Browse the repository at this point in the history
Refact code
  • Loading branch information
lpxxn authored Jun 30, 2021
2 parents 8e0761f + fbf1039 commit 653a2a3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func (a *AppConfig) parseCmdConfig() error {
}
return nil
}

func configNotExist() error {
return NotExistErr
}
10 changes: 4 additions & 6 deletions config/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path"

"github.com/BurntSushi/toml"
"github.com/skratchdot/open-golang/open"
"github.com/lpxxn/doraemon/internal"
)

const (
Expand Down Expand Up @@ -45,15 +45,13 @@ func ConfDir() string {
panic(err)
}
dirPath := path.Join(rootDir, confDirName)
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
if err = os.MkdirAll(dirPath, os.ModePerm); err != nil {
panic(err)
}
if err := internal.MakeFolder(dirPath, os.ModePerm); err != nil {
panic(err)
}
return dirPath
}
func OpenConfDir() error {
return open.Run(ConfDir())
return internal.OpenFolder(ConfDir())
}

func WritTomlToConfig(v interface{}) error {
Expand Down
15 changes: 15 additions & 0 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package internal

import (
"fmt"
"os"

"github.com/skratchdot/open-golang/open"
)

type Color string
Expand Down Expand Up @@ -67,3 +70,15 @@ func SendMsg(startWithNewLine bool, caption, text string, color Color, endWithNe
fmt.Println(startNewLine + BeautifyText(caption, color) + " " + text + endNewLine) // colorized text
}
}

func MakeFolder(folderName string, chmod os.FileMode) error {
if _, err := os.Stat(folderName); os.IsNotExist(err) {
return os.MkdirAll(folderName, chmod)
} else {
return err
}
}

func OpenFolder(folderName string) error {
return open.Run(folderName)
}

0 comments on commit 653a2a3

Please sign in to comment.