From 96e0606c6aa05f19c67e8f4542c3cdc1f0375779 Mon Sep 17 00:00:00 2001 From: Lassi Piironen Date: Sat, 16 Jun 2018 23:37:02 +0300 Subject: [PATCH 01/12] Google Calendar: the client reads all the events the user can write on instead of just the accounts primary events, the timestamp printing of the all-day events is handled --- gcal/client.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++---- gcal/widget.go | 9 +++++++-- wtf/utils.go | 1 + 3 files changed, 56 insertions(+), 6 deletions(-) mode change 100644 => 100755 gcal/client.go mode change 100644 => 100755 gcal/widget.go mode change 100644 => 100755 wtf/utils.go diff --git a/gcal/client.go b/gcal/client.go old mode 100644 new mode 100755 index de655620..922a32f1 --- a/gcal/client.go +++ b/gcal/client.go @@ -17,6 +17,7 @@ import ( "os/user" "path/filepath" "time" + "sort" "github.com/senorprogrammer/wtf/wtf" "golang.org/x/oauth2" @@ -47,14 +48,57 @@ func Fetch() (*calendar.Events, error) { return nil, err } - startTime := fromMidnight().Format(time.RFC3339) - eventLimit := int64(Config.UInt("wtf.mods.gcal.eventCount", 10)) - events, err := srv.Events.List("primary").ShowDeleted(false).SingleEvents(true).TimeMin(startTime).MaxResults(eventLimit).OrderBy("startTime").Do() + // Get all user calendars with at the least writing access + pageToken := "" + var calendarIds []string + for { + calendarList, err := srv.CalendarList.List().ShowHidden(false).MinAccessRole("writer").PageToken(pageToken).Do() + for _, calendarListItem := range calendarList.Items { + calendarIds = append(calendarIds, calendarListItem.Id) + } + + pageToken = calendarList.NextPageToken + if err != nil || pageToken == "" { + break + } + } if err != nil { return nil, err } - return events, err + // Get calendar events + var events calendar.Events + + startTime := fromMidnight().Format(time.RFC3339) + eventLimit := int64(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() + if err != nil { + break + } + events.Items = append(events.Items, calendarEvents.Items...) + } + if err != nil { + return nil, err + } + + // Sort events + timeDateChooser := func(event *calendar.Event) (time.Time, error) { + if len(event.Start.Date) > 0 { + return time.Parse("2006-01-02", event.Start.Date) + } else { + return time.Parse(time.RFC3339, event.Start.DateTime) + } + } + sort.Slice(events.Items, func(i, j int) bool { + dateA, _ := timeDateChooser(events.Items[i]) + dateB, _ := timeDateChooser(events.Items[j]) + return dateA.Before(dateB) + }) + + + return &events, err } /* -------------------- Unexported Functions -------------------- */ diff --git a/gcal/widget.go b/gcal/widget.go old mode 100644 new mode 100755 index 487c8daa..81dc6422 --- a/gcal/widget.go +++ b/gcal/widget.go @@ -133,8 +133,13 @@ func (widget *Widget) eventSummary(event *calendar.Event, conflict bool) string } func (widget *Widget) eventTimestamp(event *calendar.Event) string { - startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime) - return startTime.Format(wtf.FriendlyDateTimeFormat) + if len(event.Start.Date) > 0 { + startTime, _ := time.Parse("2006-01-02", event.Start.Date) + return startTime.Format(wtf.FriendlyDateFormat) + } else { + startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime) + return startTime.Format(wtf.FriendlyDateTimeFormat) + } } // eventIsNow returns true if the event is happening now, false if it not diff --git a/wtf/utils.go b/wtf/utils.go old mode 100644 new mode 100755 index 78ec3284..c65a925b --- a/wtf/utils.go +++ b/wtf/utils.go @@ -13,6 +13,7 @@ import ( const SimpleDateFormat = "Jan 2" const SimpleTimeFormat = "15:04 MST" +const FriendlyDateFormat = "Mon, Jan 2" const FriendlyDateTimeFormat = "Mon, Jan 2, 15:04" const TimestampFormat = "2006-01-02T15:04:05-0700" From 889aed11a5a2f80593d9249979d37138554b242c Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 05:14:53 -0700 Subject: [PATCH 02/12] Rename the help function to a better name --- help/help.go | 8 ++++---- wtf.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/help/help.go b/help/help.go index bac22d0a..1ae82d4b 100644 --- a/help/help.go +++ b/help/help.go @@ -11,11 +11,11 @@ import ( "github.com/senorprogrammer/wtf/weatherservices/weather" ) -func DisplayModuleInfo(moduleName string) { - if moduleName != "" { - fmt.Printf("%s\n", helpFor(moduleName)) - } else { +func Display(moduleName string) { + if moduleName == "" { fmt.Println("\n --module takes a module name as an argument, i.e: '--module=github'") + } else { + fmt.Printf("%s\n", helpFor(moduleName)) } os.Exit(0) diff --git a/wtf.go b/wtf.go index aabc4895..1e6aee8f 100644 --- a/wtf.go +++ b/wtf.go @@ -85,8 +85,8 @@ func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { return event } -func loadConfig(configFlag string) { - Config = cfg.LoadConfigFile(configFlag) +func loadConfig(filePath string) { + Config = cfg.LoadConfigFile(filePath) } // redrawApp redraws the rendered views to screen on a defined interval (set in config.yml) @@ -264,7 +264,7 @@ func main() { cmdFlags.Parse(version) if cmdFlags.HasModule() { - help.DisplayModuleInfo(cmdFlags.Module) + help.Display(cmdFlags.Module) } cfg.CreateConfigDir() From e92289ebae4f0996094f786d2189969c1c04c777 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 08:31:11 -0700 Subject: [PATCH 03/12] Move command line flags into it's own module --- _sample_configs/simple_config.yml | 2 +- flags/flags.go | 54 +++++++++++++++++++++++++++++++ wtf.go | 13 ++++---- wtf/command_flags.go | 53 ------------------------------ 4 files changed, 62 insertions(+), 60 deletions(-) create mode 100644 flags/flags.go delete mode 100644 wtf/command_flags.go diff --git a/_sample_configs/simple_config.yml b/_sample_configs/simple_config.yml index 3d08666d..efa5d2bf 100644 --- a/_sample_configs/simple_config.yml +++ b/_sample_configs/simple_config.yml @@ -1,6 +1,6 @@ wtf: colors: - background: gray + #background: gray border: focusable: darkslateblue focused: orange diff --git a/flags/flags.go b/flags/flags.go new file mode 100644 index 00000000..52cb3636 --- /dev/null +++ b/flags/flags.go @@ -0,0 +1,54 @@ +package flags + +import ( + "fmt" + "os" + "path/filepath" + + goFlags "github.com/jessevdk/go-flags" + "github.com/senorprogrammer/wtf/wtf" +) + +type Flags struct { + Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"` + Module string `short:"m" long:"module" optional:"yes" description:"Display info about a specific module, i.e.: 'wtf -m=todo'"` + Version bool `short:"v" long:"version" description:"Show Version Info"` +} + +func NewFlags() *Flags { + flags := Flags{} + return &flags +} + +/* -------------------- Exported Functions -------------------- */ + +func (flags *Flags) HasConfig() bool { + return len(flags.Config) > 0 +} + +func (flags *Flags) HasModule() bool { + return len(flags.Module) > 0 +} + +func (flags *Flags) Parse(version string) { + parser := goFlags.NewParser(flags, goFlags.Default) + if _, err := parser.Parse(); err != nil { + if flagsErr, ok := err.(*goFlags.Error); ok && flagsErr.Type == goFlags.ErrHelp { + os.Exit(0) + } + } + + if !flags.HasConfig() { + homeDir, err := wtf.Home() + if err != nil { + os.Exit(1) + } + + flags.Config = filepath.Join(homeDir, ".wtf", "config.yml") + } + + if flags.Version { + fmt.Printf("Version: %s\n", version) + os.Exit(0) + } +} diff --git a/wtf.go b/wtf.go index 1e6aee8f..deb72292 100644 --- a/wtf.go +++ b/wtf.go @@ -19,6 +19,7 @@ import ( "github.com/senorprogrammer/wtf/cryptoexchanges/bittrex" "github.com/senorprogrammer/wtf/cryptoexchanges/blockfolio" "github.com/senorprogrammer/wtf/cryptoexchanges/cryptolive" + "github.com/senorprogrammer/wtf/flags" "github.com/senorprogrammer/wtf/gcal" "github.com/senorprogrammer/wtf/git" "github.com/senorprogrammer/wtf/github" @@ -260,17 +261,17 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) { func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) - cmdFlags := wtf.NewCommandFlags() - cmdFlags.Parse(version) + flags := flags.NewFlags() + flags.Parse(version) - if cmdFlags.HasModule() { - help.Display(cmdFlags.Module) + if flags.HasModule() { + help.Display(flags.Module) } cfg.CreateConfigDir() cfg.WriteConfigFile() - loadConfig(cmdFlags.Config) + loadConfig(flags.Config) setTerm() app := tview.NewApplication() @@ -285,7 +286,7 @@ func main() { // Loop in a routine to redraw the screen go redrawApp(app) - go watchForConfigChanges(app, cmdFlags.Config, display.Grid, pages) + go watchForConfigChanges(app, flags.Config, display.Grid, pages) if err := app.SetRoot(pages, true).Run(); err != nil { fmt.Printf("An error occurred: %v\n", err) diff --git a/wtf/command_flags.go b/wtf/command_flags.go deleted file mode 100644 index 9b9980bb..00000000 --- a/wtf/command_flags.go +++ /dev/null @@ -1,53 +0,0 @@ -package wtf - -import ( - "fmt" - "os" - "path/filepath" - - flags "github.com/jessevdk/go-flags" -) - -type CommandFlags struct { - Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"` - Module string `short:"m" long:"module" optional:"yes" description:"Display info about a specific module, i.e.: 'wtf -m=todo'"` - Version bool `short:"v" long:"version" description:"Show Version Info"` -} - -func NewCommandFlags() *CommandFlags { - cmdFlags := CommandFlags{} - return &cmdFlags -} - -/* -------------------- Exported Functions -------------------- */ - -func (cmdFlags *CommandFlags) HasConfig() bool { - return len(cmdFlags.Config) > 0 -} - -func (cmdFlags *CommandFlags) HasModule() bool { - return len(cmdFlags.Module) > 0 -} - -func (cmdFlags *CommandFlags) Parse(version string) { - parser := flags.NewParser(cmdFlags, flags.Default) - if _, err := parser.Parse(); err != nil { - if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { - os.Exit(0) - } - } - - if !cmdFlags.HasConfig() { - homeDir, err := Home() - if err != nil { - os.Exit(1) - } - - cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml") - } - - if cmdFlags.Version { - fmt.Printf("Version: %s\n", version) - os.Exit(0) - } -} From a6505516adb6722fb9ac7e773857dceeceaa587e Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 08:37:55 -0700 Subject: [PATCH 04/12] Move responsibility for version display out of flags --- flags/flags.go | 12 ++++++------ help/help.go | 3 --- wtf.go | 8 +++++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/flags/flags.go b/flags/flags.go index 52cb3636..131ed856 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -12,7 +12,7 @@ import ( type Flags struct { Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"` Module string `short:"m" long:"module" optional:"yes" description:"Display info about a specific module, i.e.: 'wtf -m=todo'"` - Version bool `short:"v" long:"version" description:"Show Version Info"` + Version bool `short:"v" long:"version" description:"Show version info"` } func NewFlags() *Flags { @@ -30,6 +30,10 @@ func (flags *Flags) HasModule() bool { return len(flags.Module) > 0 } +func (flags *Flags) HasVersion() bool { + return flags.Version == true +} + func (flags *Flags) Parse(version string) { parser := goFlags.NewParser(flags, goFlags.Default) if _, err := parser.Parse(); err != nil { @@ -41,14 +45,10 @@ func (flags *Flags) Parse(version string) { if !flags.HasConfig() { homeDir, err := wtf.Home() if err != nil { + fmt.Printf("Error: %v\n", err) os.Exit(1) } flags.Config = filepath.Join(homeDir, ".wtf", "config.yml") } - - if flags.Version { - fmt.Printf("Version: %s\n", version) - os.Exit(0) - } } diff --git a/help/help.go b/help/help.go index 1ae82d4b..b77035ea 100644 --- a/help/help.go +++ b/help/help.go @@ -2,7 +2,6 @@ package help import ( "fmt" - "os" "github.com/senorprogrammer/wtf/git" "github.com/senorprogrammer/wtf/github" @@ -17,8 +16,6 @@ func Display(moduleName string) { } else { fmt.Printf("%s\n", helpFor(moduleName)) } - - os.Exit(0) } func helpFor(moduleName string) string { diff --git a/wtf.go b/wtf.go index deb72292..c545fd52 100644 --- a/wtf.go +++ b/wtf.go @@ -266,6 +266,12 @@ func main() { if flags.HasModule() { help.Display(flags.Module) + os.Exit(0) + } + + if flags.HasVersion() { + fmt.Println(version) + os.Exit(0) } cfg.CreateConfigDir() @@ -289,7 +295,7 @@ func main() { go watchForConfigChanges(app, flags.Config, display.Grid, pages) if err := app.SetRoot(pages, true).Run(); err != nil { - fmt.Printf("An error occurred: %v\n", err) + fmt.Printf("Error: %v\n", err) os.Exit(1) } From e9118dcc079e235382bbb98eeb858de040839bd5 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 09:13:23 -0700 Subject: [PATCH 05/12] Clean up the flag and config handling in main() --- cfg/config_files.go | 38 ++++++++++++------------ flags/flags.go | 6 ++++ wtf.go | 72 ++++++++++++++++++++++----------------------- 3 files changed, 61 insertions(+), 55 deletions(-) diff --git a/cfg/config_files.go b/cfg/config_files.go index ff7f997e..46a99780 100644 --- a/cfg/config_files.go +++ b/cfg/config_files.go @@ -30,6 +30,25 @@ func CreateConfigDir() { } } +// CreateConfigFile creates a simple config file in the config directory if +// one does not already exist +func CreateConfigFile() { + filePath, err := CreateFile("config.yml") + if err != nil { + panic(err) + } + + // If the file is empty, write to it + file, err := os.Stat(filePath) + + if file.Size() == 0 { + err = ioutil.WriteFile(filePath, []byte(simpleConfig), 0644) + if err != nil { + panic(err) + } + } +} + // CreateFile creates the named file in the config directory, if it does not already exist. // If the file exists it does not recreate it. // If successful, eturns the absolute path to the file @@ -88,25 +107,6 @@ func ReadConfigFile(fileName string) (string, error) { return string(fileData), nil } -// WriteConfigFile creates a simple config file in the config directory if -// one does not already exist -func WriteConfigFile() { - filePath, err := CreateFile("config.yml") - if err != nil { - panic(err) - } - - // If the file is empty, write to it - file, err := os.Stat(filePath) - - if file.Size() == 0 { - err = ioutil.WriteFile(filePath, []byte(simpleConfig), 0644) - if err != nil { - panic(err) - } - } -} - const simpleConfig = `wtf: colors: border: diff --git a/flags/flags.go b/flags/flags.go index 131ed856..3e798e4e 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -22,6 +22,10 @@ func NewFlags() *Flags { /* -------------------- Exported Functions -------------------- */ +func (flags *Flags) ConfigFilePath() string { + return flags.Config +} + func (flags *Flags) HasConfig() bool { return len(flags.Config) > 0 } @@ -42,6 +46,8 @@ func (flags *Flags) Parse(version string) { } } + // If no config file is explicitly passed in as a param, + // set the flag to the default config file if !flags.HasConfig() { homeDir, err := wtf.Home() if err != nil { diff --git a/wtf.go b/wtf.go index c545fd52..dd25461c 100644 --- a/wtf.go +++ b/wtf.go @@ -86,8 +86,38 @@ func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { return event } -func loadConfig(filePath string) { +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 } // redrawApp redraws the rendered views to screen on a defined interval (set in config.yml) @@ -119,7 +149,7 @@ func setTerm() { os.Setenv("TERM", Config.UString("wtf.term", os.Getenv("TERM"))) } -func watchForConfigChanges(app *tview.Application, configFlag string, grid *tview.Grid, pages *tview.Pages) { +func watchForConfigChanges(app *tview.Application, configFilePath string, grid *tview.Grid, pages *tview.Pages) { watch := watcher.New() // notify write events. @@ -129,7 +159,7 @@ func watchForConfigChanges(app *tview.Application, configFlag string, grid *tvie for { select { case <-watch.Event: - loadConfig(configFlag) + loadConfigFile(configFilePath) // Disable all widgets to stop scheduler goroutines and rmeove widgets from memory. disableAllWidgets() makeWidgets(app, pages) @@ -145,7 +175,7 @@ func watchForConfigChanges(app *tview.Application, configFlag string, grid *tvie }() // Watch config file for changes. - if err := watch.Add(configFlag); err != nil { + if err := watch.Add(configFilePath); err != nil { log.Fatalln(err) } @@ -217,36 +247,6 @@ func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) { } func makeWidgets(app *tview.Application, pages *tview.Pages) { - // 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 - mods, _ := Config.Map("wtf.mods") for mod := range mods { if enabled := Config.UBool("wtf.mods."+mod+".enabled", false); enabled { @@ -275,9 +275,9 @@ func main() { } cfg.CreateConfigDir() - cfg.WriteConfigFile() + cfg.CreateConfigFile() + loadConfigFile(flags.ConfigFilePath()) - loadConfig(flags.Config) setTerm() app := tview.NewApplication() From 6086690be76f9fb33413fea9b5ba418799ed4eaf Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 12:46:16 -0700 Subject: [PATCH 06/12] Make flags package responsible for its own display --- flags/flags.go | 15 ++++++++++++++- wtf.go | 15 +++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/flags/flags.go b/flags/flags.go index 3e798e4e..48904c36 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -6,6 +6,7 @@ import ( "path/filepath" goFlags "github.com/jessevdk/go-flags" + "github.com/senorprogrammer/wtf/help" "github.com/senorprogrammer/wtf/wtf" ) @@ -26,6 +27,18 @@ func (flags *Flags) ConfigFilePath() string { return flags.Config } +func (flags *Flags) Display(version string) { + if flags.HasModule() { + help.Display(flags.Module) + os.Exit(0) + } + + if flags.HasVersion() { + fmt.Println(version) + os.Exit(0) + } +} + func (flags *Flags) HasConfig() bool { return len(flags.Config) > 0 } @@ -38,7 +51,7 @@ func (flags *Flags) HasVersion() bool { return flags.Version == true } -func (flags *Flags) Parse(version string) { +func (flags *Flags) Parse() { parser := goFlags.NewParser(flags, goFlags.Default) if _, err := parser.Parse(); err != nil { if flagsErr, ok := err.(*goFlags.Error); ok && flagsErr.Type == goFlags.ErrHelp { diff --git a/wtf.go b/wtf.go index dd25461c..df5ce5d6 100644 --- a/wtf.go +++ b/wtf.go @@ -25,7 +25,6 @@ import ( "github.com/senorprogrammer/wtf/github" "github.com/senorprogrammer/wtf/gitlab" "github.com/senorprogrammer/wtf/gspreadsheets" - "github.com/senorprogrammer/wtf/help" "github.com/senorprogrammer/wtf/ipaddresses/ipapi" "github.com/senorprogrammer/wtf/ipaddresses/ipinfo" "github.com/senorprogrammer/wtf/jenkins" @@ -248,6 +247,7 @@ func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) { func makeWidgets(app *tview.Application, pages *tview.Pages) { mods, _ := Config.Map("wtf.mods") + for mod := range mods { if enabled := Config.UBool("wtf.mods."+mod+".enabled", false); enabled { addWidget(app, pages, mod) @@ -262,17 +262,8 @@ func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) flags := flags.NewFlags() - flags.Parse(version) - - if flags.HasModule() { - help.Display(flags.Module) - os.Exit(0) - } - - if flags.HasVersion() { - fmt.Println(version) - os.Exit(0) - } + flags.Parse() + flags.Display(version) cfg.CreateConfigDir() cfg.CreateConfigFile() From 0fc23761793b9fa2134e527d843891d8f73f6b58 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 14:04:48 -0700 Subject: [PATCH 07/12] Add a widget to display the log file in reverse order --- logging/log.go | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ wtf.go | 7 +++- wtf/log.go | 26 ------------ 3 files changed, 115 insertions(+), 28 deletions(-) create mode 100644 logging/log.go delete mode 100644 wtf/log.go diff --git a/logging/log.go b/logging/log.go new file mode 100644 index 00000000..9b87f4f6 --- /dev/null +++ b/logging/log.go @@ -0,0 +1,110 @@ +package logging + +import ( + "fmt" + //"io/ioutil" + "log" + "os" + "path/filepath" + "strings" + + "github.com/senorprogrammer/wtf/wtf" +) + +const maxBufferSize int64 = 1024 + +type Widget struct { + wtf.TextWidget + + filePath string +} + +func NewWidget() *Widget { + widget := Widget{ + TextWidget: wtf.NewTextWidget(" Logs ", "logging", true), + + filePath: logFilePath(), + } + + return &widget +} + +/* -------------------- Exported Functions -------------------- */ + +func Log(msg string) { + if logFileMissing() { + return + } + + f, err := os.OpenFile(logFilePath(), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + if err != nil { + log.Fatalf("error opening file: %v", err) + } + defer f.Close() + + log.SetOutput(f) + log.Println(msg) +} + +func (widget *Widget) Refresh() { + if logFileMissing() { + return + } + + widget.UpdateRefreshedAt() + widget.View.SetTitle(fmt.Sprintf("%s", widget.Name)) + + widget.View.SetText(fmt.Sprintf("%s", widget.tailFile())) +} + +/* -------------------- Unexported Functions -------------------- */ + +func logFileMissing() bool { + return logFilePath() == "" +} + +func logFilePath() string { + dir, err := wtf.Home() + if err != nil { + return "" + } + + return filepath.Join(dir, ".wtf", "log.txt") +} + +func (widget *Widget) tailFile() string { + file, err := os.Open(widget.filePath) + if err != nil { + return "" + } + defer file.Close() + + stat, err := file.Stat() + if err != nil { + return "" + } + + bufferSize := maxBufferSize + if maxBufferSize > stat.Size() { + bufferSize = stat.Size() + } + + startPos := stat.Size() - bufferSize + + buff := make([]byte, bufferSize) + _, err = file.ReadAt(buff, startPos) + if err != nil { + return "" + } + + dataArr := strings.Split(string(buff), "\n") + + // Reverse the array of lines + // Offset by two to account for the blank line at the end + last := len(dataArr) - 2 + for i := 0; i < len(dataArr)/2; i++ { + dataArr[i], dataArr[last-i] = dataArr[last-i], dataArr[i] + } + + return fmt.Sprintf("%s\n", strings.Join(dataArr, "\n")) +} diff --git a/wtf.go b/wtf.go index df5ce5d6..2e35179a 100644 --- a/wtf.go +++ b/wtf.go @@ -29,6 +29,7 @@ import ( "github.com/senorprogrammer/wtf/ipaddresses/ipinfo" "github.com/senorprogrammer/wtf/jenkins" "github.com/senorprogrammer/wtf/jira" + "github.com/senorprogrammer/wtf/logging" "github.com/senorprogrammer/wtf/newrelic" "github.com/senorprogrammer/wtf/opsgenie" "github.com/senorprogrammer/wtf/power" @@ -221,6 +222,8 @@ func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) { Widgets = append(Widgets, jenkins.NewWidget()) case "jira": Widgets = append(Widgets, jira.NewWidget()) + case "logging": + Widgets = append(Widgets, logging.NewWidget()) case "newrelic": Widgets = append(Widgets, newrelic.NewWidget()) case "opsgenie": @@ -285,10 +288,10 @@ func main() { go redrawApp(app) go watchForConfigChanges(app, flags.Config, display.Grid, pages) + logging.Log("Running!") + if err := app.SetRoot(pages, true).Run(); err != nil { fmt.Printf("Error: %v\n", err) os.Exit(1) } - - wtf.Log("Running!") } diff --git a/wtf/log.go b/wtf/log.go deleted file mode 100644 index eaada6f6..00000000 --- a/wtf/log.go +++ /dev/null @@ -1,26 +0,0 @@ -package wtf - -import ( - "log" - "os" - "path/filepath" -) - -//Log basic message logging, defaults to ~/.wtf/log.txt -func Log(message string) { - - dir, err := Home() - if err != nil { - return - } - - logfile := filepath.Join(dir, ".wtf", "log.txt") - f, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) - if err != nil { - log.Fatalf("error opening file: %v", err) - } - defer f.Close() - - log.SetOutput(f) - log.Println(message) -} From b2ee2d43d014d438ee6e9f5d5b183df366826c91 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 14:18:13 -0700 Subject: [PATCH 08/12] Colourize the log file output --- logging/log.go | 40 ++++++++++++++++++++++++++++++---------- newrelic/widget.go | 2 +- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/logging/log.go b/logging/log.go index 9b87f4f6..b2147ea0 100644 --- a/logging/log.go +++ b/logging/log.go @@ -54,11 +54,31 @@ func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() widget.View.SetTitle(fmt.Sprintf("%s", widget.Name)) - widget.View.SetText(fmt.Sprintf("%s", widget.tailFile())) + logLines := widget.tailFile() + widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(logLines))) } /* -------------------- Unexported Functions -------------------- */ +func (widget *Widget) contentFrom(logLines []string) string { + str := "" + + for _, line := range logLines { + chunks := strings.Split(line, " ") + + if len(chunks) >= 4 { + str = str + fmt.Sprintf( + "[green]%s[white] [yellow]%s[white] %s\n", + chunks[0], + chunks[1], + strings.Join(chunks[3:], " "), + ) + } + } + + return str +} + func logFileMissing() bool { return logFilePath() == "" } @@ -72,16 +92,16 @@ func logFilePath() string { return filepath.Join(dir, ".wtf", "log.txt") } -func (widget *Widget) tailFile() string { +func (widget *Widget) tailFile() []string { file, err := os.Open(widget.filePath) if err != nil { - return "" + return []string{} } defer file.Close() stat, err := file.Stat() if err != nil { - return "" + return []string{} } bufferSize := maxBufferSize @@ -94,17 +114,17 @@ func (widget *Widget) tailFile() string { buff := make([]byte, bufferSize) _, err = file.ReadAt(buff, startPos) if err != nil { - return "" + return []string{} } - dataArr := strings.Split(string(buff), "\n") + logLines := strings.Split(string(buff), "\n") // Reverse the array of lines // Offset by two to account for the blank line at the end - last := len(dataArr) - 2 - for i := 0; i < len(dataArr)/2; i++ { - dataArr[i], dataArr[last-i] = dataArr[last-i], dataArr[i] + last := len(logLines) - 2 + for i := 0; i < len(logLines)/2; i++ { + logLines[i], logLines[last-i] = logLines[last-i], logLines[i] } - return fmt.Sprintf("%s\n", strings.Join(dataArr, "\n")) + return logLines } diff --git a/newrelic/widget.go b/newrelic/widget.go index ca16966f..ad4c333a 100644 --- a/newrelic/widget.go +++ b/newrelic/widget.go @@ -64,7 +64,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { lineColor = "lightblue" } - var revLen = 8 + revLen := 8 if revLen > len(deploy.Revision) { revLen = len(deploy.Revision) } From 966b2df52a5db81ad51245a42be578b16fcaaa52 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 14:26:52 -0700 Subject: [PATCH 09/12] Add documentation for Logging module --- _site/content/posts/modules/logging.md | 54 ++++++ .../hyde-hyde/layouts/partials/sidebar.html | 1 + docs/404.html | 1 + docs/categories/index.html | 1 + docs/index.html | 1 + docs/index.xml | 16 +- .../posts/configuration/attributes/index.html | 1 + docs/posts/configuration/index.html | 1 + docs/posts/configuration/iterm2/index.html | 1 + docs/posts/glossary/index.html | 1 + docs/posts/index.html | 8 + docs/posts/index.xml | 16 +- docs/posts/installation/index.html | 1 + docs/posts/modules/bamboohr/index.html | 1 + docs/posts/modules/circleci/index.html | 1 + docs/posts/modules/clocks/index.html | 1 + docs/posts/modules/cmdrunner/index.html | 1 + .../cryptocurrencies/bittrex/index.html | 1 + .../cryptocurrencies/blockfolio/index.html | 1 + .../cryptocurrencies/cryptolive/index.html | 1 + docs/posts/modules/gcal/index.html | 1 + docs/posts/modules/git/index.html | 1 + docs/posts/modules/github/index.html | 1 + docs/posts/modules/gitlab/index.html | 1 + docs/posts/modules/gspreadsheet/index.html | 1 + docs/posts/modules/index.html | 1 + docs/posts/modules/ipapi/index.html | 1 + docs/posts/modules/ipinfo/index.html | 1 + docs/posts/modules/jenkins/index.html | 1 + docs/posts/modules/jira/index.html | 1 + docs/posts/modules/logging/index.html | 171 ++++++++++++++++++ docs/posts/modules/newrelic/index.html | 1 + docs/posts/modules/opsgenie/index.html | 1 + docs/posts/modules/power/index.html | 1 + docs/posts/modules/prettyweather/index.html | 1 + docs/posts/modules/security/index.html | 1 + docs/posts/modules/textfile/index.html | 1 + docs/posts/modules/todo/index.html | 1 + docs/posts/modules/weather/index.html | 1 + docs/posts/overview/index.html | 1 + docs/sitemap.xml | 9 +- docs/tags/index.html | 1 + 42 files changed, 306 insertions(+), 4 deletions(-) create mode 100644 _site/content/posts/modules/logging.md create mode 100644 docs/posts/modules/logging/index.html diff --git a/_site/content/posts/modules/logging.md b/_site/content/posts/modules/logging.md new file mode 100644 index 00000000..544cd701 --- /dev/null +++ b/_site/content/posts/modules/logging.md @@ -0,0 +1,54 @@ +--- +title: "Logging" +date: 2018-06-16T14:22:18-07:00 +draft: false +--- + +Displays the contents of the WTF log file. + +To log to this file in your own modules: + +```golang +require "github.com/senorprogrammer/wtf/logging" + logging.Log("This is a log entry") +``` + +## Source Code + +```bash +wtf/logging/ +``` + +## Required ENV Variables + +None. + +## Keyboard Commands + +Arrow keys scroll through the log file. + +## Configuration + +```yaml +textfile: + enabled: true + position: + top: 5 + left: 4 + height: 2 + width: 1 + refreshInterval: 1 +``` + +### Attributes + +`enabled`
+Determines whether or not this module is executed and if its data displayed onscreen.
+Values: `true`, `false`. + +`position`
+Defines where in the grid this module's widget will be displayed.
+ +`refreshInterval`
+How often, in seconds, this module will update its data.
+Values: A positive integer, `0..n`. diff --git a/_site/themes/hyde-hyde/layouts/partials/sidebar.html b/_site/themes/hyde-hyde/layouts/partials/sidebar.html index a5b24d6a..9c7e92f2 100644 --- a/_site/themes/hyde-hyde/layouts/partials/sidebar.html +++ b/_site/themes/hyde-hyde/layouts/partials/sidebar.html @@ -38,6 +38,7 @@ + diff --git a/docs/404.html b/docs/404.html index 7ce23127..abc09821 100644 --- a/docs/404.html +++ b/docs/404.html @@ -79,6 +79,7 @@ + diff --git a/docs/categories/index.html b/docs/categories/index.html index a0c96c23..959cb245 100644 --- a/docs/categories/index.html +++ b/docs/categories/index.html @@ -81,6 +81,7 @@ + diff --git a/docs/index.html b/docs/index.html index 62d70dbe..99975824 100644 --- a/docs/index.html +++ b/docs/index.html @@ -80,6 +80,7 @@ + diff --git a/docs/index.xml b/docs/index.xml index d5b16ac5..4249f027 100644 --- a/docs/index.xml +++ b/docs/index.xml @@ -6,11 +6,25 @@ Recent content on WTF - A Terminal Dashboard Hugo -- gohugo.io en-us - Wed, 13 Jun 2018 09:29:59 -0700 + Sat, 16 Jun 2018 14:22:18 -0700 + + Logging + https://wtfutil.com/posts/modules/logging/ + Sat, 16 Jun 2018 14:22:18 -0700 + + https://wtfutil.com/posts/modules/logging/ + Displays the contents of the WTF log file. +To log to this file in your own modules: +require &#34;github.com/senorprogrammer/wtf/logging&#34; logging.Log(&#34;This is a log entry&#34;) Source Code wtf/logging/ Required ENV Variables None. +Keyboard Commands Arrow keys scroll through the log file. +Configuration textfile:enabled:trueposition:top:5left:4height:2width:1refreshInterval:1 Attributes enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false. +position Defines where in the grid this module&rsquo;s widget will be displayed. + + Blockfolio https://wtfutil.com/posts/modules/cryptocurrencies/blockfolio/ diff --git a/docs/posts/configuration/attributes/index.html b/docs/posts/configuration/attributes/index.html index a7513494..45f00e4b 100644 --- a/docs/posts/configuration/attributes/index.html +++ b/docs/posts/configuration/attributes/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/configuration/index.html b/docs/posts/configuration/index.html index de751889..24262a30 100644 --- a/docs/posts/configuration/index.html +++ b/docs/posts/configuration/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/configuration/iterm2/index.html b/docs/posts/configuration/iterm2/index.html index c240c3db..ad673ae2 100644 --- a/docs/posts/configuration/iterm2/index.html +++ b/docs/posts/configuration/iterm2/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/glossary/index.html b/docs/posts/glossary/index.html index 192fde00..67d7d7f9 100644 --- a/docs/posts/glossary/index.html +++ b/docs/posts/glossary/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/index.html b/docs/posts/index.html index b7b08c55..f7df2293 100644 --- a/docs/posts/index.html +++ b/docs/posts/index.html @@ -81,6 +81,7 @@ + @@ -105,6 +106,13 @@

Posts

  • + + Logging + + + + +
  • Blockfolio diff --git a/docs/posts/index.xml b/docs/posts/index.xml index 82b0045a..5c85acd5 100644 --- a/docs/posts/index.xml +++ b/docs/posts/index.xml @@ -6,11 +6,25 @@ Recent content in Posts on WTF - A Terminal Dashboard Hugo -- gohugo.io en-us - Wed, 13 Jun 2018 09:29:59 -0700 + Sat, 16 Jun 2018 14:22:18 -0700 + + Logging + https://wtfutil.com/posts/modules/logging/ + Sat, 16 Jun 2018 14:22:18 -0700 + + https://wtfutil.com/posts/modules/logging/ + Displays the contents of the WTF log file. +To log to this file in your own modules: +require &#34;github.com/senorprogrammer/wtf/logging&#34; logging.Log(&#34;This is a log entry&#34;) Source Code wtf/logging/ Required ENV Variables None. +Keyboard Commands Arrow keys scroll through the log file. +Configuration textfile:enabled:trueposition:top:5left:4height:2width:1refreshInterval:1 Attributes enabled Determines whether or not this module is executed and if its data displayed onscreen. Values: true, false. +position Defines where in the grid this module&rsquo;s widget will be displayed. + + Blockfolio https://wtfutil.com/posts/modules/cryptocurrencies/blockfolio/ diff --git a/docs/posts/installation/index.html b/docs/posts/installation/index.html index 7f06e343..6d389122 100644 --- a/docs/posts/installation/index.html +++ b/docs/posts/installation/index.html @@ -79,6 +79,7 @@
  • + diff --git a/docs/posts/modules/bamboohr/index.html b/docs/posts/modules/bamboohr/index.html index e5d9613e..45cbb7c8 100644 --- a/docs/posts/modules/bamboohr/index.html +++ b/docs/posts/modules/bamboohr/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/circleci/index.html b/docs/posts/modules/circleci/index.html index ba519853..665c3486 100644 --- a/docs/posts/modules/circleci/index.html +++ b/docs/posts/modules/circleci/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/clocks/index.html b/docs/posts/modules/clocks/index.html index 08f316a5..a72f5d4e 100644 --- a/docs/posts/modules/clocks/index.html +++ b/docs/posts/modules/clocks/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/cmdrunner/index.html b/docs/posts/modules/cmdrunner/index.html index 880401b3..dd014aa4 100644 --- a/docs/posts/modules/cmdrunner/index.html +++ b/docs/posts/modules/cmdrunner/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/cryptocurrencies/bittrex/index.html b/docs/posts/modules/cryptocurrencies/bittrex/index.html index d4bcabef..9a71e071 100644 --- a/docs/posts/modules/cryptocurrencies/bittrex/index.html +++ b/docs/posts/modules/cryptocurrencies/bittrex/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/cryptocurrencies/blockfolio/index.html b/docs/posts/modules/cryptocurrencies/blockfolio/index.html index 387ef88b..26653c38 100644 --- a/docs/posts/modules/cryptocurrencies/blockfolio/index.html +++ b/docs/posts/modules/cryptocurrencies/blockfolio/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/cryptocurrencies/cryptolive/index.html b/docs/posts/modules/cryptocurrencies/cryptolive/index.html index abbbeab4..c187ed6e 100644 --- a/docs/posts/modules/cryptocurrencies/cryptolive/index.html +++ b/docs/posts/modules/cryptocurrencies/cryptolive/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/gcal/index.html b/docs/posts/modules/gcal/index.html index efcfb948..f849337b 100644 --- a/docs/posts/modules/gcal/index.html +++ b/docs/posts/modules/gcal/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/git/index.html b/docs/posts/modules/git/index.html index ddc9736b..3829d892 100644 --- a/docs/posts/modules/git/index.html +++ b/docs/posts/modules/git/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/github/index.html b/docs/posts/modules/github/index.html index c3c90345..bfe3888b 100644 --- a/docs/posts/modules/github/index.html +++ b/docs/posts/modules/github/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/gitlab/index.html b/docs/posts/modules/gitlab/index.html index 5da8c1ef..4bb6912e 100644 --- a/docs/posts/modules/gitlab/index.html +++ b/docs/posts/modules/gitlab/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/gspreadsheet/index.html b/docs/posts/modules/gspreadsheet/index.html index 17e5e82c..ae4be0af 100644 --- a/docs/posts/modules/gspreadsheet/index.html +++ b/docs/posts/modules/gspreadsheet/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/index.html b/docs/posts/modules/index.html index da012a25..8437db77 100644 --- a/docs/posts/modules/index.html +++ b/docs/posts/modules/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/ipapi/index.html b/docs/posts/modules/ipapi/index.html index a4ed8f11..ccabe254 100644 --- a/docs/posts/modules/ipapi/index.html +++ b/docs/posts/modules/ipapi/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/ipinfo/index.html b/docs/posts/modules/ipinfo/index.html index ccb0f4e5..1759df89 100644 --- a/docs/posts/modules/ipinfo/index.html +++ b/docs/posts/modules/ipinfo/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/jenkins/index.html b/docs/posts/modules/jenkins/index.html index 561b0108..83ba6b2c 100644 --- a/docs/posts/modules/jenkins/index.html +++ b/docs/posts/modules/jenkins/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/jira/index.html b/docs/posts/modules/jira/index.html index aa8d189b..129089e5 100644 --- a/docs/posts/modules/jira/index.html +++ b/docs/posts/modules/jira/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/logging/index.html b/docs/posts/modules/logging/index.html new file mode 100644 index 00000000..50587fa2 --- /dev/null +++ b/docs/posts/modules/logging/index.html @@ -0,0 +1,171 @@ + + + + + + + + + + + + +Logging | WTF - A Terminal Dashboard + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +

    Logging

    + +
    + +
    + + + +

    Displays the contents of the WTF log file.

    + +

    To log to this file in your own modules:

    +
    require "github.com/senorprogrammer/wtf/logging"
    + logging.Log("This is a log entry")
    +

    Source Code

    +
    wtf/logging/
    +

    Required ENV Variables

    + +

    None.

    + +

    Keyboard Commands

    + +

    Arrow keys scroll through the log file.

    + +

    Configuration

    +
    textfile:
    +  enabled: true
    +  position:
    +    top: 5
    +    left: 4
    +    height: 2
    +    width: 1
    +  refreshInterval: 1
    +

    Attributes

    + +

    enabled
    +Determines whether or not this module is executed and if its data displayed onscreen.
    +Values: true, false.

    + +

    position
    +Defines where in the grid this module’s widget will be displayed.

    + +

    refreshInterval
    +How often, in seconds, this module will update its data.
    +Values: A positive integer, 0..n.

    + +
    + + +
    + + + + diff --git a/docs/posts/modules/newrelic/index.html b/docs/posts/modules/newrelic/index.html index 669c374d..1330419d 100644 --- a/docs/posts/modules/newrelic/index.html +++ b/docs/posts/modules/newrelic/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/opsgenie/index.html b/docs/posts/modules/opsgenie/index.html index 955d28ea..67e5f02f 100644 --- a/docs/posts/modules/opsgenie/index.html +++ b/docs/posts/modules/opsgenie/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/power/index.html b/docs/posts/modules/power/index.html index 4cb003c3..088d69d0 100644 --- a/docs/posts/modules/power/index.html +++ b/docs/posts/modules/power/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/prettyweather/index.html b/docs/posts/modules/prettyweather/index.html index 91b1abe3..703ddad6 100644 --- a/docs/posts/modules/prettyweather/index.html +++ b/docs/posts/modules/prettyweather/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/security/index.html b/docs/posts/modules/security/index.html index 21b12d9b..d53bf968 100644 --- a/docs/posts/modules/security/index.html +++ b/docs/posts/modules/security/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/textfile/index.html b/docs/posts/modules/textfile/index.html index d73fb57d..0f25da96 100644 --- a/docs/posts/modules/textfile/index.html +++ b/docs/posts/modules/textfile/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/todo/index.html b/docs/posts/modules/todo/index.html index 20501206..7cec31de 100644 --- a/docs/posts/modules/todo/index.html +++ b/docs/posts/modules/todo/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/modules/weather/index.html b/docs/posts/modules/weather/index.html index 213ec3cf..4e8af80c 100644 --- a/docs/posts/modules/weather/index.html +++ b/docs/posts/modules/weather/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/posts/overview/index.html b/docs/posts/overview/index.html index bac121e8..05cf5186 100644 --- a/docs/posts/overview/index.html +++ b/docs/posts/overview/index.html @@ -79,6 +79,7 @@ + diff --git a/docs/sitemap.xml b/docs/sitemap.xml index dc6caed1..99e7b0f9 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -2,6 +2,11 @@ + + https://wtfutil.com/posts/modules/logging/ + 2018-06-16T14:22:18-07:00 + + https://wtfutil.com/posts/modules/cryptocurrencies/blockfolio/ 2018-06-13T09:29:59-07:00 @@ -164,7 +169,7 @@ https://wtfutil.com/posts/ - 2018-06-13T09:29:59-07:00 + 2018-06-16T14:22:18-07:00 0 @@ -175,7 +180,7 @@ https://wtfutil.com/ - 2018-06-13T09:29:59-07:00 + 2018-06-16T14:22:18-07:00 0 diff --git a/docs/tags/index.html b/docs/tags/index.html index f816472b..9de5bb91 100644 --- a/docs/tags/index.html +++ b/docs/tags/index.html @@ -81,6 +81,7 @@ + From eb5f09e65ca8a4eca41449721079ad349ed492c6 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 14:59:22 -0700 Subject: [PATCH 10/12] 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 } From 993166e57d0efaa1f1954a085941bce7b9e88896 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 15:07:40 -0700 Subject: [PATCH 11/12] Clean up some colourizing switch statements --- jenkins/widget.go | 10 +++------- jira/widget.go | 12 ++++-------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/jenkins/widget.go b/jenkins/widget.go index 32133d2e..943f78c7 100644 --- a/jenkins/widget.go +++ b/jenkins/widget.go @@ -67,16 +67,12 @@ func (widget *Widget) contentFrom(view *View) string { } func (widget *Widget) jobColor(job *Job) string { - var color string - switch job.Color { case "blue": - color = "green" + return "blue" case "red": - color = "red" + return "red" default: - color = "white" + return "white" } - - return color } diff --git a/jira/widget.go b/jira/widget.go index 62b0bb41..4ae7a4a7 100644 --- a/jira/widget.go +++ b/jira/widget.go @@ -66,20 +66,16 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string { } func (widget *Widget) issueTypeColor(issue *Issue) string { - var color string - switch issue.IssueFields.IssueType.Name { case "Bug": - color = "red" + return "red" case "Story": - color = "blue" + return "blue" case "Task": - color = "orange" + return "orange" default: - color = "white" + return "white" } - - return color } func getProjects() []string { From 3309579689c3b9efcc017da59d399a32747fdbe3 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 16 Jun 2018 22:17:10 -0700 Subject: [PATCH 12/12] Rename logging/ to logger/ --- {logging => logger}/log.go | 2 +- wtf.go | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) rename {logging => logger}/log.go (99%) diff --git a/logging/log.go b/logger/log.go similarity index 99% rename from logging/log.go rename to logger/log.go index b2147ea0..7c594520 100644 --- a/logging/log.go +++ b/logger/log.go @@ -1,4 +1,4 @@ -package logging +package logger import ( "fmt" diff --git a/wtf.go b/wtf.go index 55aa0def..3c89731e 100644 --- a/wtf.go +++ b/wtf.go @@ -29,7 +29,7 @@ import ( "github.com/senorprogrammer/wtf/ipaddresses/ipinfo" "github.com/senorprogrammer/wtf/jenkins" "github.com/senorprogrammer/wtf/jira" - "github.com/senorprogrammer/wtf/logging" + "github.com/senorprogrammer/wtf/logger" "github.com/senorprogrammer/wtf/newrelic" "github.com/senorprogrammer/wtf/opsgenie" "github.com/senorprogrammer/wtf/power" @@ -194,7 +194,7 @@ func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) { case "jira": Widgets = append(Widgets, jira.NewWidget()) case "logging": - Widgets = append(Widgets, logging.NewWidget()) + Widgets = append(Widgets, logger.NewWidget()) case "newrelic": Widgets = append(Widgets, newrelic.NewWidget()) case "opsgenie": @@ -259,8 +259,6 @@ func main() { go redrawApp(app) go watchForConfigChanges(app, flags.Config, display.Grid, pages) - logging.Log("Running!") - if err := app.SetRoot(pages, true).Run(); err != nil { fmt.Printf("Error: %v\n", err) os.Exit(1)