package main import ( "flag" "fmt" "os" "strings" "time" tea "github.com/charmbracelet/bubbletea" ) func main() { var ( repo = flag.String("repo", os.Getenv("GH_REPO"), "GitHub repository as owner/name (or GH_REPO)") poll = flag.Duration("poll", 10*time.Second, "refresh interval") showAll = flag.Bool("all", false, "show all open PRs, not only PRs authored by you") limit = flag.Int("limit", 50, "maximum open PRs to load (1-100)") endpoint = flag.String("endpoint", "https://api.github.com/graphql", "GitHub GraphQL endpoint") ) flag.Parse() parts := strings.Split(*repo, "/") if len(parts) != 2 || parts[0] == "" || parts[1] == "" { exitf("--repo owner/name (or GH_REPO) is required") } if *limit < 1 || *limit > 100 { exitf("--limit must be between 1 and 100") } if *poll < 2*time.Second { exitf("--poll must be at least 2s") } token, err := resolveToken(*endpoint) if err != nil { exitf("authenticate: %v", err) } client := NewGitHubClient(*endpoint, token) app := NewApp(client, parts[0], parts[1], *showAll, *limit, *poll) if _, err := tea.NewProgram(app, tea.WithAltScreen()).Run(); err != nil { exitf("run TUI: %v", err) } } func firstNonEmpty(values ...string) string { for _, value := range values { if value != "" { return value } } return "" } func exitf(format string, args ...any) { fmt.Fprintf(os.Stderr, "gh-threads: "+format+"\n", args...) os.Exit(1) } // Keep interface drift visible at compile time. var _ GitHubService = (*GitHubClient)(nil)