|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "flag" |
| 6 | + "fmt" |
| 7 | + "os" |
| 8 | + |
| 9 | + tea "github.com/charmbracelet/bubbletea" |
| 10 | + "github.com/valerius21/repokill/internal/filter" |
| 11 | + "github.com/valerius21/repokill/internal/github" |
| 12 | + "github.com/valerius21/repokill/internal/tui" |
| 13 | +) |
| 14 | + |
| 15 | +// Version is set at build time via ldflags. |
| 16 | +var Version = "dev" |
| 17 | + |
| 18 | +func main() { |
| 19 | + org := flag.String("org", "", "List repos for an organization") |
| 20 | + public := flag.Bool("public", false, "Show only public repos") |
| 21 | + private := flag.Bool("private", false, "Show only private repos") |
| 22 | + archived := flag.Bool("archived", false, "Show only archived repos") |
| 23 | + forked := flag.Bool("forked", false, "Show only forks") |
| 24 | + version := flag.Bool("version", false, "Show version") |
| 25 | + flag.Parse() |
| 26 | + |
| 27 | + if *version { |
| 28 | + fmt.Printf("repokill %s\n", Version) |
| 29 | + os.Exit(0) |
| 30 | + } |
| 31 | + |
| 32 | + // Build filter options |
| 33 | + var filterOpts filter.FilterOptions |
| 34 | + if *public { |
| 35 | + filterOpts.Visibility = "public" |
| 36 | + } else if *private { |
| 37 | + filterOpts.Visibility = "private" |
| 38 | + } |
| 39 | + if *archived { |
| 40 | + trueVal := true |
| 41 | + filterOpts.Archived = &trueVal |
| 42 | + } |
| 43 | + if *forked { |
| 44 | + trueVal := true |
| 45 | + filterOpts.Forked = &trueVal |
| 46 | + } |
| 47 | + |
| 48 | + // Default sort: by pushedAt ascending (oldest first) |
| 49 | + sortOpts := filter.SortOptions{ |
| 50 | + Field: filter.SortByPushedAt, |
| 51 | + Order: filter.Ascending, |
| 52 | + } |
| 53 | + |
| 54 | + // Create GitHub client |
| 55 | + client := github.NewClient(*org, nil) |
| 56 | + |
| 57 | + // Check authentication |
| 58 | + if err := client.CheckAuth(context.Background()); err != nil { |
| 59 | + fmt.Fprintf(os.Stderr, "Error: %v\n", err) |
| 60 | + os.Exit(1) |
| 61 | + } |
| 62 | + |
| 63 | + // Run TUI |
| 64 | + model := tui.New(client, filterOpts, sortOpts) |
| 65 | + p := tea.NewProgram(model, tea.WithAltScreen()) |
| 66 | + |
| 67 | + if _, err := p.Run(); err != nil { |
| 68 | + fmt.Fprintf(os.Stderr, "Error running TUI: %v\n", err) |
| 69 | + os.Exit(1) |
| 70 | + } |
| 71 | +} |
0 commit comments