term.go
1package main
2
3import (
4 "fmt"
5
6 "github.com/git-bug/git-bug/cache"
7 "github.com/git-bug/git-bug/repository"
8 "github.com/git-bug/git-bug/termui"
9 "github.com/spf13/cobra"
10)
11
12// runTerm launches the git-bug terminal UI
13// It first invalidates the cache to ensure git-bug rebuilds it,
14// then opens the repository, creates a cache, and runs the termui.
15func runTerm(repoPath string) error {
16 // Invalidate cache so git-bug is forced to rebuild it
17 invalidateGitBugCache(repoPath)
18
19 // Open the repository
20 repo, err := repository.OpenGoGitRepo(repoPath, "", nil)
21 if err != nil {
22 return fmt.Errorf("failed to open repository: %w", err)
23 }
24 defer repo.Close()
25
26 // Create the cache (will rebuild since we invalidated)
27 // Using NewRepoCacheNoEvents to simplify - it waits for all build events
28 cacheInstance, err := cache.NewRepoCacheNoEvents(repo)
29 if err != nil {
30 return fmt.Errorf("failed to create cache: %w", err)
31 }
32 defer cacheInstance.Close()
33
34 // Run the terminal UI
35 if err := termui.Run(cacheInstance); err != nil {
36 return fmt.Errorf("termui error: %w", err)
37 }
38
39 return nil
40}
41
42var termCmd = &cobra.Command{
43 Use: "term",
44 Aliases: []string{"termui", "ui"},
45 Short: "Launch the terminal UI to browse and edit bugs",
46 Long: `Launch the git-bug terminal UI to browse and edit bugs interactively.
47
48This command starts the full-featured terminal interface for managing git-bug
49issues. It provides a two-pane view with a bug list and detailed bug view,
50allowing you to browse, create, edit, and comment on bugs.
51
52Before starting the UI, the cache is invalidated to ensure git-bug rebuilds
53it with the latest data. This keeps the 'bug' command and 'git-bug' binary
54in sync.
55
56Examples:
57 bug term # Launch terminal UI in current directory
58 bug termui # Same as above (alias)
59 bug ui # Same as above (alias)
60 bug term --repo /path/to/repo # Launch UI for specific repository`,
61 RunE: func(cmd *cobra.Command, args []string) error {
62 return runTerm(repoPath)
63 },
64}