Move configuration code to seperate file

This commit is contained in:
2021-03-13 23:51:08 -06:00
parent ff05f8e2f3
commit 804ec99021
2 changed files with 32 additions and 27 deletions

32
cmd/config.go Normal file
View File

@ -0,0 +1,32 @@
package lumecmd
import (
"os"
"path"
)
const lumercFile string = ".lumerc"
func getConfigPath() string {
var tryPath, configPath string
// ~/.lumerc
homeDir, err := os.UserHomeDir()
if err == nil {
tryPath = path.Join(homeDir, lumercFile)
if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
configPath = tryPath
}
}
// ./.lumerc
cwd, err := os.Getwd()
if err == nil {
tryPath = path.Join(cwd, lumercFile)
if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
configPath = tryPath
}
}
return configPath
}