Support multiple --name and --match flags with OR logic
Allow users to specify multiple --name and --match flags in any combination. Files matching ANY of the specified criteria are collected, following standard Linux command conventions like grep -e and rsync --include. Changes: - Add CompositeMatcher for combining multiple matchers with OR logic - Update CLI to accept multiple flag values using custom stringSlice type - Add comprehensive tests for multiple flag combinations - Update usage message with examples of multiple flag usage
This commit is contained in:
parent
eb88ef97c0
commit
1265f9fb07
3 changed files with 85 additions and 13 deletions
|
@ -116,4 +116,24 @@ func (m *PatternMatcher) dirMatchesPattern(dirPath string) (bool, error) {
|
|||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// CompositeMatcher combines multiple matchers with OR logic
|
||||
type CompositeMatcher struct {
|
||||
matchers []Matcher
|
||||
}
|
||||
|
||||
// NewCompositeMatcher creates a matcher that combines multiple matchers
|
||||
func NewCompositeMatcher(matchers []Matcher) *CompositeMatcher {
|
||||
return &CompositeMatcher{matchers: matchers}
|
||||
}
|
||||
|
||||
// ShouldInclude returns true if ANY of the matchers match the file
|
||||
func (m *CompositeMatcher) ShouldInclude(path string, info os.FileInfo) bool {
|
||||
for _, matcher := range m.matchers {
|
||||
if matcher.ShouldInclude(path, info) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue