feat(cli): improve purge command flag clarity
Rename flags for better understanding: - Split generic --cache into --history-cache and --browser-cache - Rename --webkit-data to --browser-data for clarity - Add short flags: -H (history-cache), -c (browser-cache), -b (browser-data) - Update documentation and examples to reflect new flag names - Clarify distinction between dmenu fuzzy cache vs WebKit browser cache
- commit
- 6b72132048a5442edb6028e83e1bf6d0e1d49031
- author
- Brice · · 2025-09-10 20:25 UTC
- parent
- d213e3c
- signature
- unsigned
3 files · +49 -42
M CHANGELOG.md +3 -1
| @@ -17,7 +17,9 @@ All notable changes to this project will be documented in this file. | |||
| 17 | 17 | - Atomic operations for concurrent access control | |
| 18 | 18 | - Dependency injection using interfaces and gomock for testing | |
| 19 | 19 | - Purge command for cleaning up dumber data and cache files: | |
| 20 | - | - Selective purging with flags: `--database`, `--cache`, `--webkit-data`, `--state`, `--config` | |
| 20 | + | - Selective purging with flags: `--database`, `--history-cache`, `--browser-cache`, `--browser-data`, `--state`, `--config` | |
| 21 | + | - Clear distinction between history cache (dmenu fuzzy search) and browser cache (WebKit) | |
| 22 | + | - Browser data includes cookies, localStorage, sessionStorage | |
| 21 | 23 | - Confirmation prompt with `--force` flag to skip | |
| 22 | 24 | - Targets all data locations: SQLite database, WebKit cache/data, dmenu fuzzy cache, configuration files | |
| 23 | 25 | ||
| @@ -17,7 +17,9 @@ All notable changes to this project will be documented in this file. | |||||
| 17 | - Atomic operations for concurrent access control | 17 | - Atomic operations for concurrent access control | ||
| 18 | - Dependency injection using interfaces and gomock for testing | 18 | - Dependency injection using interfaces and gomock for testing | ||
| 19 | - Purge command for cleaning up dumber data and cache files: | 19 | - Purge command for cleaning up dumber data and cache files: | ||
| 20 | - | - Selective purging with flags: `--database`, `--cache`, `--webkit-data`, `--state`, `--config` | 20 | + | - Selective purging with flags: `--database`, `--history-cache`, `--browser-cache`, `--browser-data`, `--state`, `--config` |
| 21 | + | - Clear distinction between history cache (dmenu fuzzy search) and browser cache (WebKit) | |||
| 22 | + | - Browser data includes cookies, localStorage, sessionStorage | |||
| 21 | - Confirmation prompt with `--force` flag to skip | 23 | - Confirmation prompt with `--force` flag to skip | ||
| 22 | - Targets all data locations: SQLite database, WebKit cache/data, dmenu fuzzy cache, configuration files | 24 | - Targets all data locations: SQLite database, WebKit cache/data, dmenu fuzzy cache, configuration files | ||
| 23 | 25 | ||||
M README.md +4 -4
| @@ -104,10 +104,10 @@ Development: | |||
| 104 | 104 | - rofi: `dumber dmenu | rofi -dmenu -p "Browse: " | dumber dmenu --select` | |
| 105 | 105 | - fuzzel: `dumber dmenu | fuzzel --dmenu -p "Browse: " | dumber dmenu --select` | |
| 106 | 106 | - Clean up data and cache: | |
| 107 | - | - `dumber purge` # purge all data (with confirmation) | |
| 108 | - | - `dumber purge --force` # purge all data (no confirmation) | |
| 109 | - | - `dumber purge --database --cache` # purge only database and caches | |
| 110 | - | - `dumber purge --webkit-data` # purge only WebKit data (cookies, etc.) | |
| 107 | + | - `dumber purge` # purge all data (with confirmation) | |
| 108 | + | - `dumber purge --force` # purge all data (no confirmation) | |
| 109 | + | - `dumber purge -d -H -c` # purge database and both caches | |
| 110 | + | - `dumber purge --browser-data` # purge WebKit data (cookies, etc.) | |
| 111 | 111 | ||
| 112 | 112 | ### Dmenu mode invocation | |
| 113 | 113 | You can invoke dmenu mode in two ways: | |
| @@ -104,10 +104,10 @@ Development: | |||||
| 104 | - rofi: `dumber dmenu | rofi -dmenu -p "Browse: " | dumber dmenu --select` | 104 | - rofi: `dumber dmenu | rofi -dmenu -p "Browse: " | dumber dmenu --select` | ||
| 105 | - fuzzel: `dumber dmenu | fuzzel --dmenu -p "Browse: " | dumber dmenu --select` | 105 | - fuzzel: `dumber dmenu | fuzzel --dmenu -p "Browse: " | dumber dmenu --select` | ||
| 106 | - Clean up data and cache: | 106 | - Clean up data and cache: | ||
| 107 | - | - `dumber purge` # purge all data (with confirmation) | 107 | + | - `dumber purge` # purge all data (with confirmation) |
| 108 | - | - `dumber purge --force` # purge all data (no confirmation) | 108 | + | - `dumber purge --force` # purge all data (no confirmation) |
| 109 | - | - `dumber purge --database --cache` # purge only database and caches | 109 | + | - `dumber purge -d -H -c` # purge database and both caches |
| 110 | - | - `dumber purge --webkit-data` # purge only WebKit data (cookies, etc.) | 110 | + | - `dumber purge --browser-data` # purge WebKit data (cookies, etc.) |
| 111 | 111 | ||||
| 112 | ### Dmenu mode invocation | 112 | ### Dmenu mode invocation | ||
| 113 | You can invoke dmenu mode in two ways: | 113 | You can invoke dmenu mode in two ways: | ||
M internal/cli/purge.go +42 -37
| @@ -13,13 +13,14 @@ import ( | |||
| 13 | 13 | ||
| 14 | 14 | // PurgeFlags holds all the purge command flags | |
| 15 | 15 | type PurgeFlags struct { | |
| 16 | - | Database bool | |
| 17 | - | Cache bool | |
| 18 | - | State bool | |
| 19 | - | WebkitData bool | |
| 20 | - | Config bool | |
| 21 | - | All bool | |
| 22 | - | Force bool | |
| 16 | + | Database bool | |
| 17 | + | HistoryCache bool | |
| 18 | + | BrowserCache bool | |
| 19 | + | BrowserData bool | |
| 20 | + | State bool | |
| 21 | + | Config bool | |
| 22 | + | All bool | |
| 23 | + | Force bool | |
| 23 | 24 | } | |
| 24 | 25 | ||
| 25 | 26 | // NewPurgeCmd creates the purge command | |
| @@ -32,20 +33,21 @@ func NewPurgeCmd() *cobra.Command { | |||
| 32 | 33 | Long: `Purge various dumber data and cache files. By default, purges everything. | |
| 33 | 34 | ||
| 34 | 35 | Available purge targets: | |
| 35 | - | --database, -d Purge the SQLite database (history, shortcuts, zoom levels) | |
| 36 | - | --cache, -c Purge WebKit cache and dmenu fuzzy search cache | |
| 37 | - | --state, -s Purge all state data (includes database and caches) | |
| 38 | - | --webkit-data, -w Purge WebKit data (cookies, local storage, session data) | |
| 39 | - | --config Purge configuration files | |
| 40 | - | --all, -a Purge everything (default if no specific flags are provided) | |
| 36 | + | --database, -d Purge the SQLite database (history, shortcuts, zoom levels) | |
| 37 | + | --history-cache, -H Purge dmenu fuzzy search cache for history | |
| 38 | + | --browser-cache, -c Purge WebKit browser cache (cached images, files, etc.) | |
| 39 | + | --browser-data, -b Purge WebKit browser data (cookies, localStorage, sessionStorage) | |
| 40 | + | --state, -s Purge all state data (includes database and caches) | |
| 41 | + | --config Purge configuration files | |
| 42 | + | --all, -a Purge everything (default if no specific flags are provided) | |
| 41 | 43 | ||
| 42 | 44 | Use --force to skip the confirmation prompt. | |
| 43 | 45 | ||
| 44 | 46 | Examples: | |
| 45 | 47 | dumber purge # Purge everything (with confirmation) | |
| 46 | 48 | dumber purge --force # Purge everything (no confirmation) | |
| 47 | - | dumber purge -d -c # Purge only database and caches | |
| 48 | - | dumber purge --webkit-data -f # Force purge WebKit data only`, | |
| 49 | + | dumber purge -d -H -c # Purge database and both caches | |
| 50 | + | dumber purge --browser-data -f # Force purge browser data only`, | |
| 49 | 51 | RunE: func(_ *cobra.Command, _ []string) error { | |
| 50 | 52 | // Initialize CLI to get config paths | |
| 51 | 53 | cli, err := NewCLI() | |
| @@ -64,9 +66,10 @@ Examples: | |||
| 64 | 66 | ||
| 65 | 67 | // Add flags | |
| 66 | 68 | cmd.Flags().BoolVarP(&flags.Database, "database", "d", false, "Purge the SQLite database") | |
| 67 | - | cmd.Flags().BoolVarP(&flags.Cache, "cache", "c", false, "Purge WebKit cache and dmenu fuzzy cache") | |
| 69 | + | cmd.Flags().BoolVarP(&flags.HistoryCache, "history-cache", "H", false, "Purge dmenu fuzzy search cache") | |
| 70 | + | cmd.Flags().BoolVarP(&flags.BrowserCache, "browser-cache", "c", false, "Purge WebKit browser cache") | |
| 71 | + | cmd.Flags().BoolVarP(&flags.BrowserData, "browser-data", "b", false, "Purge WebKit browser data (cookies, localStorage)") | |
| 68 | 72 | cmd.Flags().BoolVarP(&flags.State, "state", "s", false, "Purge all state data") | |
| 69 | - | cmd.Flags().BoolVarP(&flags.WebkitData, "webkit-data", "w", false, "Purge WebKit data (cookies, local storage)") | |
| 70 | 73 | cmd.Flags().BoolVar(&flags.Config, "config", false, "Purge configuration files") | |
| 71 | 74 | cmd.Flags().BoolVarP(&flags.All, "all", "a", false, "Purge everything") | |
| 72 | 75 | cmd.Flags().BoolVarP(&flags.Force, "force", "f", false, "Skip confirmation prompt") | |
| @@ -106,23 +109,26 @@ func determinePurgeItems(flags PurgeFlags) []string { | |||
| 106 | 109 | var items []string | |
| 107 | 110 | ||
| 108 | 111 | // If no specific flags are set, or --all is set, purge everything | |
| 109 | - | if flags.All || (!flags.Database && !flags.Cache && !flags.State && !flags.WebkitData && !flags.Config) { | |
| 110 | - | return []string{"database", "cache", "webkit-data", "config"} | |
| 112 | + | if flags.All || (!flags.Database && !flags.HistoryCache && !flags.BrowserCache && !flags.BrowserData && !flags.State && !flags.Config) { | |
| 113 | + | return []string{"database", "history-cache", "browser-cache", "browser-data", "config"} | |
| 111 | 114 | } | |
| 112 | 115 | ||
| 113 | 116 | // Add items based on flags | |
| 114 | 117 | if flags.Database { | |
| 115 | 118 | items = append(items, "database") | |
| 116 | 119 | } | |
| 117 | - | if flags.Cache { | |
| 118 | - | items = append(items, "cache") | |
| 120 | + | if flags.HistoryCache { | |
| 121 | + | items = append(items, "history-cache") | |
| 119 | 122 | } | |
| 120 | - | if flags.State { | |
| 121 | - | // State includes database and caches | |
| 122 | - | items = append(items, "database", "cache") | |
| 123 | + | if flags.BrowserCache { | |
| 124 | + | items = append(items, "browser-cache") | |
| 125 | + | } | |
| 126 | + | if flags.BrowserData { | |
| 127 | + | items = append(items, "browser-data") | |
| 123 | 128 | } | |
| 124 | - | if flags.WebkitData { | |
| 125 | - | items = append(items, "webkit-data") | |
| 129 | + | if flags.State { | |
| 130 | + | // State includes database and both caches | |
| 131 | + | items = append(items, "database", "history-cache", "browser-cache") | |
| 126 | 132 | } | |
| 127 | 133 | if flags.Config { | |
| 128 | 134 | items = append(items, "config") | |
| @@ -154,24 +160,23 @@ func getPurgePaths(items []string) (map[string][]string, error) { | |||
| 154 | 160 | } | |
| 155 | 161 | paths[item] = []string{dbPath} | |
| 156 | 162 | ||
| 157 | - | case "cache": | |
| 158 | - | var cachePaths []string | |
| 159 | - | ||
| 160 | - | // WebKit cache | |
| 163 | + | case "history-cache": | |
| 161 | 164 | stateDir, err := config.GetStateDir() | |
| 162 | 165 | if err != nil { | |
| 163 | 166 | return nil, fmt.Errorf("failed to get state directory: %w", err) | |
| 164 | 167 | } | |
| 165 | - | webkitCache := filepath.Join(stateDir, "webkit-cache") | |
| 166 | - | cachePaths = append(cachePaths, webkitCache) | |
| 167 | - | ||
| 168 | - | // Dmenu fuzzy cache | |
| 169 | 168 | dmenuCache := filepath.Join(stateDir, "dmenu_fuzzy_cache.bin") | |
| 170 | - | cachePaths = append(cachePaths, dmenuCache) | |
| 169 | + | paths[item] = []string{dmenuCache} | |
| 171 | 170 | ||
| 172 | - | paths[item] = cachePaths | |
| 171 | + | case "browser-cache": | |
| 172 | + | stateDir, err := config.GetStateDir() | |
| 173 | + | if err != nil { | |
| 174 | + | return nil, fmt.Errorf("failed to get state directory: %w", err) | |
| 175 | + | } | |
| 176 | + | webkitCache := filepath.Join(stateDir, "webkit-cache") | |
| 177 | + | paths[item] = []string{webkitCache} | |
| 173 | 178 | ||
| 174 | - | case "webkit-data": | |
| 179 | + | case "browser-data": | |
| 175 | 180 | dataDir, err := config.GetDataDir() | |
| 176 | 181 | if err != nil { | |
| 177 | 182 | return nil, fmt.Errorf("failed to get data directory: %w", err) | |
| @@ -13,13 +13,14 @@ import ( | |||||
| 13 | 13 | ||||
| 14 | // PurgeFlags holds all the purge command flags | 14 | // PurgeFlags holds all the purge command flags | ||
| 15 | type PurgeFlags struct { | 15 | type PurgeFlags struct { | ||
| 16 | - | Database bool | 16 | + | Database bool |
| 17 | - | Cache bool | 17 | + | HistoryCache bool |
| 18 | - | State bool | 18 | + | BrowserCache bool |
| 19 | - | WebkitData bool | 19 | + | BrowserData bool |
| 20 | - | Config bool | 20 | + | State bool |
| 21 | - | All bool | 21 | + | Config bool |
| 22 | - | Force bool | 22 | + | All bool |
| 23 | + | Force bool | |||
| 23 | } | 24 | } | ||
| 24 | 25 | ||||
| 25 | // NewPurgeCmd creates the purge command | 26 | // NewPurgeCmd creates the purge command | ||
| @@ -32,20 +33,21 @@ func NewPurgeCmd() *cobra.Command { | |||||
| 32 | Long: `Purge various dumber data and cache files. By default, purges everything. | 33 | Long: `Purge various dumber data and cache files. By default, purges everything. | ||
| 33 | 34 | ||||
| 34 | Available purge targets: | 35 | Available purge targets: | ||
| 35 | - | --database, -d Purge the SQLite database (history, shortcuts, zoom levels) | 36 | + | --database, -d Purge the SQLite database (history, shortcuts, zoom levels) |
| 36 | - | --cache, -c Purge WebKit cache and dmenu fuzzy search cache | 37 | + | --history-cache, -H Purge dmenu fuzzy search cache for history |
| 37 | - | --state, -s Purge all state data (includes database and caches) | 38 | + | --browser-cache, -c Purge WebKit browser cache (cached images, files, etc.) |
| 38 | - | --webkit-data, -w Purge WebKit data (cookies, local storage, session data) | 39 | + | --browser-data, -b Purge WebKit browser data (cookies, localStorage, sessionStorage) |
| 39 | - | --config Purge configuration files | 40 | + | --state, -s Purge all state data (includes database and caches) |
| 40 | - | --all, -a Purge everything (default if no specific flags are provided) | 41 | + | --config Purge configuration files |
| 42 | + | --all, -a Purge everything (default if no specific flags are provided) | |||
| 41 | 43 | ||||
| 42 | Use --force to skip the confirmation prompt. | 44 | Use --force to skip the confirmation prompt. | ||
| 43 | 45 | ||||
| 44 | Examples: | 46 | Examples: | ||
| 45 | dumber purge # Purge everything (with confirmation) | 47 | dumber purge # Purge everything (with confirmation) | ||
| 46 | dumber purge --force # Purge everything (no confirmation) | 48 | dumber purge --force # Purge everything (no confirmation) | ||
| 47 | - | dumber purge -d -c # Purge only database and caches | 49 | + | dumber purge -d -H -c # Purge database and both caches |
| 48 | - | dumber purge --webkit-data -f # Force purge WebKit data only`, | 50 | + | dumber purge --browser-data -f # Force purge browser data only`, |
| 49 | RunE: func(_ *cobra.Command, _ []string) error { | 51 | RunE: func(_ *cobra.Command, _ []string) error { | ||
| 50 | // Initialize CLI to get config paths | 52 | // Initialize CLI to get config paths | ||
| 51 | cli, err := NewCLI() | 53 | cli, err := NewCLI() | ||
| @@ -64,9 +66,10 @@ Examples: | |||||
| 64 | 66 | ||||
| 65 | // Add flags | 67 | // Add flags | ||
| 66 | cmd.Flags().BoolVarP(&flags.Database, "database", "d", false, "Purge the SQLite database") | 68 | cmd.Flags().BoolVarP(&flags.Database, "database", "d", false, "Purge the SQLite database") | ||
| 67 | - | cmd.Flags().BoolVarP(&flags.Cache, "cache", "c", false, "Purge WebKit cache and dmenu fuzzy cache") | 69 | + | cmd.Flags().BoolVarP(&flags.HistoryCache, "history-cache", "H", false, "Purge dmenu fuzzy search cache") |
| 70 | + | cmd.Flags().BoolVarP(&flags.BrowserCache, "browser-cache", "c", false, "Purge WebKit browser cache") | |||
| 71 | + | cmd.Flags().BoolVarP(&flags.BrowserData, "browser-data", "b", false, "Purge WebKit browser data (cookies, localStorage)") | |||
| 68 | cmd.Flags().BoolVarP(&flags.State, "state", "s", false, "Purge all state data") | 72 | cmd.Flags().BoolVarP(&flags.State, "state", "s", false, "Purge all state data") | ||
| 69 | - | cmd.Flags().BoolVarP(&flags.WebkitData, "webkit-data", "w", false, "Purge WebKit data (cookies, local storage)") | |||
| 70 | cmd.Flags().BoolVar(&flags.Config, "config", false, "Purge configuration files") | 73 | cmd.Flags().BoolVar(&flags.Config, "config", false, "Purge configuration files") | ||
| 71 | cmd.Flags().BoolVarP(&flags.All, "all", "a", false, "Purge everything") | 74 | cmd.Flags().BoolVarP(&flags.All, "all", "a", false, "Purge everything") | ||
| 72 | cmd.Flags().BoolVarP(&flags.Force, "force", "f", false, "Skip confirmation prompt") | 75 | cmd.Flags().BoolVarP(&flags.Force, "force", "f", false, "Skip confirmation prompt") | ||
| @@ -106,23 +109,26 @@ func determinePurgeItems(flags PurgeFlags) []string { | |||||
| 106 | var items []string | 109 | var items []string | ||
| 107 | 110 | ||||
| 108 | // If no specific flags are set, or --all is set, purge everything | 111 | // If no specific flags are set, or --all is set, purge everything | ||
| 109 | - | if flags.All || (!flags.Database && !flags.Cache && !flags.State && !flags.WebkitData && !flags.Config) { | 112 | + | if flags.All || (!flags.Database && !flags.HistoryCache && !flags.BrowserCache && !flags.BrowserData && !flags.State && !flags.Config) { |
| 110 | - | return []string{"database", "cache", "webkit-data", "config"} | 113 | + | return []string{"database", "history-cache", "browser-cache", "browser-data", "config"} |
| 111 | } | 114 | } | ||
| 112 | 115 | ||||
| 113 | // Add items based on flags | 116 | // Add items based on flags | ||
| 114 | if flags.Database { | 117 | if flags.Database { | ||
| 115 | items = append(items, "database") | 118 | items = append(items, "database") | ||
| 116 | } | 119 | } | ||
| 117 | - | if flags.Cache { | 120 | + | if flags.HistoryCache { |
| 118 | - | items = append(items, "cache") | 121 | + | items = append(items, "history-cache") |
| 119 | } | 122 | } | ||
| 120 | - | if flags.State { | 123 | + | if flags.BrowserCache { |
| 121 | - | // State includes database and caches | 124 | + | items = append(items, "browser-cache") |
| 122 | - | items = append(items, "database", "cache") | 125 | + | } |
| 126 | + | if flags.BrowserData { | |||
| 127 | + | items = append(items, "browser-data") | |||
| 123 | } | 128 | } | ||
| 124 | - | if flags.WebkitData { | 129 | + | if flags.State { |
| 125 | - | items = append(items, "webkit-data") | 130 | + | // State includes database and both caches |
| 131 | + | items = append(items, "database", "history-cache", "browser-cache") | |||
| 126 | } | 132 | } | ||
| 127 | if flags.Config { | 133 | if flags.Config { | ||
| 128 | items = append(items, "config") | 134 | items = append(items, "config") | ||
| @@ -154,24 +160,23 @@ func getPurgePaths(items []string) (map[string][]string, error) { | |||||
| 154 | } | 160 | } | ||
| 155 | paths[item] = []string{dbPath} | 161 | paths[item] = []string{dbPath} | ||
| 156 | 162 | ||||
| 157 | - | case "cache": | 163 | + | case "history-cache": |
| 158 | - | var cachePaths []string | |||
| 159 | - | ||||
| 160 | - | // WebKit cache | |||
| 161 | stateDir, err := config.GetStateDir() | 164 | stateDir, err := config.GetStateDir() | ||
| 162 | if err != nil { | 165 | if err != nil { | ||
| 163 | return nil, fmt.Errorf("failed to get state directory: %w", err) | 166 | return nil, fmt.Errorf("failed to get state directory: %w", err) | ||
| 164 | } | 167 | } | ||
| 165 | - | webkitCache := filepath.Join(stateDir, "webkit-cache") | |||
| 166 | - | cachePaths = append(cachePaths, webkitCache) | |||
| 167 | - | ||||
| 168 | - | // Dmenu fuzzy cache | |||
| 169 | dmenuCache := filepath.Join(stateDir, "dmenu_fuzzy_cache.bin") | 168 | dmenuCache := filepath.Join(stateDir, "dmenu_fuzzy_cache.bin") | ||
| 170 | - | cachePaths = append(cachePaths, dmenuCache) | 169 | + | paths[item] = []string{dmenuCache} |
| 171 | 170 | ||||
| 172 | - | paths[item] = cachePaths | 171 | + | case "browser-cache": |
| 172 | + | stateDir, err := config.GetStateDir() | |||
| 173 | + | if err != nil { | |||
| 174 | + | return nil, fmt.Errorf("failed to get state directory: %w", err) | |||
| 175 | + | } | |||
| 176 | + | webkitCache := filepath.Join(stateDir, "webkit-cache") | |||
| 177 | + | paths[item] = []string{webkitCache} | |||
| 173 | 178 | ||||
| 174 | - | case "webkit-data": | 179 | + | case "browser-data": |
| 175 | dataDir, err := config.GetDataDir() | 180 | dataDir, err := config.GetDataDir() | ||
| 176 | if err != nil { | 181 | if err != nil { | ||
| 177 | return nil, fmt.Errorf("failed to get data directory: %w", err) | 182 | return nil, fmt.Errorf("failed to get data directory: %w", err) | ||