Skip to content

Commit

Permalink
feat: added ignore pattern matching for filesystem plugin (#97)
Browse files Browse the repository at this point in the history
I added the `--ignore` flag to let the user add patterns for files to be
ignored. A user may supply multiple patterns using this form: `2ms
filesystem --path path --ignore "*foo" --ignore "bar*"`

I did not add tests as I am unsure how you guys want to test the
plugins, worth discussing how a plugin test should be written.

Awaiting your feedback, cheers.

Close #93

---------

Signed-off-by: SHA65536 <[email protected]>
  • Loading branch information
SHA65536 authored Jun 21, 2023
1 parent 157f7f5 commit 67d27fe
Showing 1 changed file with 17 additions and 1 deletion.
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")

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

0 comments on commit 67d27fe

Please sign in to comment.