From eb5f09e65ca8a4eca41449721079ad349ed492c6 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 14:59:22 -0700 Subject: [PATCH] Properly scope Config to the wtf package and remove it as a dependency from everywhere else --- bamboohr/widget.go | 4 ---- bargraph/widget.go | 4 ---- circleci/build.go | 12 +++++----- circleci/widget.go | 20 +++++------------ clocks/clock_collection.go | 4 +++- clocks/widget.go | 6 +---- cmdrunner/widget.go | 10 +++------ cryptoexchanges/bittrex/widget.go | 20 +++++++---------- cryptoexchanges/blockfolio/widget.go | 14 +++++------- cryptoexchanges/cryptolive/widget.go | 18 ++++++--------- gcal/client.go | 9 ++++---- gcal/widget.go | 24 +++++++++----------- git/git_repo.go | 6 ++--- git/widget.go | 6 +---- github/display.go | 4 ++-- github/widget.go | 6 +---- gitlab/display.go | 4 ++-- gitlab/widget.go | 8 ++----- gspreadsheets/client.go | 6 ++--- gspreadsheets/widget.go | 8 ++----- ipaddresses/ipapi/widget.go | 6 +---- ipaddresses/ipinfo/widget.go | 6 +---- jenkins/view.go | 12 +++++----- jenkins/widget.go | 13 +++++------ jira/client.go | 18 ++++++++------- jira/widget.go | 16 +++++++------- newrelic/client.go | 5 +++-- newrelic/widget.go | 6 +---- opsgenie/widget.go | 6 +---- power/widget.go | 4 ---- security/widget.go | 4 ---- security/widget_windows.go | 4 ---- status/widget.go | 4 ---- system/widget.go | 4 ---- textfile/widget.go | 6 +---- todo/display.go | 8 +++---- todo/item.go | 6 ++++- todo/widget.go | 6 +---- weatherservices/prettyweather/widget.go | 10 +++------ weatherservices/weather/display.go | 4 ++-- weatherservices/weather/widget.go | 12 +++++----- wtf.go | 29 ------------------------- 42 files changed, 128 insertions(+), 254 deletions(-) diff --git a/bamboohr/widget.go b/bamboohr/widget.go index 1e9eb751..3d38946d 100644 --- a/bamboohr/widget.go +++ b/bamboohr/widget.go @@ -3,13 +3,9 @@ package bamboohr import ( "fmt" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget } diff --git a/bargraph/widget.go b/bargraph/widget.go index 0e798952..1b2b6ab4 100644 --- a/bargraph/widget.go +++ b/bargraph/widget.go @@ -8,13 +8,9 @@ import ( "math/rand" "time" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - var started = false var ok = true diff --git a/circleci/build.go b/circleci/build.go index f0ee6cab..270befc2 100644 --- a/circleci/build.go +++ b/circleci/build.go @@ -1,10 +1,10 @@ package circleci type Build struct { - AuthorEmail string `json:"author_email"` - AuthorName string `json:"author_name"` - Branch string `json:"branch"` - BuildNum int `json:"build_num"` - Reponame string `json:"reponame"` - Status string `json:"status"` + AuthorEmail string `json:"author_email"` + AuthorName string `json:"author_name"` + Branch string `json:"branch"` + BuildNum int `json:"build_num"` + Reponame string `json:"reponame"` + Status string `json:"status"` } diff --git a/circleci/widget.go b/circleci/widget.go index 0e3d6a28..e15cc5fd 100644 --- a/circleci/widget.go +++ b/circleci/widget.go @@ -2,13 +2,9 @@ package circleci import ( "fmt" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget } @@ -65,19 +61,15 @@ func (widget *Widget) contentFrom(builds []*Build) string { return str } -func buildColor(b *Build) string { - var color string - - switch b.Status { +func buildColor(build *Build) string { + switch build.Status { case "failed": - color = "red" + return "red" case "running": - color = "yellow" + return "yellow" case "success": - color = "green" + return "green" default: - color = "white" + return "white" } - - return color } diff --git a/clocks/clock_collection.go b/clocks/clock_collection.go index a1c226ea..c1ce1a1c 100644 --- a/clocks/clock_collection.go +++ b/clocks/clock_collection.go @@ -3,6 +3,8 @@ package clocks import ( "sort" "time" + + "github.com/senorprogrammer/wtf/wtf" ) type ClockCollection struct { @@ -10,7 +12,7 @@ type ClockCollection struct { } func (clocks *ClockCollection) Sorted() []Clock { - if "chronological" == Config.UString("wtf.mods.clocks.sort", "alphabetical") { + if "chronological" == wtf.Config.UString("wtf.mods.clocks.sort", "alphabetical") { clocks.SortedChronologically() } else { clocks.SortedAlphabetically() diff --git a/clocks/widget.go b/clocks/widget.go index d6d6ee2a..551ebda7 100644 --- a/clocks/widget.go +++ b/clocks/widget.go @@ -3,13 +3,9 @@ package clocks import ( "time" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget @@ -21,7 +17,7 @@ func NewWidget() *Widget { TextWidget: wtf.NewTextWidget(" World Clocks ", "clocks", false), } - widget.clockColl = widget.buildClockCollection(Config.UMap("wtf.mods.clocks.locations")) + widget.clockColl = widget.buildClockCollection(wtf.Config.UMap("wtf.mods.clocks.locations")) return &widget } diff --git a/cmdrunner/widget.go b/cmdrunner/widget.go index c1460a16..1a28308e 100644 --- a/cmdrunner/widget.go +++ b/cmdrunner/widget.go @@ -5,13 +5,9 @@ import ( "os/exec" "strings" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget @@ -24,8 +20,8 @@ func NewWidget() *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(" CmdRunner ", "cmdrunner", false), - args: wtf.ToStrs(Config.UList("wtf.mods.cmdrunner.args")), - cmd: Config.UString("wtf.mods.cmdrunner.cmd"), + args: wtf.ToStrs(wtf.Config.UList("wtf.mods.cmdrunner.args")), + cmd: wtf.Config.UString("wtf.mods.cmdrunner.cmd"), } widget.View.SetWrap(true) @@ -37,7 +33,7 @@ func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() widget.execute() - title := Config.UString("wtf.mods.cmdrunner.title", widget.String()) + title := wtf.Config.UString("wtf.mods.cmdrunner.title", widget.String()) widget.View.SetTitle(fmt.Sprintf("%s", title)) widget.View.SetText(fmt.Sprintf("%s", widget.result)) diff --git a/cryptoexchanges/bittrex/widget.go b/cryptoexchanges/bittrex/widget.go index 7bbf1003..c5892733 100644 --- a/cryptoexchanges/bittrex/widget.go +++ b/cryptoexchanges/bittrex/widget.go @@ -7,13 +7,9 @@ import ( "net/http" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type TextColors struct { base struct { name string @@ -55,17 +51,17 @@ func NewWidget() *Widget { } func (widget *Widget) config() { - widget.TextColors.base.name = Config.UString("wtf.mods.bittrex.colors.base.name", "red") - widget.TextColors.base.displayName = Config.UString("wtf.mods.bittrex.colors.base.displayName", "grey") - widget.TextColors.market.name = Config.UString("wtf.mods.bittrex.colors.market.name", "red") - widget.TextColors.market.field = Config.UString("wtf.mods.bittrex.colors.market.field", "coral") - widget.TextColors.market.value = Config.UString("wtf.mods.bittrex.colors.market.value", "white") + widget.TextColors.base.name = wtf.Config.UString("wtf.mods.bittrex.colors.base.name", "red") + widget.TextColors.base.displayName = wtf.Config.UString("wtf.mods.bittrex.colors.base.displayName", "grey") + widget.TextColors.market.name = wtf.Config.UString("wtf.mods.bittrex.colors.market.name", "red") + widget.TextColors.market.field = wtf.Config.UString("wtf.mods.bittrex.colors.market.field", "coral") + widget.TextColors.market.value = wtf.Config.UString("wtf.mods.bittrex.colors.market.value", "white") } func (widget *Widget) setSummaryList() { - sCurrencies, _ := Config.Map("wtf.mods.bittrex.summary") + sCurrencies, _ := wtf.Config.Map("wtf.mods.bittrex.summary") for baseCurrencyName := range sCurrencies { - displayName, _ := Config.String("wtf.mods.bittrex.summary." + baseCurrencyName + ".displayName") + displayName, _ := wtf.Config.String("wtf.mods.bittrex.summary." + baseCurrencyName + ".displayName") mCurrencyList := makeSummaryMarketList(baseCurrencyName) widget.summaryList.addSummaryItem(baseCurrencyName, displayName, mCurrencyList) } @@ -74,7 +70,7 @@ func (widget *Widget) setSummaryList() { func makeSummaryMarketList(currencyName string) []*mCurrency { mCurrencyList := []*mCurrency{} - configMarketList, _ := Config.List("wtf.mods.bittrex.summary." + currencyName + ".market") + configMarketList, _ := wtf.Config.List("wtf.mods.bittrex.summary." + currencyName + ".market") for _, mCurrencyName := range configMarketList { mCurrencyList = append(mCurrencyList, makeMarketCurrency(mCurrencyName.(string))) } diff --git a/cryptoexchanges/blockfolio/widget.go b/cryptoexchanges/blockfolio/widget.go index 968cd7f1..ac7b2440 100644 --- a/cryptoexchanges/blockfolio/widget.go +++ b/cryptoexchanges/blockfolio/widget.go @@ -7,14 +7,10 @@ import ( "log" "net/http" - "github.com/olebedev/config" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget @@ -25,7 +21,7 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(" Blockfolio ", "blockfolio", false), - device_token: Config.UString("wtf.mods.blockfolio.device_token"), + device_token: wtf.Config.UString("wtf.mods.blockfolio.device_token"), } return &widget @@ -47,10 +43,10 @@ func (widget *Widget) Refresh() { /* -------------------- Unexported Functions -------------------- */ func contentFrom(positions *AllPositionsResponse) string { res := "" - colorName := Config.UString("wtf.mods.blockfolio.colors.name") - colorGrows := Config.UString("wtf.mods.blockfolio.colors.grows") - colorDrop := Config.UString("wtf.mods.blockfolio.colors.drop") - displayHoldings := Config.UBool("wtf.mods.blockfolio.displayHoldings") + colorName := wtf.Config.UString("wtf.mods.blockfolio.colors.name") + colorGrows := wtf.Config.UString("wtf.mods.blockfolio.colors.grows") + colorDrop := wtf.Config.UString("wtf.mods.blockfolio.colors.drop") + displayHoldings := wtf.Config.UBool("wtf.mods.blockfolio.displayHoldings") var totalFiat float32 totalFiat = 0.0 for i := 0; i < len(positions.PositionList); i++ { diff --git a/cryptoexchanges/cryptolive/widget.go b/cryptoexchanges/cryptolive/widget.go index daaefa0e..cb2b98f4 100644 --- a/cryptoexchanges/cryptolive/widget.go +++ b/cryptoexchanges/cryptolive/widget.go @@ -6,13 +6,9 @@ import ( "net/http" "time" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - var baseURL = "https://min-api.cryptocompare.com/data/price" var ok = true @@ -56,10 +52,10 @@ func (widget *Widget) Refresh() { func (widget *Widget) display() { str := "" var ( - fromNameColor = Config.UString("wtf.mods.cryptolive.colors.from.name", "coral") - fromDisplayNameColor = Config.UString("wtf.mods.cryptolive.colors.from.displayName", "grey") - toNameColor = Config.UString("wtf.mods.cryptolive.colors.to.name", "white") - toPriceColor = Config.UString("wtf.mods.cryptolive.colors.to.price", "green") + fromNameColor = wtf.Config.UString("wtf.mods.cryptolive.colors.from.name", "coral") + fromDisplayNameColor = wtf.Config.UString("wtf.mods.cryptolive.colors.from.displayName", "grey") + toNameColor = wtf.Config.UString("wtf.mods.cryptolive.colors.to.name", "white") + toPriceColor = wtf.Config.UString("wtf.mods.cryptolive.colors.to.price", "green") ) for _, item := range widget.list.items { str += fmt.Sprintf(" [%s]%s[%s] (%s)\n", fromNameColor, item.displayName, fromDisplayNameColor, item.name) @@ -73,7 +69,7 @@ func (widget *Widget) display() { } func getToList(fromName string) []*toCurrency { - toNames, _ := Config.List("wtf.mods.cryptolive.currencies." + fromName + ".to") + toNames, _ := wtf.Config.List("wtf.mods.cryptolive.currencies." + fromName + ".to") var toList []*toCurrency @@ -88,12 +84,12 @@ func getToList(fromName string) []*toCurrency { } func (widget *Widget) setList() { - currenciesMap, _ := Config.Map("wtf.mods.cryptolive.currencies") + currenciesMap, _ := wtf.Config.Map("wtf.mods.cryptolive.currencies") widget.list = &list{} for currency := range currenciesMap { - displayName, _ := Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName") + displayName, _ := wtf.Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName") toList := getToList(currency) widget.list.addItem(currency, displayName, toList) } diff --git a/gcal/client.go b/gcal/client.go index 922a32f1..f5cf2cfb 100755 --- a/gcal/client.go +++ b/gcal/client.go @@ -16,8 +16,8 @@ import ( "os" "os/user" "path/filepath" - "time" "sort" + "time" "github.com/senorprogrammer/wtf/wtf" "golang.org/x/oauth2" @@ -30,7 +30,7 @@ import ( func Fetch() (*calendar.Events, error) { ctx := context.Background() - secretPath, _ := wtf.ExpandHomeDir(Config.UString("wtf.mods.gcal.secretFile")) + secretPath, _ := wtf.ExpandHomeDir(wtf.Config.UString("wtf.mods.gcal.secretFile")) b, err := ioutil.ReadFile(secretPath) if err != nil { @@ -70,7 +70,7 @@ func Fetch() (*calendar.Events, error) { var events calendar.Events startTime := fromMidnight().Format(time.RFC3339) - eventLimit := int64(Config.UInt("wtf.mods.gcal.eventCount", 10)) + eventLimit := int64(wtf.Config.UInt("wtf.mods.gcal.eventCount", 10)) for _, calendarId := range calendarIds { calendarEvents, err := srv.Events.List(calendarId).ShowDeleted(false).TimeMin(startTime).MaxResults(eventLimit).SingleEvents(true).OrderBy("startTime").Do() @@ -94,10 +94,9 @@ func Fetch() (*calendar.Events, error) { sort.Slice(events.Items, func(i, j int) bool { dateA, _ := timeDateChooser(events.Items[i]) dateB, _ := timeDateChooser(events.Items[j]) - return dateA.Before(dateB) + return dateA.Before(dateB) }) - return &events, err } diff --git a/gcal/widget.go b/gcal/widget.go index 81dc6422..c29d76e0 100755 --- a/gcal/widget.go +++ b/gcal/widget.go @@ -6,14 +6,10 @@ import ( "strings" "time" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" "google.golang.org/api/calendar/v3" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget } @@ -105,10 +101,10 @@ func (widget *Widget) dayDivider(event, prevEvent *calendar.Event) string { } func (widget *Widget) descriptionColor(event *calendar.Event) string { - color := Config.UString("wtf.mods.gcal.colors.description", "white") + color := wtf.Config.UString("wtf.mods.gcal.colors.description", "white") if widget.eventIsPast(event) { - color = Config.UString("wtf.mods.gcal.colors.past", "gray") + color = wtf.Config.UString("wtf.mods.gcal.colors.past", "gray") } return color @@ -120,13 +116,13 @@ func (widget *Widget) eventSummary(event *calendar.Event, conflict bool) string if widget.eventIsNow(event) { summary = fmt.Sprintf( "%s %s", - Config.UString("wtf.mods.gcal.currentIcon", "🔸"), + wtf.Config.UString("wtf.mods.gcal.currentIcon", "🔸"), event.Summary, ) } if conflict { - return fmt.Sprintf("%s %s", Config.UString("wtf.mods.gcal.conflictIcon", "🚨"), summary) + return fmt.Sprintf("%s %s", wtf.Config.UString("wtf.mods.gcal.conflictIcon", "🚨"), summary) } else { return summary } @@ -156,9 +152,9 @@ func (widget *Widget) eventIsPast(event *calendar.Event) bool { } func (widget *Widget) titleColor(event *calendar.Event) string { - color := Config.UString("wtf.mods.gcal.colors.title", "white") + color := wtf.Config.UString("wtf.mods.gcal.colors.title", "white") - for _, untypedArr := range Config.UList("wtf.mods.gcal.colors.highlights") { + for _, untypedArr := range wtf.Config.UList("wtf.mods.gcal.colors.highlights") { highlightElements := wtf.ToStrs(untypedArr.([]interface{})) match, _ := regexp.MatchString( @@ -172,14 +168,14 @@ func (widget *Widget) titleColor(event *calendar.Event) string { } if widget.eventIsPast(event) { - color = Config.UString("wtf.mods.gcal.colors.past", "gray") + color = wtf.Config.UString("wtf.mods.gcal.colors.past", "gray") } return color } func (widget *Widget) location(event *calendar.Event) string { - if Config.UBool("wtf.mods.gcal.displayLocation", true) == false { + if wtf.Config.UBool("wtf.mods.gcal.displayLocation", true) == false { return "" } @@ -195,14 +191,14 @@ func (widget *Widget) location(event *calendar.Event) string { } func (widget *Widget) responseIcon(event *calendar.Event) string { - if false == Config.UBool("wtf.mods.gcal.displayResponseStatus", true) { + if false == wtf.Config.UBool("wtf.mods.gcal.displayResponseStatus", true) { return "" } response := "" for _, attendee := range event.Attendees { - if attendee.Email == Config.UString("wtf.mods.gcal.email") { + if attendee.Email == wtf.Config.UString("wtf.mods.gcal.email") { response = attendee.ResponseStatus break } diff --git a/git/git_repo.go b/git/git_repo.go index 502b8f1e..aed7b59e 100644 --- a/git/git_repo.go +++ b/git/git_repo.go @@ -50,12 +50,12 @@ func (repo *GitRepo) changedFiles() []string { } func (repo *GitRepo) commits() []string { - numStr := fmt.Sprintf("-n %d", Config.UInt("wtf.mods.git.commitCount", 10)) + numStr := fmt.Sprintf("-n %d", wtf.Config.UInt("wtf.mods.git.commitCount", 10)) - dateFormat := Config.UString("wtf.mods.git.dateFormat", "%b %d, %Y") + dateFormat := wtf.Config.UString("wtf.mods.git.dateFormat", "%b %d, %Y") dateStr := fmt.Sprintf("--date=format:\"%s\"", dateFormat) - commitFormat := Config.UString("wtf.mods.git.commitFormat", "[forestgreen]%h [white]%s [grey]%an on %cd[white]") + commitFormat := wtf.Config.UString("wtf.mods.git.commitFormat", "[forestgreen]%h [white]%s [grey]%an on %cd[white]") commitStr := fmt.Sprintf("--pretty=format:\"%s\"", commitFormat) arg := []string{repo.gitDir(), repo.workTree(), "log", dateStr, numStr, commitStr} diff --git a/git/widget.go b/git/widget.go index 894d71b5..12a82e1d 100644 --- a/git/widget.go +++ b/git/widget.go @@ -2,14 +2,10 @@ package git import ( "github.com/gdamore/tcell" - "github.com/olebedev/config" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - const HelpText = ` Keyboard commands for Git: @@ -53,7 +49,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - repoPaths := wtf.ToStrs(Config.UList("wtf.mods.git.repositories")) + repoPaths := wtf.ToStrs(wtf.Config.UList("wtf.mods.git.repositories")) widget.UpdateRefreshedAt() widget.Data = widget.gitRepos(repoPaths) diff --git a/github/display.go b/github/display.go index e9346367..6aa31082 100644 --- a/github/display.go +++ b/github/display.go @@ -21,10 +21,10 @@ func (widget *Widget) display() { str = str + widget.displayStats(repo) str = str + "\n" str = str + " [red]Open Review Requests[white]\n" - str = str + widget.displayMyReviewRequests(repo, Config.UString("wtf.mods.github.username")) + str = str + widget.displayMyReviewRequests(repo, wtf.Config.UString("wtf.mods.github.username")) str = str + "\n" str = str + " [red]My Pull Requests[white]\n" - str = str + widget.displayMyPullRequests(repo, Config.UString("wtf.mods.github.username")) + str = str + widget.displayMyPullRequests(repo, wtf.Config.UString("wtf.mods.github.username")) widget.View.SetText(str) } diff --git a/github/widget.go b/github/widget.go index 717f1bab..c86917cb 100644 --- a/github/widget.go +++ b/github/widget.go @@ -2,14 +2,10 @@ package github import ( "github.com/gdamore/tcell" - "github.com/olebedev/config" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - const HelpText = ` Keyboard commands for Github: @@ -41,7 +37,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { pages: pages, } - widget.GithubRepos = widget.buildRepoCollection(Config.UMap("wtf.mods.github.repositories")) + widget.GithubRepos = widget.buildRepoCollection(wtf.Config.UMap("wtf.mods.github.repositories")) widget.View.SetInputCapture(widget.keyboardIntercept) diff --git a/gitlab/display.go b/gitlab/display.go index 8968701b..d7783385 100644 --- a/gitlab/display.go +++ b/gitlab/display.go @@ -21,10 +21,10 @@ func (widget *Widget) display() { str = str + widget.displayStats(project) str = str + "\n" str = str + " [red]Open Approval Requests[white]\n" - str = str + widget.displayMyApprovalRequests(project, Config.UString("wtf.mods.gitlab.username")) + str = str + widget.displayMyApprovalRequests(project, wtf.Config.UString("wtf.mods.gitlab.username")) str = str + "\n" str = str + " [red]My Merge Requests[white]\n" - str = str + widget.displayMyMergeRequests(project, Config.UString("wtf.mods.gitlab.username")) + str = str + widget.displayMyMergeRequests(project, wtf.Config.UString("wtf.mods.gitlab.username")) widget.View.SetText(str) } diff --git a/gitlab/widget.go b/gitlab/widget.go index 35e56a91..c7c3f96f 100644 --- a/gitlab/widget.go +++ b/gitlab/widget.go @@ -4,15 +4,11 @@ import ( "os" "github.com/gdamore/tcell" - "github.com/olebedev/config" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" glb "github.com/xanzy/go-gitlab" ) -// Config is a pointer to the global config object -var Config *config.Config - const HelpText = ` Keyboard commands for Gitlab: @@ -39,7 +35,7 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { apiKey := os.Getenv("WTF_GITLAB_TOKEN") - baseURL := Config.UString("wtf.mods.gitlab.domain") + baseURL := wtf.Config.UString("wtf.mods.gitlab.domain") gitlab := glb.NewClient(nil, apiKey) if baseURL != "" { gitlab.SetBaseURL(baseURL) @@ -56,7 +52,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { Idx: 0, } - widget.GitlabProjects = widget.buildProjectCollection(Config.UMap("wtf.mods.gitlab.projects")) + widget.GitlabProjects = widget.buildProjectCollection(wtf.Config.UMap("wtf.mods.gitlab.projects")) widget.View.SetInputCapture(widget.keyboardIntercept) diff --git a/gspreadsheets/client.go b/gspreadsheets/client.go index 1cf16321..4b0b31a6 100644 --- a/gspreadsheets/client.go +++ b/gspreadsheets/client.go @@ -29,7 +29,7 @@ import ( func Fetch() ([]*sheets.ValueRange, error) { ctx := context.Background() - secretPath, _ := wtf.ExpandHomeDir(Config.UString("wtf.mods.gspreadsheets.secretFile")) + secretPath, _ := wtf.ExpandHomeDir(wtf.Config.UString("wtf.mods.gspreadsheets.secretFile")) b, err := ioutil.ReadFile(secretPath) if err != nil { @@ -51,8 +51,8 @@ func Fetch() ([]*sheets.ValueRange, error) { return nil, err } - cells := wtf.ToStrs(Config.UList("wtf.mods.gspreadsheets.cells.addresses")) - documentId := Config.UString("wtf.mods.gspreadsheets.sheetId") + cells := wtf.ToStrs(wtf.Config.UList("wtf.mods.gspreadsheets.cells.addresses")) + documentId := wtf.Config.UString("wtf.mods.gspreadsheets.sheetId") addresses := strings.Join(cells[:], ";") responses := make([]*sheets.ValueRange, len(cells)) diff --git a/gspreadsheets/widget.go b/gspreadsheets/widget.go index 680869cf..416523e0 100644 --- a/gspreadsheets/widget.go +++ b/gspreadsheets/widget.go @@ -3,14 +3,10 @@ package gspreadsheets import ( "fmt" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" sheets "google.golang.org/api/sheets/v4" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget } @@ -40,10 +36,10 @@ func (widget *Widget) contentFrom(valueRanges []*sheets.ValueRange) string { return "error 1" } - valuesColor := Config.UString("wtf.mods.gspreadsheets.colors.values", "green") + valuesColor := wtf.Config.UString("wtf.mods.gspreadsheets.colors.values", "green") res := "" - cells := wtf.ToStrs(Config.UList("wtf.mods.gspreadsheets.cells.names")) + cells := wtf.ToStrs(wtf.Config.UList("wtf.mods.gspreadsheets.cells.names")) for i := 0; i < len(valueRanges); i++ { res = res + fmt.Sprintf("%s\t[%s]%s\n", cells[i], valuesColor, valueRanges[i].Values[0][0]) } diff --git a/ipaddresses/ipapi/widget.go b/ipaddresses/ipapi/widget.go index d65f2456..e40e4039 100644 --- a/ipaddresses/ipapi/widget.go +++ b/ipaddresses/ipapi/widget.go @@ -9,13 +9,9 @@ import ( "bytes" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - // Widget widget struct type Widget struct { wtf.TextWidget @@ -87,7 +83,7 @@ func (widget *Widget) ipinfo() { // read module configs func (widget *Widget) config() { - nameColor, valueColor := Config.UString("wtf.mods.ipinfo.colors.name", "red"), Config.UString("wtf.mods.ipinfo.colors.value", "white") + nameColor, valueColor := wtf.Config.UString("wtf.mods.ipinfo.colors.name", "red"), wtf.Config.UString("wtf.mods.ipinfo.colors.value", "white") widget.colors.name = nameColor widget.colors.value = valueColor } diff --git a/ipaddresses/ipinfo/widget.go b/ipaddresses/ipinfo/widget.go index 62db1732..f165aa5a 100644 --- a/ipaddresses/ipinfo/widget.go +++ b/ipaddresses/ipinfo/widget.go @@ -8,13 +8,9 @@ import ( "bytes" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget result string @@ -82,7 +78,7 @@ func (widget *Widget) ipinfo() { // read module configs func (widget *Widget) config() { - nameColor, valueColor := Config.UString("wtf.mods.ipinfo.colors.name", "red"), Config.UString("wtf.mods.ipinfo.colors.value", "white") + nameColor, valueColor := wtf.Config.UString("wtf.mods.ipinfo.colors.name", "red"), wtf.Config.UString("wtf.mods.ipinfo.colors.value", "white") widget.colors.name = nameColor widget.colors.value = valueColor } diff --git a/jenkins/view.go b/jenkins/view.go index 9041b297..03a7f6ed 100644 --- a/jenkins/view.go +++ b/jenkins/view.go @@ -1,10 +1,10 @@ package jenkins type View struct { - Class string `json:"_class"` - Description string `json:"description"` - Jobs []Job `json:"jobs"` - Name string `json:"name"` - Property []string `json:"property"` - url string `json:"url"` + Class string `json:"_class"` + Description string `json:"description"` + Jobs []Job `json:"jobs"` + Name string `json:"name"` + Property []string `json:"property"` + url string `json:"url"` } diff --git a/jenkins/widget.go b/jenkins/widget.go index a922fbbf..32133d2e 100644 --- a/jenkins/widget.go +++ b/jenkins/widget.go @@ -2,14 +2,10 @@ package jenkins import ( "fmt" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" "os" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget } @@ -29,8 +25,11 @@ func (widget *Widget) Refresh() { return } - view, err := Create(Config.UString("wtf.mods.jenkins.url"), - Config.UString("wtf.mods.jenkins.user"), os.Getenv("WTF_JENKINS_API_KEY")) + view, err := Create( + wtf.Config.UString("wtf.mods.jenkins.url"), + wtf.Config.UString("wtf.mods.jenkins.user"), + os.Getenv("WTF_JENKINS_API_KEY"), + ) widget.UpdateRefreshedAt() widget.View.Clear() @@ -54,7 +53,7 @@ func (widget *Widget) Refresh() { /* -------------------- Unexported Functions -------------------- */ func (widget *Widget) contentFrom(view *View) string { - str := fmt.Sprintf(" [red]%s[white]\n", view.Name); + str := fmt.Sprintf(" [red]%s[white]\n", view.Name) for _, job := range view.Jobs { str = str + fmt.Sprintf( diff --git a/jira/client.go b/jira/client.go index ad1f51a9..b28ec616 100644 --- a/jira/client.go +++ b/jira/client.go @@ -11,6 +11,8 @@ import ( "net/url" "os" "strings" + + "github.com/senorprogrammer/wtf/wtf" ) func IssuesFor(username string, projects []string, jql string) (*SearchResult, error) { @@ -53,21 +55,21 @@ func buildJql(key string, value string) string { /* -------------------- Unexported Functions -------------------- */ func jiraRequest(path string) (*http.Response, error) { - url := fmt.Sprintf("%s%s", Config.UString("wtf.mods.jira.domain"), path) + url := fmt.Sprintf("%s%s", wtf.Config.UString("wtf.mods.jira.domain"), path) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err } - req.SetBasicAuth(Config.UString("wtf.mods.jira.email"), os.Getenv("WTF_JIRA_API_KEY")) + req.SetBasicAuth(wtf.Config.UString("wtf.mods.jira.email"), os.Getenv("WTF_JIRA_API_KEY")) - verifyServerCertificate := Config.UBool("wtf.mods.jira.verifyServerCertificate", true) + verifyServerCertificate := wtf.Config.UBool("wtf.mods.jira.verifyServerCertificate", true) httpClient := &http.Client{Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: !verifyServerCertificate, - }, - }, - } + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: !verifyServerCertificate, + }, + }, + } resp, err := httpClient.Do(req) if err != nil { return nil, err diff --git a/jira/widget.go b/jira/widget.go index 6ca9670e..62b0bb41 100644 --- a/jira/widget.go +++ b/jira/widget.go @@ -3,13 +3,9 @@ package jira import ( "fmt" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget } @@ -25,7 +21,11 @@ func NewWidget() *Widget { /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - searchResult, err := IssuesFor(Config.UString("wtf.mods.jira.username"), getProjects(), Config.UString("wtf.mods.jira.jql", "")) + searchResult, err := IssuesFor( + wtf.Config.UString("wtf.mods.jira.username"), + getProjects(), + wtf.Config.UString("wtf.mods.jira.jql", ""), + ) widget.UpdateRefreshedAt() @@ -39,7 +39,7 @@ func (widget *Widget) Refresh() { fmt.Sprintf( "%s- [green]%s[white]", widget.Name, - Config.UString("wtf.mods.jira.project"), + wtf.Config.UString("wtf.mods.jira.project"), ), ) widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(searchResult))) @@ -85,12 +85,12 @@ func (widget *Widget) issueTypeColor(issue *Issue) string { func getProjects() []string { // see if project is set to a single string configPath := "wtf.mods.jira.project" - singleProject, err := Config.String(configPath) + singleProject, err := wtf.Config.String(configPath) if err == nil { return []string{singleProject} } // else, assume list - projList := Config.UList(configPath) + projList := wtf.Config.UList(configPath) var ret []string for _, proj := range projList { if str, ok := proj.(string); ok { diff --git a/newrelic/client.go b/newrelic/client.go index c5d3f9a9..f88d4e3e 100644 --- a/newrelic/client.go +++ b/newrelic/client.go @@ -3,13 +3,14 @@ package newrelic import ( "os" + "github.com/senorprogrammer/wtf/wtf" nr "github.com/yfronto/newrelic" ) func Application() (*nr.Application, error) { client := nr.NewClient(os.Getenv("WTF_NEW_RELIC_API_KEY")) - application, err := client.GetApplication(Config.UInt("wtf.mods.newrelic.applicationId")) + application, err := client.GetApplication(wtf.Config.UInt("wtf.mods.newrelic.applicationId")) if err != nil { return nil, err } @@ -21,7 +22,7 @@ func Deployments() ([]nr.ApplicationDeployment, error) { client := nr.NewClient(os.Getenv("WTF_NEW_RELIC_API_KEY")) opts := &nr.ApplicationDeploymentOptions{Page: 1} - deployments, err := client.GetApplicationDeployments(Config.UInt("wtf.mods.newrelic.applicationId"), opts) + deployments, err := client.GetApplicationDeployments(wtf.Config.UInt("wtf.mods.newrelic.applicationId"), opts) if err != nil { return nil, err } diff --git a/newrelic/widget.go b/newrelic/widget.go index ad4c333a..09cf5f81 100644 --- a/newrelic/widget.go +++ b/newrelic/widget.go @@ -3,14 +3,10 @@ package newrelic import ( "fmt" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" nr "github.com/yfronto/newrelic" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget } @@ -79,7 +75,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { revisions = append(revisions, deploy.Revision) - if len(revisions) == Config.UInt("wtf.mods.newrelic.deployCount", 5) { + if len(revisions) == wtf.Config.UInt("wtf.mods.newrelic.deployCount", 5) { break } } diff --git a/opsgenie/widget.go b/opsgenie/widget.go index 314b832a..593302aa 100644 --- a/opsgenie/widget.go +++ b/opsgenie/widget.go @@ -4,13 +4,9 @@ import ( "fmt" "strings" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget } @@ -45,7 +41,7 @@ func (widget *Widget) Refresh() { func (widget *Widget) contentFrom(onCallResponse *OnCallResponse) string { str := "" - displayEmpty := Config.UBool("wtf.mods.opsgenie.displayEmpty", true) + displayEmpty := wtf.Config.UBool("wtf.mods.opsgenie.displayEmpty", true) for _, data := range onCallResponse.OnCallData { if (len(data.Recipients) == 0) && (displayEmpty == false) { diff --git a/power/widget.go b/power/widget.go index d3d3a996..c191b620 100644 --- a/power/widget.go +++ b/power/widget.go @@ -3,13 +3,9 @@ package power import ( "fmt" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget diff --git a/security/widget.go b/security/widget.go index 17d91135..a991af49 100644 --- a/security/widget.go +++ b/security/widget.go @@ -6,13 +6,9 @@ import ( "fmt" "strings" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget } diff --git a/security/widget_windows.go b/security/widget_windows.go index 8ce3652b..009e7860 100644 --- a/security/widget_windows.go +++ b/security/widget_windows.go @@ -6,13 +6,9 @@ import ( "fmt" "strings" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget } diff --git a/status/widget.go b/status/widget.go index e258f83e..43f40238 100644 --- a/status/widget.go +++ b/status/widget.go @@ -3,13 +3,9 @@ package status import ( "fmt" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget diff --git a/system/widget.go b/system/widget.go index c13ed5ea..39d1853a 100644 --- a/system/widget.go +++ b/system/widget.go @@ -4,13 +4,9 @@ import ( "fmt" "time" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget diff --git a/textfile/widget.go b/textfile/widget.go index 2bc3afe6..e17e452a 100644 --- a/textfile/widget.go +++ b/textfile/widget.go @@ -5,14 +5,10 @@ import ( "io/ioutil" "github.com/gdamore/tcell" - "github.com/olebedev/config" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - const HelpText = ` Keyboard commands for Textfile: @@ -33,7 +29,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { TextWidget: wtf.NewTextWidget(" Text File ", "textfile", true), app: app, - filePath: Config.UString("wtf.mods.textfile.filePath"), + filePath: wtf.Config.UString("wtf.mods.textfile.filePath"), pages: pages, } diff --git a/todo/display.go b/todo/display.go index d25d20cb..6c5c7137 100644 --- a/todo/display.go +++ b/todo/display.go @@ -33,15 +33,15 @@ func (widget *Widget) display() { } func (widget *Widget) formattedItemLine(item *Item, selectedItem *Item, maxLen int) string { - foreColor, backColor := "white", Config.UString("wtf.colors.background", "black") + foreColor, backColor := "white", wtf.Config.UString("wtf.colors.background", "black") if item.Checked { - foreColor = Config.UString("wtf.mods.todo.colors.checked", "white") + foreColor = wtf.Config.UString("wtf.mods.todo.colors.checked", "white") } if widget.View.HasFocus() && (item == selectedItem) { - foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black") - backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white") + foreColor = wtf.Config.UString("wtf.mods.todo.colors.highlight.fore", "black") + backColor = wtf.Config.UString("wtf.mods.todo.colors.highlight.back", "white") } str := fmt.Sprintf( diff --git a/todo/item.go b/todo/item.go index bc87b897..f546b124 100644 --- a/todo/item.go +++ b/todo/item.go @@ -1,5 +1,9 @@ package todo +import ( + "github.com/senorprogrammer/wtf/wtf" +) + type Item struct { Checked bool Text string @@ -7,7 +11,7 @@ type Item struct { func (item *Item) CheckMark() string { if item.Checked { - return Config.UString("wtf.mods.todo.checkedIcon", "x") + return wtf.Config.UString("wtf.mods.todo.checkedIcon", "x") } else { return " " } diff --git a/todo/widget.go b/todo/widget.go index e06c007c..6bebc605 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -5,16 +5,12 @@ import ( "io/ioutil" "github.com/gdamore/tcell" - "github.com/olebedev/config" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/cfg" "github.com/senorprogrammer/wtf/wtf" "gopkg.in/yaml.v2" ) -// Config is a pointer to the global config object -var Config *config.Config - const HelpText = ` Keyboard commands for Todo: @@ -52,7 +48,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { TextWidget: wtf.NewTextWidget(" Todo ", "todo", true), app: app, - filePath: Config.UString("wtf.mods.todo.filename"), + filePath: wtf.Config.UString("wtf.mods.todo.filename"), list: &List{selected: -1}, pages: pages, } diff --git a/weatherservices/prettyweather/widget.go b/weatherservices/prettyweather/widget.go index c0ef7596..8c47c5c0 100644 --- a/weatherservices/prettyweather/widget.go +++ b/weatherservices/prettyweather/widget.go @@ -6,13 +6,9 @@ import ( "net/http" "strings" - "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object -var Config *config.Config - type Widget struct { wtf.TextWidget result string @@ -39,9 +35,9 @@ func (widget *Widget) Refresh() { //this method reads the config and calls wttr.in for pretty weather func (widget *Widget) prettyWeather() { client := &http.Client{} - widget.unit = Config.UString("wtf.mods.prettyweather.unit", "m") - widget.city = Config.UString("wtf.mods.prettyweather.city", "") - widget.view = Config.UString("wtf.mods.prettyweather.view", "0") + widget.unit = wtf.Config.UString("wtf.mods.prettyweather.unit", "m") + widget.city = wtf.Config.UString("wtf.mods.prettyweather.city", "") + widget.view = wtf.Config.UString("wtf.mods.prettyweather.view", "0") req, err := http.NewRequest("GET", "https://wttr.in/"+widget.city+"?"+widget.view+"?"+widget.unit, nil) if err != nil { widget.result = fmt.Sprintf("%s", err.Error()) diff --git a/weatherservices/weather/display.go b/weatherservices/weather/display.go index 9acd9e3d..33bf9314 100644 --- a/weatherservices/weather/display.go +++ b/weatherservices/weather/display.go @@ -55,14 +55,14 @@ func (widget *Widget) sunInfo(cityData *owm.CurrentWeatherData) string { } func (widget *Widget) temperatures(cityData *owm.CurrentWeatherData) string { - tempUnit := Config.UString("wtf.mods.weather.tempUnit", "C") + tempUnit := wtf.Config.UString("wtf.mods.weather.tempUnit", "C") str := fmt.Sprintf("%8s: %4.1f° %s\n", "High", cityData.Main.TempMax, tempUnit) str = str + fmt.Sprintf( "%8s: [%s]%4.1f° %s[white]\n", "Current", - Config.UString("wtf.mods.weather.colors.current", "green"), + wtf.Config.UString("wtf.mods.weather.colors.current", "green"), cityData.Main.Temp, tempUnit, ) diff --git a/weatherservices/weather/widget.go b/weatherservices/weather/widget.go index d1c3d203..86208480 100644 --- a/weatherservices/weather/widget.go +++ b/weatherservices/weather/widget.go @@ -5,14 +5,10 @@ import ( owm "github.com/briandowns/openweathermap" "github.com/gdamore/tcell" - "github.com/olebedev/config" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) -// Config is a pointer to the global config object. -var Config *config.Config - const HelpText = ` Keyboard commands for Weather: @@ -75,7 +71,7 @@ func (widget *Widget) Fetch(cityIDs []int) []*owm.CurrentWeatherData { // widget's view for rendering func (widget *Widget) Refresh() { if widget.apiKeyValid() { - widget.Data = widget.Fetch(wtf.ToInts(Config.UList("wtf.mods.weather.cityids", widget.defaultCityCodes()))) + widget.Data = widget.Fetch(wtf.ToInts(wtf.Config.UList("wtf.mods.weather.cityids", widget.defaultCityCodes()))) } widget.UpdateRefreshedAt() @@ -131,7 +127,11 @@ func (widget *Widget) currentData() *owm.CurrentWeatherData { } func (widget *Widget) currentWeather(apiKey string, cityCode int) (*owm.CurrentWeatherData, error) { - weather, err := owm.NewCurrent(Config.UString("wtf.mods.weather.tempUnit", "C"), Config.UString("wtf.mods.weather.language", "EN"), apiKey) + weather, err := owm.NewCurrent( + wtf.Config.UString("wtf.mods.weather.tempUnit", "C"), + wtf.Config.UString("wtf.mods.weather.language", "EN"), + apiKey, + ) if err != nil { return nil, err } diff --git a/wtf.go b/wtf.go index 2e35179a..55aa0def 100644 --- a/wtf.go +++ b/wtf.go @@ -88,35 +88,6 @@ func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { func loadConfigFile(filePath string) { Config = cfg.LoadConfigFile(filePath) - - // Always in alphabetical order - bamboohr.Config = Config - bargraph.Config = Config - bittrex.Config = Config - blockfolio.Config = Config - circleci.Config = Config - clocks.Config = Config - cmdrunner.Config = Config - cryptolive.Config = Config - gcal.Config = Config - git.Config = Config - github.Config = Config - gitlab.Config = Config - gspreadsheets.Config = Config - ipapi.Config = Config - ipinfo.Config = Config - jenkins.Config = Config - jira.Config = Config - newrelic.Config = Config - opsgenie.Config = Config - power.Config = Config - prettyweather.Config = Config - security.Config = Config - status.Config = Config - system.Config = Config - textfile.Config = Config - todo.Config = Config - weather.Config = Config wtf.Config = Config }