diff --git a/.gitignore b/.gitignore index d4c55a3..549b8c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .vscode/* build/* +hack/* +log/* *.log diff --git a/cmd/root.go b/cmd/root.go index 44bbfc5..6d671d6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -33,6 +33,7 @@ import ( "github.com/spf13/viper" ) +// TODO https://github.com/clcollins/srepd/issues/6 - allow custom commands const cfgFile = "srepd.yaml" const cfgFilePath = ".config/srepd/" const defaultEditor = "/usr/bin/vim" diff --git a/pkg/tui/commands.go b/pkg/tui/commands.go index 2cdf6c8..5d81e68 100644 --- a/pkg/tui/commands.go +++ b/pkg/tui/commands.go @@ -24,6 +24,7 @@ type waitForSelectedIncidentThenDoMsg struct { msg tea.Msg } +//lint:ignore U1000 - future proofing type waitForSelectedIncidentThenRenderMsg string func renderIncidentMarkdown(content string) (string, error) { @@ -43,6 +44,7 @@ func renderIncidentMarkdown(content string) (string, error) { return str, nil } +//lint:ignore U1000 - future proofing func updateSelectedIncident(p *pd.Config, id string) tea.Cmd { return tea.Sequence( getIncident(p, id), @@ -61,7 +63,6 @@ func updateIncidentList(p *pd.Config) tea.Cmd { return func() tea.Msg { opts := pd.NewListIncidentOptsFromDefaults() opts.TeamIDs = getTeamsAsStrings(p) - i, err := pd.GetIncidents(p.Client, opts) return updatedIncidentListMsg{i, err} } @@ -180,16 +181,17 @@ func openEditorCmd(editor string) tea.Cmd { }) } -type openOCMContainerMsg string -type ocmContainerFinishedMsg error +type openClusterMsg string +type openClusterFinishedMsg error -const term = "/usr/bin/gnome-terminal" -const clusterCmd = "o" +// Must not be aliases - must be real commands or links +const defaultTerm = "/usr/bin/gnome-terminal" +const defaultShell = "/bin/bash" +const defaultClusterCmd = "srepd_exec_ocm_container" -// TODO https://github.com/clcollins/srepd/issues/6 - allow custom commands -func openOCMContainer(cluster string) tea.Cmd { - debug("openOCMContainer") - c := exec.Command(term, "--", "/bin/bash", "srepd_exec_ocm_container", cluster) +func openCluster(cluster string) tea.Cmd { + debug("openCluster") + c := exec.Command(defaultTerm, "--", defaultShell, defaultClusterCmd, cluster) c.Stdin = os.Stdin c.Stdout = os.Stdout c.Stderr = os.Stderr @@ -203,7 +205,7 @@ func openOCMContainer(cluster string) tea.Cmd { } } return func() tea.Msg { - return ocmContainerFinishedMsg(nil) + return openClusterFinishedMsg(nil) } } @@ -272,6 +274,7 @@ func silenceIncidents(i []*pagerduty.Incident, u []*pagerduty.User) tea.Cmd { } } +//lint:ignore U1000 - future proofing type addIncidentNoteMsg string type waitForSelectedIncidentsThenAnnotateMsg string type addedIncidentNoteMsg struct { diff --git a/pkg/tui/commands_test.go b/pkg/tui/commands_test.go index 82ada78..44a93c8 100644 --- a/pkg/tui/commands_test.go +++ b/pkg/tui/commands_test.go @@ -2,6 +2,7 @@ package tui import "testing" +//lint:ignore U1000 - future proofing func testUpdateIncidentList(t *testing.T) { // updateIncidentList accepts a pointer to a pd.Config struct // and returns a tea.Cmd function. The tea.Cmd function returns diff --git a/pkg/tui/tui.go b/pkg/tui/tui.go index 78b02e7..befc3e7 100644 --- a/pkg/tui/tui.go +++ b/pkg/tui/tui.go @@ -189,7 +189,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Set the selected incident to the incident returned from the getIncident command case gotIncidentMsg: - debug("gotIncidentMsg", fmt.Sprint("TRUNCATED")) + debug("gotIncidentMsg", "TRUNCATED") if msg.err != nil { m.setStatus(msg.err.Error()) log.Fatal(msg.err) @@ -204,7 +204,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { ) case gotIncidentNotesMsg: - debug("gotIncidentNotesMsg", fmt.Sprint("TRUNCATED")) + debug("gotIncidentNotesMsg", "TRUNCATED") if msg.err != nil { m.setStatus(msg.err.Error()) log.Fatal(msg.err) @@ -220,7 +220,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } case gotIncidentAlertsMsg: - debug("gotIncidentAlertsMsg", fmt.Sprint("TRUNCATED")) + debug("gotIncidentAlertsMsg", "TRUNCATED") if msg.err != nil { m.setStatus(msg.err.Error()) log.Fatal(msg.err) @@ -261,7 +261,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, updateIncidentList(m.config)) case updatedIncidentListMsg: - debug("updatedIncidentListMsg", fmt.Sprint("TRUNCATED")) + debug("updatedIncidentListMsg", "TRUNCATED") if msg.err != nil { m.setStatus(msg.err.Error()) log.Fatal(msg.err) @@ -324,23 +324,23 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } cmds = append(cmds, func() tea.Msg { return getIncidentMsg(m.selectedIncident.ID) }) - case openOCMContainerMsg: - debug("openOCMContainerMsg", fmt.Sprint(msg)) + case openClusterMsg: + debug("openClusterMsg", fmt.Sprint(msg)) if len(m.selectedIncidentAlerts) == 0 { debug(fmt.Sprintf("no alerts found for incident %s - requeuing", m.selectedIncident.ID)) - return m, func() tea.Msg { return openOCMContainerMsg("sender: openOCMContainerMsg; requeue") } + return m, func() tea.Msg { return openClusterMsg("sender: openClusterMsg; requeue") } } if len(m.selectedIncidentAlerts) == 1 { cluster := getDetailFieldFromAlert("cluster_id", m.selectedIncidentAlerts[0]) m.setStatus(fmt.Sprintf("opening cluster %s", cluster)) - return m, func() tea.Msg { return openOCMContainer(cluster) } + return m, func() tea.Msg { return openCluster(cluster) } } // TODO https://github.com/clcollins/srepd/issues/1: Figure out how to prompt with list to select from cluster := getDetailFieldFromAlert("cluster_id", m.selectedIncidentAlerts[0]) m.setStatus(fmt.Sprintf("multiple alerts for incident - opening cluster %s from first alert %s", cluster, m.selectedIncidentAlerts[0].ID)) - return m, func() tea.Msg { return openOCMContainer(cluster) } + return m, func() tea.Msg { return openCluster(cluster) } case waitForSelectedIncidentThenDoMsg: debug("waitForSelectedIncidentThenDoMsg", fmt.Sprint(msg.action, msg.msg)) @@ -375,8 +375,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // func() tea.Msg { return clearSelectedIncidentsMsg("sender: acknowledgeIncidentsMsg") }, // ) // case "annotateIncidentsMsg": - case "openOCMContainerMsg": - return m, func() tea.Msg { return openOCMContainerMsg("open") } + // TODO: The "ACTION" here needs to be a tea.Msg, not a string + case "openClusterMsg": + return m, func() tea.Msg { return openClusterMsg("open") } // case "reassignIncidentsMsg": case "renderIncidentMsg": return m, func() tea.Msg { return renderIncidentMsg("render") } @@ -577,7 +578,7 @@ func switchTableFocusMode(m model, msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, defaultKeyMap.Open): return m, tea.Sequence( func() tea.Msg { return getIncidentMsg(m.table.SelectedRow()[1]) }, - func() tea.Msg { return waitForSelectedIncidentThenDoMsg{action: "openOCMContainerMsg", msg: "wait"} }, + func() tea.Msg { return waitForSelectedIncidentThenDoMsg{action: "openClusterMsg", msg: "wait"} }, ) } } @@ -628,7 +629,7 @@ func switchIncidentFocusedMode(m model, msg tea.Msg) (tea.Model, tea.Cmd) { case key.Matches(msg, defaultKeyMap.Open): return m, tea.Sequence( func() tea.Msg { return getIncidentMsg(m.table.SelectedRow()[1]) }, - func() tea.Msg { return waitForSelectedIncidentThenDoMsg{action: "openOCMContainerMsg", msg: "wait"} }, + func() tea.Msg { return waitForSelectedIncidentThenDoMsg{action: "openClusterMsg", msg: "wait"} }, ) } }