Skip to content

Commit

Permalink
improving log content
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Collins <[email protected]>
  • Loading branch information
clcollins committed Jun 6, 2024
1 parent d80e670 commit c4a8dc0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 107 deletions.
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func checkSettings() {

for _, k := range keys {
if deprecation.Deprecated(k) {
log.Info(fmt.Sprintf("Found deprecated key: `%v`; you may remove this from your config.", k))
log.Info("Found deprecated key; you may remove this from your config", k)
continue
}

Expand All @@ -117,7 +117,7 @@ func checkSettings() {
v = "*****"
}

log.Debug(fmt.Sprintf("Found key: `%v`, value: `%v`", k, v))
log.Debug("Found key", k, v)

}
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/tui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

"github.com/PagerDuty/go-pagerduty"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/log"
"github.com/clcollins/srepd/pkg/launcher"
"github.com/clcollins/srepd/pkg/pd"
"github.com/charmbracelet/log"
)

const (
Expand Down Expand Up @@ -72,7 +72,6 @@ func updateIncidentList(p *pd.Config) tea.Cmd {

// Retrieve incidents assigned to the TeamIDs and filtered UserIDs
i, err := pd.GetIncidents(p.Client, opts)
log.Debug(fmt.Sprintf("tui.updateIncidentList(): retrieved %v incidents after filtering", len(i)))
return updatedIncidentListMsg{i, err}
}
}
Expand Down Expand Up @@ -424,16 +423,15 @@ func acknowledged(a []pagerduty.Acknowledgement) string {
}

func doIfIncidentSelected(m *model, cmd tea.Cmd) tea.Cmd {
log.Debug("doIfIncidentSelected()")
if m.table.SelectedRow() == nil {
log.Debug("doIfIncidentSelected(): selected row is nil")
log.Debug("doIfIncidentSelected", "selectedRow", "nil")
m.setStatus(nilIncidentErr)
m.viewingIncident = false
return tea.Sequence(
func() tea.Msg { return errMsg{errors.New(nilIncidentErr)} },
)
}
log.Debug("doIfIncidentSelected(): got selected row")
log.Debug("doIfIncidentSelected", "selectedRow", m.table.SelectedRow())
return tea.Sequence(
func() tea.Msg { return getIncidentMsg(m.table.SelectedRow()[1]) },
cmd,
Expand Down
19 changes: 3 additions & 16 deletions pkg/tui/model.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package tui

import (
"fmt"

"github.com/PagerDuty/go-pagerduty"
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/table"
"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/log"
"github.com/clcollins/srepd/pkg/launcher"
"github.com/clcollins/srepd/pkg/pd"
"github.com/charmbracelet/log"
)

type model struct {
Expand Down Expand Up @@ -46,7 +44,6 @@ func InitialModel(
editor []string,
launcher launcher.ClusterLauncher,
) (tea.Model, tea.Cmd) {
log.Debug("InitialModel")
var err error

m := model{
Expand Down Expand Up @@ -74,29 +71,21 @@ func InitialModel(
}

func (m *model) setStatus(msg string) {
var d []string

m.status = fmt.Sprint(msg)

d = append(d, "setStatus")
d = append(d, msg)

log.Infof("%s", d)
log.Info("setStatus", "status", msg)
m.status = msg
}

func (m *model) toggleHelp() {
m.help.ShowAll = !m.help.ShowAll
}

func newTableWithStyles() table.Model {
log.Debug("newTableWithStyles")
t := table.New(table.WithFocused(true))
t.SetStyles(tableStyle)
return t
}

func newTextInput() textinput.Model {
log.Debug("newTextInput")
i := textinput.New()
i.Prompt = " $ "
i.CharLimit = 32
Expand All @@ -105,14 +94,12 @@ func newTextInput() textinput.Model {
}

func newHelp() help.Model {
log.Debug("newHelp")
h := help.New()
h.ShowAll = true
return h
}

func newIncidentViewer() viewport.Model {
log.Debug("newIncidentViewer")
vp := viewport.New(100, 100)
vp.Style = incidentViewerStyle
return vp
Expand Down
18 changes: 7 additions & 11 deletions pkg/tui/msgHandlers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tui

import (
"fmt"
"reflect"

"github.com/PagerDuty/go-pagerduty"
"github.com/charmbracelet/bubbles/key"
Expand All @@ -12,7 +12,7 @@ import (

// errMsgHandler is the message handler for the errMsg message
func (m model) errMsgHandler(msg tea.Msg) (tea.Model, tea.Cmd) {
log.Warn("errMsgHandler")
log.Error("errMsgHandler", "tea.errMsg", msg)
m.setStatus(msg.(errMsg).Error())
m.err = msg.(errMsg)
return m, nil
Expand All @@ -21,8 +21,6 @@ func (m model) errMsgHandler(msg tea.Msg) (tea.Model, tea.Cmd) {
// windowSizeMsgHandler is the message handler for the windowSizeMsg message
// and resizes the tui according to the new terminal window size
func (m model) windowSizeMsgHandler(msg tea.Msg) (tea.Model, tea.Cmd) {
log.Debug("windowSizeMsgHandler")
m.setStatus(fmt.Sprintf("window size changed: %v", msg.(tea.WindowSizeMsg)))
windowSize = msg.(tea.WindowSizeMsg)
top, _, bottom, _ := mainStyle.GetMargin()
eighthWindow := windowSize.Width / 8
Expand All @@ -47,7 +45,6 @@ func (m model) windowSizeMsgHandler(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m model) keyMsgHandler(msg tea.Msg) (tea.Model, tea.Cmd) {
log.Debug("keyMsgHandler", "tea.KeyMsg", fmt.Sprint(msg))
if key.Matches(msg.(tea.KeyMsg), defaultKeyMap.Quit) {
return m, tea.Quit
}
Expand All @@ -72,7 +69,7 @@ func (m model) keyMsgHandler(msg tea.Msg) (tea.Model, tea.Cmd) {

// tableFocusMode is the main mode for the application
func switchTableFocusMode(m model, msg tea.Msg) (tea.Model, tea.Cmd) {
log.Debug("switchTableFocusMode")
log.Debug("switchTableFocusMode", reflect.TypeOf(msg), msg)
var cmds []tea.Cmd

switch msg := msg.(type) {
Expand All @@ -95,15 +92,14 @@ func switchTableFocusMode(m model, msg tea.Msg) (tea.Model, tea.Cmd) {

case key.Matches(msg, defaultKeyMap.Enter):
m.viewingIncident = true
// TODO TODAY - fix this
log.Debug("Enter key pressed")
return m, doIfIncidentSelected(&m, func() tea.Msg {
return waitForSelectedIncidentThenDoMsg{action: func() tea.Msg { return renderIncidentMsg("render") }, msg: "render"}
},
)

case key.Matches(msg, defaultKeyMap.Team):
m.teamMode = !m.teamMode
log.Debug("switchTableFocusMode", "teamMode", m.teamMode)
cmds = append(cmds, func() tea.Msg { return updatedIncidentListMsg{m.incidentList, nil} })

case key.Matches(msg, defaultKeyMap.Refresh):
Expand Down Expand Up @@ -167,7 +163,7 @@ func switchTableFocusMode(m model, msg tea.Msg) (tea.Model, tea.Cmd) {
}

func switchInputFocusMode(m model, msg tea.Msg) (tea.Model, tea.Cmd) {
log.Debug("switchInputFocusMode")
log.Debug("switchInputFocusMode", reflect.TypeOf(msg), msg)
var cmds []tea.Cmd

switch msg := msg.(type) {
Expand All @@ -190,7 +186,7 @@ func switchInputFocusMode(m model, msg tea.Msg) (tea.Model, tea.Cmd) {
}

func switchIncidentFocusMode(m model, msg tea.Msg) (tea.Model, tea.Cmd) {
log.Debug("switchIncidentFocusMode")
log.Debug("switchIncidentFocusMode", reflect.TypeOf(msg), msg)
var cmd tea.Cmd
var cmds []tea.Cmd

Expand Down Expand Up @@ -236,7 +232,7 @@ func switchIncidentFocusMode(m model, msg tea.Msg) (tea.Model, tea.Cmd) {
}

func switchErrorFocusMode(m model, msg tea.Msg) (tea.Model, tea.Cmd) {
log.Debug("switchErrorFocusMode")
log.Debug("switchErrorFocusMode", reflect.TypeOf(msg), msg)
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
Expand Down
Loading

0 comments on commit c4a8dc0

Please sign in to comment.