Move configuration code to seperate file

This commit is contained in:
Ryan Cavicchioni 2021-03-13 23:51:08 -06:00
parent ff05f8e2f3
commit 804ec99021
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
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
}

View File

@ -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