Compare commits
3 Commits
9b20413d64
...
100b585663
Author | SHA1 | Date | |
---|---|---|---|
100b585663
|
|||
f0cf3e12b6
|
|||
ce5f14db5d
|
@@ -11,6 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const lumercFile string = ".lumerc"
|
const lumercFile string = ".lumerc"
|
||||||
|
const lumeConfigFile string = "lume.conf"
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AccessToken string `toml:"access_token"`
|
AccessToken string `toml:"access_token"`
|
||||||
@@ -42,8 +43,9 @@ func GetConfig() *Config {
|
|||||||
// Validate configuration struct
|
// Validate configuration struct
|
||||||
func (c *Config) Validate() error {
|
func (c *Config) Validate() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if c.AccessToken == "" {
|
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 {
|
if err = c.validateColors(); err != nil {
|
||||||
@@ -109,10 +111,11 @@ func LoadConfigFile(configPath string) (*Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getConfigPath() string {
|
func getConfigPath() string {
|
||||||
var tryPath, configPath string
|
var tryPath, configPath, homeDir, cwd string
|
||||||
|
var err error
|
||||||
|
|
||||||
// ~/.lumerc
|
// ~/.lumerc
|
||||||
homeDir, err := os.UserHomeDir()
|
homeDir, err = os.UserHomeDir()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tryPath = path.Join(homeDir, lumercFile)
|
tryPath = path.Join(homeDir, lumercFile)
|
||||||
if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
|
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
|
// ./.lumerc
|
||||||
cwd, err := os.Getwd()
|
cwd, err = os.Getwd()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tryPath = path.Join(cwd, lumercFile)
|
tryPath = path.Join(cwd, lumercFile)
|
||||||
if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
|
if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
|
||||||
|
Reference in New Issue
Block a user