v0.20.0 c741a39

purge.go RawHistoryFolder

1package cmd
2
3import (
4	"fmt"
5
6	tea "github.com/charmbracelet/bubbletea"
7	"github.com/spf13/cobra"
8
9	"github.com/bnema/dumber/internal/application/usecase"
10	"github.com/bnema/dumber/internal/cli"
11	"github.com/bnema/dumber/internal/cli/model"
12	"github.com/bnema/dumber/internal/cli/styles"
13	"github.com/bnema/dumber/internal/infrastructure/desktop"
14	"github.com/bnema/dumber/internal/infrastructure/filesystem"
15	xdgadapter "github.com/bnema/dumber/internal/infrastructure/xdg"
16)
17
18var purgeForce bool
19
20var purgeCmd = &cobra.Command{
21	Use:   "purge",
22	Short: "Remove dumber data and configuration",
23	Long: `Interactively select and remove dumber data directories and files.
24
25This can remove:
26  - Config directory
27  - Data directory
28  - State directory
29  - Cache directory
30  - Content filter caches
31  - Desktop integration files
32
33Use --force to remove everything without prompting.`,
34	RunE: runPurge,
35}
36
37func init() {
38	rootCmd.AddCommand(purgeCmd)
39	purgeCmd.Flags().BoolVarP(&purgeForce, "force", "f", false, "remove all items without prompting")
40}
41
42func runPurge(_ *cobra.Command, _ []string) error {
43	app := GetApp()
44	if app == nil {
45		return fmt.Errorf("app not initialized")
46	}
47
48	fsAdapter := filesystem.New()
49	xdgAdapter := xdgadapter.New()
50	desktopAdapter := desktop.New()
51	purgeUC := usecase.NewPurgeDataUseCase(fsAdapter, xdgAdapter, desktopAdapter)
52
53	if purgeForce {
54		return runPurgeForce(app, purgeUC)
55	}
56
57	m := model.NewPurgeModel(app.Theme, purgeUC)
58	p := tea.NewProgram(m, tea.WithAltScreen())
59	_, err := p.Run()
60	return err
61}
62
63func runPurgeForce(app *cli.App, purgeUC *usecase.PurgeDataUseCase) error {
64	out, err := purgeUC.PurgeAll(app.Ctx())
65	if out != nil {
66		for _, r := range out.Results {
67			if r.Success {
68				fmt.Printf("%s %s\n", app.Theme.SuccessStyle.Render(styles.IconCheck), r.Target.Path)
69			} else {
70				fmt.Printf("%s %s: %v\n", app.Theme.ErrorStyle.Render(styles.IconX), r.Target.Path, r.Error)
71			}
72		}
73	}
74	return err
75}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close