Compare commits

...

3 Commits

Author SHA1 Message Date
100b585663 Add ~/.config/lume/lume.conf to configuration file search paths 2021-03-31 00:19:03 -05:00
f0cf3e12b6 Declare variables at the top of function 2021-03-31 00:18:00 -05:00
ce5f14db5d Fix access token validation
The access token was not be validated when there were additional
validations errors with the named colors
2021-03-31 00:13:49 -05:00

View File

@@ -11,6 +11,7 @@ import (
)
const lumercFile string = ".lumerc"
const lumeConfigFile string = "lume.conf"
type Config struct {
AccessToken string `toml:"access_token"`
@@ -42,8 +43,9 @@ func GetConfig() *Config {
// Validate configuration struct
func (c *Config) Validate() error {
var err error
if c.AccessToken == "" {
err = errors.New("access_token is not set")
return errors.New("access_token is not set")
}
if err = c.validateColors(); err != nil {
@@ -109,10 +111,11 @@ func LoadConfigFile(configPath string) (*Config, error) {
}
func getConfigPath() string {
var tryPath, configPath string
var tryPath, configPath, homeDir, cwd string
var err error
// ~/.lumerc
homeDir, err := os.UserHomeDir()
homeDir, err = os.UserHomeDir()
if err == nil {
tryPath = path.Join(homeDir, lumercFile)
if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
@@ -120,8 +123,17 @@ func getConfigPath() string {
}
}
// ~/.config/lume/lume.conf
homeDir, err = os.UserHomeDir()
if err == nil {
tryPath = path.Join(homeDir, ".config/lume", lumeConfigFile)
if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
configPath = tryPath
}
}
// ./.lumerc
cwd, err := os.Getwd()
cwd, err = os.Getwd()
if err == nil {
tryPath = path.Join(cwd, lumercFile)
if _, err := os.Stat(tryPath); !os.IsNotExist(err) {