Move configuration code to seperate file
This commit is contained in:
32
cmd/config.go
Normal file
32
cmd/config.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user