Skip to content

Commit

Permalink
Merge pull request #56 from qonto/add_grep_inlcude_param
Browse files Browse the repository at this point in the history
Add --include flag to grep configuration
  • Loading branch information
B3rs authored Feb 7, 2024
2 parents 2dba195 + a5d4e6f commit f0bf01b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ type FileRule struct {

type GrepRule struct {
Path string `validate:"required"`
Recursive bool
Pattern string `validate:"required"`
Include string
Recursive bool
Match bool
SkipNotFound bool `yaml:"skip-not-found"`
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/ruler/rules/grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (

type GrepRule struct {
Path string
Recursive bool
Include string
Pattern string
Recursive bool
Match bool
SkipNotFound bool
}
Expand All @@ -26,6 +27,7 @@ func NewGrepRule(config config.GrepRule) *GrepRule {
Path: config.Path,
Recursive: config.Recursive,
Pattern: config.Pattern,
Include: config.Include,
Match: config.Match,
SkipNotFound: config.SkipNotFound,
}
Expand All @@ -42,6 +44,9 @@ func (rule *GrepRule) Do(ctx context.Context, project project.Project) error {
if rule.Recursive {
arguments = append(arguments, "-r")
}
if rule.Include != "" {
arguments = append(arguments, "--include", rule.Include)
}
arguments = append(arguments, rule.Pattern, path)

cmd := exec.CommandContext(ctx, "grep", arguments...) //nolint
Expand Down
19 changes: 19 additions & 0 deletions pkg/ruler/rules/grep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ func TestGrepRule(t *testing.T) {
Match: false,
},
},
{
rule: rules.GrepRule{
Path: "_testdata",
Recursive: true,
Include: "file1",
Pattern: "abcdefg",
Match: true,
},
},
{
rule: rules.GrepRule{
Path: "_testdata",
Recursive: true,
Include: "file2",
Pattern: "abcdefg",
Match: true,
},
error: "no match for pattern",
},
{
rule: rules.GrepRule{
Path: "_testdata",
Expand Down

0 comments on commit f0bf01b

Please sign in to comment.