Skip to content

Commit

Permalink
WTF-400 CmdRunner extracted to new config format
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Cummer committed Apr 15, 2019
1 parent 3735667 commit 73e0e18
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
3 changes: 2 additions & 1 deletion main.go
Expand Up @@ -199,7 +199,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
cfg := clocks.NewSettingsFromYAML(wtf.Config)
widget = clocks.NewWidget(app, cfg)
case "cmdrunner":
widget = cmdrunner.NewWidget(app)
cfg := cmdrunner.NewSettingsFromYAML(wtf.Config)
widget = cmdrunner.NewWidget(app, cfg)
case "cryptolive":
widget = cryptolive.NewWidget(app)
case "datadog":
Expand Down
1 change: 0 additions & 1 deletion modules/bamboohr/widget.go
Expand Up @@ -2,7 +2,6 @@ package bamboohr

import (
"fmt"
// "os"

"github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf"
Expand Down
1 change: 0 additions & 1 deletion modules/circleci/widget.go
Expand Up @@ -2,7 +2,6 @@ package circleci

import (
"fmt"
// "os"

"github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf"
Expand Down
27 changes: 27 additions & 0 deletions modules/cmdrunner/settings.go
@@ -0,0 +1,27 @@
package cmdrunner

import (
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf"
)

type Settings struct {
common *cfg.Common

args []string
cmd string
}

func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
localConfig, _ := ymlConfig.Get("wtf.mods.cmdrunner")

settings := Settings{
common: cfg.NewCommonSettingsFromYAML(ymlConfig),

args: wtf.ToStrs(wtf.Config.UList("args")),
cmd: localConfig.UString("cmd"),
}

return &settings
}
14 changes: 8 additions & 6 deletions modules/cmdrunner/widget.go
Expand Up @@ -12,17 +12,19 @@ import (
type Widget struct {
wtf.TextWidget

args []string
cmd string
result string
args []string
cmd string
result string
settings *Settings
}

func NewWidget(app *tview.Application) *Widget {
func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(app, "CmdRunner", "cmdrunner", false),

args: wtf.ToStrs(wtf.Config.UList("wtf.mods.cmdrunner.args")),
cmd: wtf.Config.UString("wtf.mods.cmdrunner.cmd"),
args: settings.args,
cmd: settings.cmd,
settings: settings,
}

widget.View.SetWrap(true)
Expand Down

0 comments on commit 73e0e18

Please sign in to comment.