Skip to content

Commit d6a0797

Browse files
Simplify the inclusion of the Common config settings into each module
Signed-off-by: Chris Cummer <chriscummer@me.com>
1 parent f9a0654 commit d6a0797

File tree

161 files changed

+378
-330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+378
-330
lines changed

cfg/common_settings.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ type Common struct {
2828
PositionSettings `help:"Defines where in the grid this module’s widget will be displayed."`
2929
Sigils
3030

31-
Colors ColorTheme
31+
Colors ColorTheme
32+
Config *config.Config
33+
34+
DocPath string
35+
3236
Bordered bool `help:"Whether or not the module should be displayed with a border." values:"true, false" optional:"true" default:"true"`
3337
Enabled bool `help:"Whether or not this module is executed and if its data displayed onscreen." values:"true, false" optional:"true" default:"false"`
3438
Focusable bool `help:"Whether or not this module is focusable." values:"true, false" optional:"true" default:"false"`
3539
RefreshInterval int `help:"How often, in seconds, this module will update its data." values:"A positive integer, 0..n." optional:"true"`
3640
Title string `help:"The title string to show when displaying this module" optional:"true"`
37-
Config *config.Config
3841

3942
focusChar int `help:"Define one of the number keys as a short cut key to access the widget." optional:"true"`
4043
}
@@ -167,6 +170,15 @@ func (common *Common) PaginationMarker(len, pos, width int) string {
167170
return sigils
168171
}
169172

173+
// SetDocumentationPath is used to explicitly set the documentation path that should be opened
174+
// when the key to open the documentation is pressed.
175+
// Setting this is probably not necessary unless the module documentation is nested inside a
176+
// documentation subdirectory in the /wtfutildocs repo, or the module here has a different
177+
// name than the module's display name in the documentation (which ideally wouldn't be a thing).
178+
func (common *Common) SetDocumentationPath(path string) {
179+
common.DocPath = path
180+
}
181+
170182
// Validations aggregates all the validations from all the sub-sections in Common into a
171183
// single array of validations
172184
func (common *Common) Validations() []Validatable {

modules/azuredevops/settings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const (
1414

1515
// Settings defines the configuration options for this module
1616
type Settings struct {
17-
common *cfg.Common
17+
*cfg.Common
1818

1919
apiToken string `help:"Your Azure DevOps Access Token."`
2020
labelColor string
@@ -26,7 +26,7 @@ type Settings struct {
2626
// NewSettingsFromYAML creates and returns an instance of Settings with configuration options populated
2727
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
2828
settings := Settings{
29-
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocus, ymlConfig, globalConfig),
29+
Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocus, ymlConfig, globalConfig),
3030

3131
apiToken: ymlConfig.UString("apiToken", os.Getenv("WTF_AZURE_DEVOPS_API_TOKEN")),
3232
labelColor: ymlConfig.UString("labelColor", "white"),

modules/azuredevops/widget.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Widget struct {
2121

2222
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
2323
widget := Widget{
24-
TextWidget: view.NewTextWidget(app, pages, settings.common),
24+
TextWidget: view.NewTextWidget(app, pages, settings.Common),
2525
settings: settings,
2626
}
2727

modules/bamboohr/settings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ const (
1313
)
1414

1515
type Settings struct {
16-
common *cfg.Common
16+
*cfg.Common
1717

1818
apiKey string `help:"Your BambooHR API token."`
1919
subdomain string `help:"Your BambooHR API subdomain name."`
2020
}
2121

2222
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
2323
settings := Settings{
24-
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
24+
Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
2525

2626
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_BAMBOO_HR_TOKEN"))),
2727
subdomain: ymlConfig.UString("subdomain", os.Getenv("WTF_BAMBOO_HR_SUBDOMAIN")),

modules/bamboohr/widget.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Widget struct {
2121

2222
func NewWidget(app *tview.Application, settings *Settings) *Widget {
2323
widget := Widget{
24-
TextWidget: view.NewTextWidget(app, nil, settings.common),
24+
TextWidget: view.NewTextWidget(app, nil, settings.Common),
2525

2626
settings: settings,
2727
}

modules/bargraph/settings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ const (
1111
)
1212

1313
type Settings struct {
14-
common *cfg.Common
14+
*cfg.Common
1515
}
1616

1717
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
1818
settings := Settings{
19-
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
19+
Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
2020
}
2121

2222
return &settings

modules/bargraph/widget.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Widget struct {
2323
// NewWidget Make new instance of widget
2424
func NewWidget(app *tview.Application, settings *Settings) *Widget {
2525
widget := Widget{
26-
BarGraph: view.NewBarGraph(app, "Sample Bar Graph", settings.common),
26+
BarGraph: view.NewBarGraph(app, "Sample Bar Graph", settings.Common),
2727

2828
app: app,
2929
}

modules/buildkite/settings.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ type PipelineSettings struct {
2121

2222
// Settings defines the configuration properties for this module
2323
type Settings struct {
24-
common *cfg.Common
24+
*cfg.Common
25+
2526
apiKey string `help:"Your Buildkite API Token"`
2627
orgSlug string `help:"Organization Slug"`
2728
pipelines []PipelineSettings `help:"An array of pipelines to get data from"`
@@ -30,7 +31,8 @@ type Settings struct {
3031
// NewSettingsFromYAML creates a new settings instance from a YAML config block
3132
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
3233
settings := Settings{
33-
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
34+
Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
35+
3436
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_BUILDKITE_TOKEN")),
3537
orgSlug: ymlConfig.UString("organizationSlug"),
3638
pipelines: buildPipelineSettings(ymlConfig),

modules/buildkite/widget.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Widget struct {
1717

1818
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
1919
widget := Widget{
20-
TextWidget: view.NewTextWidget(app, pages, settings.common),
20+
TextWidget: view.NewTextWidget(app, pages, settings.Common),
2121
settings: settings,
2222
}
2323

modules/cds/favorites/display.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (widget *Widget) content() (string, string, bool) {
2525
}
2626

2727
_, _, width, _ := widget.View.GetRect()
28-
str := widget.settings.common.PaginationMarker(len(widget.workflows), widget.Idx, width) + "\n"
28+
str := widget.settings.PaginationMarker(len(widget.workflows), widget.Idx, width) + "\n"
2929
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(workflow))
3030

3131
str += widget.displayWorkflowRuns(workflow)
@@ -36,7 +36,7 @@ func (widget *Widget) content() (string, string, bool) {
3636
func (widget *Widget) title(workflow *sdk.Workflow) string {
3737
return fmt.Sprintf(
3838
"[%s]%s/%s[white]",
39-
widget.settings.common.Colors.TextTheme.Title,
39+
widget.settings.Colors.TextTheme.Title,
4040
workflow.ProjectKey, workflow.Name,
4141
)
4242
}

0 commit comments

Comments
 (0)