Skip to content

Commit b7d0f3c

Browse files
authored
Merge pull request #30 from cybrota/feat/improvement
feat: Add a new flag quiet to reduce verbosity of tool
2 parents 86a1449 + 4683a84 commit b7d0f3c

File tree

6 files changed

+57
-41
lines changed

6 files changed

+57
-41
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ filesystem:
8989
- ".git"
9090
- "node_modules"
9191
- ".DS_Store"
92+
93+
# Reduce the verbosity of app. Default is false.
94+
quiet: true
9295
```
9396
9497
## Usage
@@ -110,7 +113,7 @@ recaller fs index /usr/local ~/code # Index multiple directories recursively
110113
# Launch filesystem search UI
111114
recaller fs # Launch search UI (auto re-indexes tracked paths)
112115

113-
# Manage filesystem index
116+
# Manage filesystem index
114117
recaller fs clean --stale # Remove entries for deleted files
115118
recaller fs clean --older-than 30 # Remove entries older than 30 days
116119
recaller fs clean --clear # Clear entire index
@@ -140,4 +143,4 @@ cd recaller && go mod tidy && go run .
140143

141144
Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details.
142145

143-
Copyright © 2025 [Naren Yellavula](https://github.com/narenaryan)
146+
Copyright © 2025 [Naren Yellavula](https://github.com/narenaryan)

app.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func run(tree *AVLTree, hc *cache.Cache) {
259259
inputPara.Title = " Type Command "
260260
inputPara.Text = ""
261261
inputPara.TextStyle.Bg = ui.ColorBlue
262-
inputPara.TextStyle.Fg = ui.ColorBlack
262+
inputPara.TextStyle.Fg = ui.ColorWhite
263263
inputPara.BorderStyle = ui.NewStyle(ui.ColorYellow)
264264

265265
// List to show matching results
@@ -643,7 +643,7 @@ func runFilesystemSearch(fsIndexer *FilesystemIndexer, config *Config) {
643643
inputPara.Title = " Search Files & Directories "
644644
inputPara.Text = ""
645645
inputPara.TextStyle.Bg = ui.ColorBlue
646-
inputPara.TextStyle.Fg = ui.ColorBlack
646+
inputPara.TextStyle.Fg = ui.ColorWhite
647647
inputPara.BorderStyle = ui.NewStyle(ui.ColorYellow)
648648

649649
// List to show matching files
@@ -659,7 +659,7 @@ func runFilesystemSearch(fsIndexer *FilesystemIndexer, config *Config) {
659659
metadataList.Title = " 📋 File Info "
660660
metadataList.Rows = []string{"Select a file to view details"}
661661
metadataList.SelectedRow = 0
662-
metadataList.SelectedRowStyle = ui.NewStyle(ui.ColorBlack, ui.ColorYellow)
662+
metadataList.SelectedRowStyle = ui.NewStyle(ui.ColorWhite, ui.ColorYellow)
663663
metadataList.WrapText = true
664664

665665
// Layout setup
@@ -882,7 +882,7 @@ func runFilesystemSearch(fsIndexer *FilesystemIndexer, config *Config) {
882882

883883
// Persist updated index
884884
go func() {
885-
if err := fsIndexer.PersistIndex(); err != nil {
885+
if err := fsIndexer.PersistIndex(!config.Quiet); err != nil {
886886
log.Printf("Failed to persist index: %v", err)
887887
}
888888
}()

config.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type FilesystemConfig struct {
4242
type Config struct {
4343
History HistoryConfig `yaml:"history"`
4444
Filesystem FilesystemConfig `yaml:"filesystem"`
45+
Quiet bool `yaml:"quiet"`
4546
}
4647

4748
var defaultConfig = Config{
@@ -154,10 +155,17 @@ func displaySettings() {
154155
fmt.Printf("📍 Config file: %s (newly created)\n", configPath)
155156
}
156157

157-
fmt.Printf("📊 Current settings:\n\n")
158+
fmt.Printf("Current settings:\n\n")
158159

159-
fmt.Printf("🔍 %sHistory Search:%s\n", Green, Reset)
160+
fmt.Printf("🔘 %sVerbosity:%s\n", Green, Reset)
161+
162+
quietValue := "true"
163+
if !config.Quiet {
164+
quietValue = "false"
165+
}
166+
fmt.Printf(" • %squiet%s: %s\n\n", Green, Reset, quietValue)
160167

168+
fmt.Printf("🔍 %sHistory Search:%s\n", Green, Reset)
161169
fuzzyValue := "true"
162170
fuzzyDesc := "Fuzzy search (substring matching anywhere)"
163171
if !config.History.EnableFuzzing {

fs_indexer.go

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (fi *FilesystemIndexer) IndexDirectoryWithProgress(rootPath string, showPro
265265
BarEnd: "]",
266266
}),
267267
progressbar.OptionOnCompletion(func() {
268-
fmt.Printf("\n Indexing completed!\n")
268+
fmt.Printf("\n✔️ Indexing completed!\n")
269269
}),
270270
)
271271
}
@@ -350,7 +350,10 @@ func (fi *FilesystemIndexer) IndexDirectoriesWithProgress(rootPaths []string, sh
350350
// Track this root path if not already tracked
351351
fi.addRootPath(rootPath)
352352

353-
log.Printf("Starting filesystem indexing for directory %d/%d: %s", i+1, len(rootPaths), rootPath)
353+
if showProgress {
354+
log.Printf("Starting filesystem indexing for directory %d/%d: %s", i+1, len(rootPaths), rootPath)
355+
}
356+
354357
count := 0
355358

356359
err := filepath.WalkDir(rootPath, func(path string, d fs.DirEntry, err error) error {
@@ -407,15 +410,17 @@ func (fi *FilesystemIndexer) IndexDirectoriesWithProgress(rootPaths []string, sh
407410
}
408411
}
409412

410-
log.Printf("Completed indexing directory %s: %d files/directories", rootPath, count)
413+
if showProgress {
414+
log.Printf("Completed indexing directory %s: %d files/directories", rootPath, count)
415+
}
411416
}
412417

413418
if showProgress && overallBar != nil {
414-
overallBar.Describe(" Indexing completed")
419+
overallBar.Describe("✔️ Indexing completed")
415420
overallBar.Finish()
416-
}
417421

418-
log.Printf("Multi-directory indexing completed. Total indexed: %d files/directories across %d directories", totalCount, len(rootPaths))
422+
log.Printf("Multi-directory indexing completed. Total indexed: %d files/directories across %d directories", totalCount, len(rootPaths))
423+
}
419424
return nil
420425
}
421426

@@ -471,7 +476,9 @@ func (fi *FilesystemIndexer) ReindexExistingPaths(showProgress bool) error {
471476
return nil
472477
}
473478

474-
log.Printf("Re-indexing %d tracked root paths to discover new files", len(fi.rootPaths))
479+
if showProgress {
480+
log.Printf("Re-indexing %d tracked root paths to discover new files", len(fi.rootPaths))
481+
}
475482

476483
// Filter out root paths that no longer exist
477484
var validRootPaths []string
@@ -502,9 +509,7 @@ func (fi *FilesystemIndexer) RefreshIndex(showProgress bool, showStats bool) err
502509
return fmt.Errorf("no tracked paths found in index")
503510
}
504511

505-
if showStats {
506-
fmt.Printf("📊 Current index: %s\n", fi.GetIndexStats())
507-
}
512+
fmt.Printf("📊 Current index: %s\n", fi.GetIndexStats())
508513

509514
if showProgress {
510515
fmt.Printf("🔄 Re-indexing %d tracked paths to discover new files...\n", len(rootPaths))
@@ -521,17 +526,13 @@ func (fi *FilesystemIndexer) RefreshIndex(showProgress bool, showStats bool) err
521526
fmt.Printf("\n💾 Saving updated index to disk...")
522527
}
523528

524-
if persistErr := fi.PersistIndex(); persistErr != nil {
529+
if persistErr := fi.PersistIndex(showProgress); persistErr != nil {
525530
if showProgress {
526531
fmt.Printf(" ❌\n")
527532
}
528533
return fmt.Errorf("failed to persist updated index: %v", persistErr)
529534
}
530535

531-
if showProgress {
532-
fmt.Printf(" ✅\n")
533-
}
534-
535536
if showStats {
536537
fmt.Printf("\n📊 Updated index: %s\n", fi.GetIndexStats())
537538
}
@@ -807,25 +808,30 @@ func (fi *FilesystemIndexer) GetIndexPath() string {
807808
return filepath.Join(homeDir, ".recaller_fs_index.bin")
808809
}
809810

810-
func (fi *FilesystemIndexer) LoadOrCreateIndex() error {
811+
func (fi *FilesystemIndexer) LoadOrCreateIndex(showProgress bool) error {
811812
indexPath := fi.GetIndexPath()
812813

813814
if _, err := os.Stat(indexPath); os.IsNotExist(err) {
814815
log.Printf("No existing filesystem index found, will create new one")
815816
return nil
816817
}
817818

818-
log.Printf("Loading existing filesystem index from: %s", indexPath)
819+
if showProgress {
820+
log.Printf("Loading existing filesystem index from: %s", indexPath)
821+
}
819822
return fi.LoadFromFile(indexPath)
820823
}
821824

822-
func (fi *FilesystemIndexer) PersistIndex() error {
825+
func (fi *FilesystemIndexer) PersistIndex(showProgress bool) error {
823826
if !fi.isDirty {
824827
return nil
825828
}
826829

827830
indexPath := fi.GetIndexPath()
828-
log.Printf("Persisting filesystem index to: %s", indexPath)
831+
832+
if showProgress {
833+
log.Printf("Persisting filesystem index to: %s", indexPath)
834+
}
829835
return fi.SaveToFile(indexPath)
830836
}
831837

@@ -834,12 +840,11 @@ func (fi *FilesystemIndexer) GetIndexStats() string {
834840
sketchSize := CountMinDepth * CountMinWidth * 4 // int32 = 4 bytes
835841
bloomSize := int(fi.bloomFilter.Cap() / 8) // Approximate bloom filter size in bytes
836842

837-
return fmt.Sprintf("Index Stats: %d files, Memory: %.2fKB (Records: %.2fKB, Sketch: %.2fKB, Bloom: %.2fKB)",
843+
return fmt.Sprintf("Index Stats: %d files, Memory: %.2fKB (Records: %.2fKB, Metadata: %.2fKB)",
838844
len(fi.pathRecords),
839845
float64(indexSize+sketchSize+bloomSize)/1024,
840846
float64(indexSize)/1024,
841-
float64(sketchSize)/1024,
842-
float64(bloomSize)/1024)
847+
(float64(sketchSize)/1024)+(float64(bloomSize)/1024))
843848
}
844849

845850
// CleanupOptions defines options for index cleanup

main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Copyright @ Naren Yellavula (Please give us a star ⭐ here: https://github.com/
117117
fsIndexer := NewFilesystemIndexer(config.Filesystem)
118118

119119
// Load existing index
120-
if err := fsIndexer.LoadOrCreateIndex(); err != nil {
120+
if err := fsIndexer.LoadOrCreateIndex(!config.Quiet); err != nil {
121121
fmt.Printf("❌ Failed to load filesystem index: %v\n", err)
122122
fmt.Printf("💡 Run 'recaller fs index [path]' to create an index first.\n")
123123
return
@@ -132,7 +132,7 @@ Copyright @ Naren Yellavula (Please give us a star ⭐ here: https://github.com/
132132

133133
// Auto re-index existing paths to discover new files
134134
if len(fsIndexer.GetRootPaths()) > 0 {
135-
if err := fsIndexer.RefreshIndex(true, false); err != nil {
135+
if err := fsIndexer.RefreshIndex(!config.Quiet, false); err != nil {
136136
log.Printf("Warning: Re-indexing completed with errors: %v", err)
137137
}
138138
}
@@ -209,7 +209,7 @@ Copyright @ Naren Yellavula (Please give us a star ⭐ here: https://github.com/
209209
fsIndexer := NewFilesystemIndexer(config.Filesystem)
210210

211211
// Load existing index if available
212-
if err := fsIndexer.LoadOrCreateIndex(); err != nil {
212+
if err := fsIndexer.LoadOrCreateIndex(!config.Quiet); err != nil {
213213
log.Printf("Failed to load filesystem index: %v", err)
214214
}
215215

@@ -240,7 +240,7 @@ Copyright @ Naren Yellavula (Please give us a star ⭐ here: https://github.com/
240240

241241
// Persist the index
242242
fmt.Printf("\n💾 Saving index to disk...")
243-
if err := fsIndexer.PersistIndex(); err != nil {
243+
if err := fsIndexer.PersistIndex(!config.Quiet); err != nil {
244244
log.Printf("Warning: Failed to persist index: %v", err)
245245
} else {
246246
fmt.Printf(" ✅\n")
@@ -274,7 +274,7 @@ Copyright @ Naren Yellavula (Please give us a star ⭐ here: https://github.com/
274274
fsIndexer := NewFilesystemIndexer(config.Filesystem)
275275

276276
// Load existing index
277-
if err := fsIndexer.LoadOrCreateIndex(); err != nil {
277+
if err := fsIndexer.LoadOrCreateIndex(!config.Quiet); err != nil {
278278
fmt.Printf("❌ Failed to load filesystem index: %v\n", err)
279279
return
280280
}
@@ -311,7 +311,7 @@ Copyright @ Naren Yellavula (Please give us a star ⭐ here: https://github.com/
311311
return
312312
}
313313

314-
if err := fsIndexer.PersistIndex(); err != nil {
314+
if err := fsIndexer.PersistIndex(!config.Quiet); err != nil {
315315
fmt.Printf("❌ Failed to persist cleared index: %v\n", err)
316316
return
317317
}
@@ -375,7 +375,7 @@ Copyright @ Naren Yellavula (Please give us a star ⭐ here: https://github.com/
375375
if !dryRun && stats.RemovedEntries > 0 {
376376
// Persist changes
377377
fmt.Printf("\n💾 Saving cleaned index...")
378-
if err := fsIndexer.PersistIndex(); err != nil {
378+
if err := fsIndexer.PersistIndex(!config.Quiet); err != nil {
379379
fmt.Printf(" ❌ Failed: %v\n", err)
380380
} else {
381381
fmt.Printf(" ✅\n")
@@ -427,14 +427,14 @@ Copyright @ Naren Yellavula (Please give us a star ⭐ here: https://github.com/
427427
fsIndexer := NewFilesystemIndexer(config.Filesystem)
428428

429429
// Load existing index
430-
if err := fsIndexer.LoadOrCreateIndex(); err != nil {
430+
if err := fsIndexer.LoadOrCreateIndex(!config.Quiet); err != nil {
431431
fmt.Printf("❌ Failed to load filesystem index: %v\n", err)
432432
fmt.Printf("💡 Run 'recaller fs index [path]' to create an index first.\n")
433433
return
434434
}
435435

436436
// Refresh the index using the shared function
437-
if err := fsIndexer.RefreshIndex(true, true); err != nil {
437+
if err := fsIndexer.RefreshIndex(!config.Quiet, true); err != nil {
438438
if err.Error() == "no tracked paths found in index" {
439439
fmt.Printf("📂 No tracked paths found in index.\n")
440440
fmt.Printf("💡 Run 'recaller fs index [path]' to index directories first.\n")
@@ -446,7 +446,7 @@ Copyright @ Naren Yellavula (Please give us a star ⭐ here: https://github.com/
446446
return
447447
}
448448

449-
fmt.Printf(" Refresh completed successfully!\n")
449+
fmt.Printf("✔️ Refresh completed successfully!\n")
450450
},
451451
}
452452

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
package main
1616

17-
const version = "v0.3.0"
17+
const version = "v0.4.0"

0 commit comments

Comments
 (0)