Skip to content

Commit

Permalink
add --php-ext argument
Browse files Browse the repository at this point in the history
Fixes #82
  • Loading branch information
quasilyte committed Apr 29, 2024
1 parent a5d57a4 commit 1921660
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions internal/phpgrep/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type arguments struct {
cpuProfile string
memProfile string

phpFileExt string
phpFileExtList []string

targets string
pattern string
filters []string
Expand Down Expand Up @@ -168,6 +171,8 @@ Supported command-line flags:
`exclude files or directories by regexp pattern`)
flag.StringVar(&args.excludeResults, "exclude-results", "",
`exclude the results listed in the file`)
flag.StringVar(&args.phpFileExt, "php-ext", "php,php5,inc,phtml",
`a comma-separated list of extensions to scan`)

flag.StringVar(&args.progressMode, "progress", "update",
`progress printing mode: "update", "append" or "none"`)
Expand Down
12 changes: 6 additions & 6 deletions internal/phpgrep/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func (p *program) validateFlags() error {
if p.args.limit == 0 || p.args.limit > maxLimit {
p.args.limit = maxLimit
}

for _, e := range strings.Split(p.args.phpFileExt, ",") {
p.args.phpFileExtList = append(p.args.phpFileExtList, "."+strings.TrimSpace(e))
}

return nil
}

Expand Down Expand Up @@ -353,12 +358,7 @@ func (p *program) executePattern() error {
}

func (p *program) walkTarget(target string, filenameQueue chan<- string, ticker *time.Ticker) error {
phpExtensions := []string{
".php",
".php5",
".inc",
".phtml",
}
phpExtensions := p.args.phpFileExtList
isPHPFile := func(name string) bool {
for _, ext := range phpExtensions {
if strings.HasSuffix(name, ext) {
Expand Down

0 comments on commit 1921660

Please sign in to comment.