From 804ec99021c94342330d4fc26c3b05da25de7c68 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sat, 13 Mar 2021 23:51:08 -0600 Subject: [PATCH] Move configuration code to seperate file --- cmd/config.go | 32 ++++++++++++++++++++++++++++++++ cmd/main.go | 27 --------------------------- 2 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 cmd/config.go 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