1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Creates the ~/.wtf directory. Displays a message if the config file is missing.

This commit is contained in:
Chris Cummer 2018-04-04 20:02:03 -07:00 committed by Chris Cummer
parent 71f8fc789f
commit 3c30bc4732
2 changed files with 41 additions and 15 deletions

21
wtf.go
View File

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

35
wtf/config_files.go Normal file
View File

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