From 19216604700135dc6fcafb7861081800554da614 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Mon, 29 Apr 2024 18:27:29 +0400 Subject: [PATCH] add --php-ext argument Fixes #82 --- internal/phpgrep/main.go | 5 +++++ internal/phpgrep/program.go | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/phpgrep/main.go b/internal/phpgrep/main.go index 2557988..4207921 100644 --- a/internal/phpgrep/main.go +++ b/internal/phpgrep/main.go @@ -30,6 +30,9 @@ type arguments struct { cpuProfile string memProfile string + phpFileExt string + phpFileExtList []string + targets string pattern string filters []string @@ -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"`) diff --git a/internal/phpgrep/program.go b/internal/phpgrep/program.go index d916cf3..ec6a9f7 100644 --- a/internal/phpgrep/program.go +++ b/internal/phpgrep/program.go @@ -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 } @@ -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) {