goldsmith/filters/depth/depth.go

33 lines
479 B
Go
Raw Normal View History

2024-04-16 03:52:36 +00:00
package depth
import (
"path/filepath"
"strings"
"git.foosoft.net/alex/goldsmith"
)
type Depth struct {
depth int
}
func New(depth int) *Depth {
return &Depth{depth: depth}
}
func (*Depth) Name() string {
return "depth"
}
func (self *Depth) Accept(file *goldsmith.File) bool {
if self.depth == 0 {
return true
}
2024-05-06 02:38:30 +00:00
if parts := strings.Split(filepath.FromSlash(file.Path()), string(filepath.Separator)); len(parts) <= self.depth {
2024-04-16 03:52:36 +00:00
return true
}
return false
}