Skip to content

Commit 1c3b90d

Browse files
committed
Exclude certain files by default in the debug output
1 parent 2169176 commit 1c3b90d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

cmd/debug/debug.go

+29
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
"regexp"
78
"sort"
89
"strings"
910

@@ -25,6 +26,14 @@ type FileInfo struct {
2526
Path string
2627
}
2728

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+
2837
// debugCmd represents the config command
2938
var debugCmd = &cobra.Command{
3039
Use: "debug",
@@ -80,6 +89,12 @@ func collectFiles(root string) []FileInfo {
8089
info, err := os.Stat(path)
8190
if err == nil {
8291
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+
8398
files = append(files, FileInfo{Size: info.Size(), Path: relPath})
8499
}
85100
}
@@ -91,6 +106,17 @@ func collectFiles(root string) []FileInfo {
91106
return files
92107
}
93108

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+
94120
// humanReadableSize converts bytes into a human-friendly format (KB, MB, GB, etc.)
95121
func humanReadableSize(bytes int64) string {
96122
const unit = 1024
@@ -107,7 +133,10 @@ func humanReadableSize(bytes int64) string {
107133

108134
func init() {
109135
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+
110138
cobra.CheckErr(viper.BindPFlag("debug-sort", debugCmd.PersistentFlags().Lookup("sort")))
139+
cobra.CheckErr(viper.BindPFlag("debug-all-files", debugCmd.PersistentFlags().Lookup("all-files")))
111140

112141
cmd.RootCmd.AddCommand(debugCmd)
113142
}

0 commit comments

Comments
 (0)