diff --git a/cmd/config.go b/cmd/config.go new file mode 100644 index 0000000..0fb1d32 --- /dev/null +++ b/cmd/config.go @@ -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 +} diff --git a/cmd/main.go b/cmd/main.go index 4b698d4..a49dee8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "os" - "path" "strings" "git.kill0.net/chill9/lifx-go" @@ -33,8 +32,6 @@ var Version string var BuildDate string var GitCommit string -const lumercFile string = ".lumerc" - func Main(args []string) (int, error) { var config Config var err error @@ -99,30 +96,6 @@ func Main(args []string) (int, error) { return exitCode, err } -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 -} - func initUserAgent() string { var b strings.Builder