add get config dir

This commit is contained in:
Zack Scholl 2019-07-17 15:55:43 -06:00
parent 68ddbe7f14
commit f18c2eae7e
1 changed files with 9 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
@ -96,14 +97,19 @@ func Run() (err error) {
// return croc.SaveDefaultConfig() // return croc.SaveDefaultConfig()
// } // }
func makeConfigDir() (err error) { func getConfigDir() (homedir string, err error) {
homedir, err := os.UserHomeDir() homedir, err = os.UserHomeDir()
if err != nil { if err != nil {
log.Error(err) log.Error(err)
return return
} }
log.SetLevel("debug") log.SetLevel("debug")
log.Debugf("creating home directory %s", homedir) homedir = path.Join(homedir, ".config", "croc")
if _, err := os.Stat(homedir); os.IsNotExist(err) {
log.Debugf("creating home directory %s", homedir)
err = os.MkdirAll(homedir, 0700)
}
return return
} }