37 lines
856 B
Go
37 lines
856 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/kyoh86/xdg"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
const (
|
|
configFileBase = "harmon.conf"
|
|
configFileBaseAlt = "harmon.cfg"
|
|
)
|
|
|
|
func findConfigFile() string {
|
|
var name string
|
|
for _, dir := range append(xdg.AllConfigDirs(), ".") {
|
|
// Base
|
|
name = filepath.Join(dir, configFileBase)
|
|
logrus.WithField("name", name).Trace("auto detecting configuration file")
|
|
if i, err := os.Stat(name); err == nil && !i.IsDir() {
|
|
logrus.WithField("name", name).Trace("found configuration file")
|
|
return name
|
|
}
|
|
|
|
// Alt
|
|
name = filepath.Join(dir, configFileBaseAlt)
|
|
logrus.WithField("name", name).Trace("auto detecting configuration file")
|
|
if i, err := os.Stat(name); err == nil && !i.IsDir() {
|
|
logrus.WithField("name", name).Trace("found configuration file")
|
|
return name
|
|
}
|
|
}
|
|
return ""
|
|
}
|