Files
pipelines/internal/tui/debug.go
T

44 lines
1.0 KiB
Go

package tui
import (
"fmt"
"os/exec"
"git.a-wan.net/alan/pipelines/internal/runinspect"
tea "github.com/charmbracelet/bubbletea"
)
type debugClosedMsg struct{ err error }
func (m Model) selectedRunID() int64 {
if !m.runOpen || m.runStartRequest != "" {
return 0
}
if m.runDetail != nil {
return m.runDetail.ID
}
if m.requestedRunID > 0 {
return 0
}
runs := m.visibleRuns()
if len(runs) > 0 {
return runs[min(m.runIndex, len(runs)-1)].ID
}
return 0
}
func (m Model) debugRun() (tea.Model, tea.Cmd) {
id := m.selectedRunID()
if id <= 0 {
m.appendLine("Select a loaded run to debug.")
return m, nil
}
cli, err := runinspect.CLIExecutable()
if err != nil {
m.appendLine("debug: pipelines CLI is unavailable: " + err.Error())
return m, nil
}
cmd := exec.Command(cli, "--url", m.url, "debug", fmt.Sprint(id), "--yes")
return m.confirmMutation(fmt.Sprintf("Open a new debugging session for run #%d?", id), func() tea.Cmd { return tea.ExecProcess(cmd, func(err error) tea.Msg { return debugClosedMsg{err} }) })
}