Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added ignore pattern matching for filesystem plugin #97

Merged
merged 2 commits into from
Jun 21, 2023
Merged
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
18 changes: 17 additions & 1 deletion plugins/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
)

const flagFolder = "path"
const flagIgnored = "ignore"

var ignoredFolders = []string{".git"}

type FileSystemPlugin struct {
Plugin
Path string
Path string
Ignored *[]string
}

func (p *FileSystemPlugin) GetName() string {
Expand All @@ -43,6 +45,8 @@ func (p *FileSystemPlugin) DefineCommand(channels Channels) (*cobra.Command, err
return nil, fmt.Errorf("error while marking '%s' flag as required: %w", flagFolder, err)
}

p.Ignored = flags.StringArray(flagIgnored, []string{}, "Patterns to ignore")
baruchiro marked this conversation as resolved.
Show resolved Hide resolved

return cmd, nil
}

Expand All @@ -57,6 +61,18 @@ func (p *FileSystemPlugin) getFiles(items chan Item, errs chan error, wg *sync.W
return filepath.SkipDir
}
}
for _, ignoredPattern := range *p.Ignored {
matched, err := filepath.Match(ignoredPattern, filepath.Base(path))
if err != nil {
return err
}
if matched && fInfo.IsDir() {
return filepath.SkipDir
}
if matched {
return nil
}
}
if fInfo.Size() == 0 {
return nil
}
Expand Down