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:
parent
c3abb76612
commit
0b20c4939e
18
wtf.go
18
wtf.go
@ -1,10 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/olebedev/config"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/senorprogrammer/wtf/bamboohr"
|
||||
"github.com/senorprogrammer/wtf/gcal"
|
||||
@ -57,7 +59,7 @@ func buildGrid(modules []wtf.TextViewer) *tview.Grid {
|
||||
func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
// Ctrl-R: force-refreshes every widget
|
||||
if event.Key() == tcell.KeyCtrlR {
|
||||
for _, module := range Modules {
|
||||
for _, module := range Widgets {
|
||||
go module.Refresh()
|
||||
}
|
||||
}
|
||||
@ -81,13 +83,19 @@ func refresher(app *tview.Application) {
|
||||
}
|
||||
|
||||
var result = wtf.CreateConfigDir()
|
||||
var Config = wtf.LoadConfigFile()
|
||||
|
||||
var Modules []wtf.TextViewer
|
||||
var Config *config.Config
|
||||
var Widgets []wtf.TextViewer
|
||||
|
||||
/* -------------------- 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
|
||||
|
||||
bamboohr.Config = Config
|
||||
@ -102,7 +110,7 @@ func main() {
|
||||
textfile.Config = Config
|
||||
weather.Config = Config
|
||||
|
||||
Modules = []wtf.TextViewer{
|
||||
Widgets = []wtf.TextViewer{
|
||||
bamboohr.NewWidget(),
|
||||
gcal.NewWidget(),
|
||||
git.NewWidget(),
|
||||
@ -122,7 +130,7 @@ func main() {
|
||||
// Loop in a routine to redraw the screen
|
||||
go refresher(app)
|
||||
|
||||
grid := buildGrid(Modules)
|
||||
grid := buildGrid(Widgets)
|
||||
if err := app.SetRoot(grid, true).Run(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ func CreateConfigDir() bool {
|
||||
}
|
||||
|
||||
// LoadConfigFile loads the config.yml file to configure the app
|
||||
func LoadConfigFile() *config.Config {
|
||||
absPath, _ := homedir.Expand("~/.wtf/config.yml")
|
||||
func LoadConfigFile(filePath string) *config.Config {
|
||||
absPath, _ := homedir.Expand(filePath)
|
||||
|
||||
cfg, err := config.ParseYamlFile(absPath)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user