logreader.go

v0.7.0
Doc Versions Source
1
package cmd
2
3
import (
4
	"fmt"
5
	"os"
6
7
	tea "github.com/charmbracelet/bubbletea"
8
	"github.com/spf13/cobra"
9
	"sourcecraft.dev/bigbes/claudio/logreader"
10
)
11
12
var logReaderPath string
13
14
var logReaderCmd = &cobra.Command{
15
	Use:   "log-reader",
16
	Short: "Interactive TUI viewer for proxy debug logs",
17
	RunE:  runLogReader,
18
}
19
20
func init() {
21
	logReaderCmd.Flags().StringVarP(&logReaderPath, "path", "p", "./claude-proxy.log", "Path to the log file")
22
	rootCmd.AddCommand(logReaderCmd)
23
}
24
25
func runLogReader(cmd *cobra.Command, args []string) error {
26
	f, err := os.Open(logReaderPath)
27
	if err != nil {
28
		return fmt.Errorf("opening log file: %w", err)
29
	}
30
	defer f.Close()
31
32
	entries := logreader.Parse(f)
33
	if len(entries) == 0 {
34
		fmt.Println("No log entries found in", logReaderPath)
35
		return nil
36
	}
37
38
	m := logreader.New(entries)
39
	p := tea.NewProgram(m, tea.WithAltScreen())
40
	if _, err := p.Run(); err != nil {
41
		return fmt.Errorf("TUI error: %w", err)
42
	}
43
	return nil
44
}
45

Source Files