diff --git a/wtf.go b/wtf.go index fa7c83f4..bb8f120a 100644 --- a/wtf.go +++ b/wtf.go @@ -3,13 +3,11 @@ package main import ( "time" - "github.com/olebedev/config" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/bamboohr" "github.com/senorprogrammer/wtf/gcal" "github.com/senorprogrammer/wtf/git" "github.com/senorprogrammer/wtf/github" - "github.com/senorprogrammer/wtf/homedir" "github.com/senorprogrammer/wtf/jira" "github.com/senorprogrammer/wtf/opsgenie" "github.com/senorprogrammer/wtf/security" @@ -18,19 +16,6 @@ import ( "github.com/senorprogrammer/wtf/wtf" ) -var Config = loadConfig() - -func loadConfig() *config.Config { - configPath, _ := homedir.Expand("~/.wtf/config.yml") - - cfg, err := config.ParseYamlFile(configPath) - if err != nil { - panic(err) - } - - return cfg -} - func refresher(stat *status.Widget, app *tview.Application) { tick := time.NewTicker(time.Duration(Config.UInt("wtf.refreshInterval", 1)) * time.Second) quit := make(chan struct{}) @@ -46,7 +31,13 @@ func refresher(stat *status.Widget, app *tview.Application) { } } +var result = wtf.CreateConfigDir() +var Config = wtf.LoadConfigFile() + +/* -------------------- Main -------------------- */ + func main() { + bamboohr.Config = Config bamboo := bamboohr.NewWidget() bamboo.Refresh() diff --git a/wtf/config_files.go b/wtf/config_files.go new file mode 100644 index 00000000..040e0773 --- /dev/null +++ b/wtf/config_files.go @@ -0,0 +1,35 @@ +package wtf + +import ( + "fmt" + "os" + + "github.com/olebedev/config" + "github.com/senorprogrammer/wtf/homedir" +) + +// CreateConfigDir creates the .wtf directory in the user's home dir +func CreateConfigDir() bool { + homeDir, _ := homedir.Expand("~/.wtf/") + + if _, err := os.Stat(homeDir); os.IsNotExist(err) { + err := os.Mkdir(homeDir, os.ModePerm) + if err != nil { + panic(err) + } + } + return true +} + +// LoadConfigFile loads the config.yml file to configure the app +func LoadConfigFile() *config.Config { + configPath, _ := homedir.Expand("~/.wtf/config.yml") + + cfg, err := config.ParseYamlFile(configPath) + if err != nil { + fmt.Println("\n\n\033[1m ERROR:\033[0m Could not load '\033[0;33mconfig.yml\033[0m'.\n Please add a \033[0;33mconfig.yml\033[0m file to your \033[0;33m~/.wtf\033[0m directory.\n See \033[1;34mhttps://github.com/senorprogrammer/wtf\033[0m for details.\n\n") + os.Exit(1) + } + + return cfg +}