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

Properly scope Config to the wtf package and remove it as a dependency from everywhere else

This commit is contained in:
Chris Cummer 2018-06-16 14:59:22 -07:00
parent abedee0ce0
commit 66b69471d0
42 changed files with 126 additions and 251 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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"`
}

View File

@ -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
}

View File

@ -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()

View File

@ -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
}

View File

@ -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))

View File

@ -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)))
}

View File

@ -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++ {

View File

@ -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)
}

View File

@ -29,7 +29,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 {
@ -48,7 +48,7 @@ func Fetch() (*calendar.Events, error) {
}
startTime := fromMidnight().Format(time.RFC3339)
eventLimit := int64(Config.UInt("wtf.mods.gcal.eventCount", 10))
eventLimit := int64(wtf.Config.UInt("wtf.mods.gcal.eventCount", 10))
events, err := srv.Events.List("primary").ShowDeleted(false).SingleEvents(true).TimeMin(startTime).MaxResults(eventLimit).OrderBy("startTime").Do()
if err != nil {
return nil, err

View File

@ -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
}
@ -151,9 +147,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(
@ -167,14 +163,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 ""
}
@ -190,14 +186,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
}

View File

@ -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}

View File

@ -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)

View File

@ -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)
}

View File

@ -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)

View File

@ -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)
}

View File

@ -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)

View File

@ -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))

View File

@ -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])
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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"`
}

View File

@ -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(

View File

@ -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

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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) {

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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,
}

View File

@ -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(

View File

@ -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 " "
}

View File

@ -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,
}

View File

@ -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())

View File

@ -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,
)

View File

@ -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
}

29
wtf.go
View File

@ -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
}