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

Accepts optional --config argument to specify a config file

This commit is contained in:
Chris Cummer 2018-04-15 14:41:39 -07:00 committed by Chris Cummer
parent c3abb76612
commit 0b20c4939e
2 changed files with 15 additions and 7 deletions

18
wtf.go
View File

@ -1,10 +1,12 @@
package main package main
import ( import (
"flag"
"os" "os"
"time" "time"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/olebedev/config"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/senorprogrammer/wtf/bamboohr" "github.com/senorprogrammer/wtf/bamboohr"
"github.com/senorprogrammer/wtf/gcal" "github.com/senorprogrammer/wtf/gcal"
@ -57,7 +59,7 @@ func buildGrid(modules []wtf.TextViewer) *tview.Grid {
func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
// Ctrl-R: force-refreshes every widget // Ctrl-R: force-refreshes every widget
if event.Key() == tcell.KeyCtrlR { if event.Key() == tcell.KeyCtrlR {
for _, module := range Modules { for _, module := range Widgets {
go module.Refresh() go module.Refresh()
} }
} }
@ -81,13 +83,19 @@ func refresher(app *tview.Application) {
} }
var result = wtf.CreateConfigDir() var result = wtf.CreateConfigDir()
var Config = wtf.LoadConfigFile()
var Modules []wtf.TextViewer var Config *config.Config
var Widgets []wtf.TextViewer
/* -------------------- Main -------------------- */ /* -------------------- Main -------------------- */
func main() { func main() {
// Optional argument to accept path to a config file
configFile := flag.String("config", "~/.wtf/config.yml", "Path to config file")
flag.Parse()
Config = wtf.LoadConfigFile(*configFile)
wtf.Config = Config wtf.Config = Config
bamboohr.Config = Config bamboohr.Config = Config
@ -102,7 +110,7 @@ func main() {
textfile.Config = Config textfile.Config = Config
weather.Config = Config weather.Config = Config
Modules = []wtf.TextViewer{ Widgets = []wtf.TextViewer{
bamboohr.NewWidget(), bamboohr.NewWidget(),
gcal.NewWidget(), gcal.NewWidget(),
git.NewWidget(), git.NewWidget(),
@ -122,7 +130,7 @@ func main() {
// Loop in a routine to redraw the screen // Loop in a routine to redraw the screen
go refresher(app) go refresher(app)
grid := buildGrid(Modules) grid := buildGrid(Widgets)
if err := app.SetRoot(grid, true).Run(); err != nil { if err := app.SetRoot(grid, true).Run(); err != nil {
os.Exit(1) os.Exit(1)
} }

View File

@ -22,8 +22,8 @@ func CreateConfigDir() bool {
} }
// LoadConfigFile loads the config.yml file to configure the app // LoadConfigFile loads the config.yml file to configure the app
func LoadConfigFile() *config.Config { func LoadConfigFile(filePath string) *config.Config {
absPath, _ := homedir.Expand("~/.wtf/config.yml") absPath, _ := homedir.Expand(filePath)
cfg, err := config.ParseYamlFile(absPath) cfg, err := config.ParseYamlFile(absPath)
if err != nil { if err != nil {