4
4
"fmt"
5
5
"os"
6
6
"path/filepath"
7
+ "regexp"
7
8
"sort"
8
9
"strings"
9
10
@@ -25,6 +26,14 @@ type FileInfo struct {
25
26
Path string
26
27
}
27
28
29
+ // Exclusions - List of patterns to exclude in the default mode
30
+ var exclusions = []string {
31
+ `\.DS_Store$` ,
32
+ `data_layer/db/server_files_location.*/.*delta.*` , // Don't show delta files by default
33
+ `wallet/db/temp.*` ,
34
+ `run/.*` ,
35
+ }
36
+
28
37
// debugCmd represents the config command
29
38
var debugCmd = & cobra.Command {
30
39
Use : "debug" ,
@@ -80,6 +89,12 @@ func collectFiles(root string) []FileInfo {
80
89
info , err := os .Stat (path )
81
90
if err == nil {
82
91
relPath , _ := filepath .Rel (root , path )
92
+
93
+ // Apply exclusions
94
+ if ! viper .GetBool ("debug-all-files" ) && isExcluded (relPath ) {
95
+ return nil // Skip this file
96
+ }
97
+
83
98
files = append (files , FileInfo {Size : info .Size (), Path : relPath })
84
99
}
85
100
}
@@ -91,6 +106,17 @@ func collectFiles(root string) []FileInfo {
91
106
return files
92
107
}
93
108
109
+ // isExcluded checks if a file path matches any exclusion pattern
110
+ func isExcluded (path string ) bool {
111
+ for _ , pattern := range exclusions {
112
+ match , _ := regexp .MatchString (pattern , path )
113
+ if match {
114
+ return true
115
+ }
116
+ }
117
+ return false
118
+ }
119
+
94
120
// humanReadableSize converts bytes into a human-friendly format (KB, MB, GB, etc.)
95
121
func humanReadableSize (bytes int64 ) string {
96
122
const unit = 1024
@@ -107,7 +133,10 @@ func humanReadableSize(bytes int64) string {
107
133
108
134
func init () {
109
135
debugCmd .PersistentFlags ().Bool ("sort" , false , "Sort the files largest first" )
136
+ debugCmd .PersistentFlags ().Bool ("all-files" , false , "Show all files. By default, some typically small files are excluded from the output" )
137
+
110
138
cobra .CheckErr (viper .BindPFlag ("debug-sort" , debugCmd .PersistentFlags ().Lookup ("sort" )))
139
+ cobra .CheckErr (viper .BindPFlag ("debug-all-files" , debugCmd .PersistentFlags ().Lookup ("all-files" )))
111
140
112
141
cmd .RootCmd .AddCommand (debugCmd )
113
142
}
0 commit comments