Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions pkg/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@
fileColorFunc := getColorFunc(fileColorName)
execColorFunc := getColorFunc(execColorName)

var traverse func(string, string, int) error
var traverse func(string, string, int) bool
traverse = func(currentDir string, prefix string, depth int) error {

Check failure on line 129 in pkg/printer/printer.go

View workflow job for this annotation

GitHub Actions / Run Tests

cannot use func(currentDir string, prefix string, depth int) error {…} (value of type func(currentDir string, prefix string, depth int) error) as func(string, string, int) bool value in assignment
if maxDepth != -1 && depth >= maxDepth {
return nil
return false

Check failure on line 131 in pkg/printer/printer.go

View workflow job for this annotation

GitHub Actions / Run Tests

cannot use false (constant of type bool) as error value in return statement: bool does not implement error (missing method Error)
}
dir, err := os.Open(currentDir)
if err != nil {
Expand All @@ -138,12 +138,13 @@

entries, err := dir.Readdir(-1)
if err != nil {
return err
return false

Check failure on line 141 in pkg/printer/printer.go

View workflow job for this annotation

GitHub Actions / Run Tests

cannot use false (constant of type bool) as error value in return statement: bool does not implement error (missing method Error)
}

// Sort entries based on the specified criteria and order
sortEntries(entries, sortBy, order)

found := false
for i, entry := range entries {
if !includeHidden && strings.HasPrefix(entry.Name(), ".") {
continue
Expand All @@ -159,17 +160,16 @@
isLast := i == len(entries)-1

if entry.IsDir() {
dirCount++
if useColor {
fmt.Printf("%s%s/\n", prefix+getTreePrefix(isLast), dirColorFunc(entry.Name()))
} else {
fmt.Printf("%s%s/\n", prefix+getTreePrefix(isLast), entry.Name())
}
output += fmt.Sprintf("%s%s/\n", prefix+getTreePrefix(isLast), entry.Name())

err := traverse(filepath.Join(currentDir, entry.Name()), prefix+getIndent(isLast), depth+1)
if err != nil {
return err
hasMatch := traverse(filepath.Join(currentDir, entry.Name()), prefix+getIndent(isLast), depth+1)
if extFilter == "" || hasMatch {
found = true
dirCount++
if useColor {
fmt.Printf("%s%s/\n", prefix+getTreePrefix(isLast), dirColorFunc(entry.Name()))
} else {
fmt.Printf("%s%s/\n", prefix+getTreePrefix(isLast), entry.Name())
}
output += fmt.Sprintf("%s%s/\n", prefix+getTreePrefix(isLast), entry.Name())
}
} else {
if extFilter == "" || strings.HasSuffix(entry.Name(), extFilter) {
Expand All @@ -187,21 +187,17 @@
fmt.Printf("%s%s\n", prefix+getTreePrefix(isLast), entry.Name())
}
output += fmt.Sprintf("%s%s/\n", prefix+getTreePrefix(isLast), entry.Name())
found = true
}
}
}

return nil
return found

Check failure on line 194 in pkg/printer/printer.go

View workflow job for this annotation

GitHub Actions / Run Tests

cannot use found (variable of type bool) as error value in return statement: bool does not implement error (missing method Error)
}

fmt.Printf("%s/\n", filepath.Base(root))
output += fmt.Sprintf("%s/\n", filepath.Base(root))

err := traverse(root, "", 0)
if err != nil {
fmt.Println("Error traversing directory:", err)
output += fmt.Sprintf("Error traversing directory: %v\n", err)
}
traverse(root, "", 0)
fmt.Printf("\n%d directories, %d files\n", dirCount, fileCount)
output += fmt.Sprintf("\n%d directories, %d files\n", dirCount, fileCount)

Expand Down Expand Up @@ -291,7 +287,7 @@

if entry.IsDir() {
child := buildTree(filepath.Join(currentDir, entry.Name()), extFilter, excludePatterns, sortBy, order, includeHidden, maxDepth, depth+1)
if child != nil {
if child != nil && (extFilter == "" || len(child.Children) > 0) {
node.Children = append(node.Children, child)
}
} else if extFilter == "" || strings.HasSuffix(entry.Name(), extFilter) {
Expand Down
Loading