Skip to content

Commit

Permalink
add --fullpath option
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Dec 26, 2024
1 parent e26badb commit 8d10564
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/gocloc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type CmdOptions struct {
NotMatch string `long:"not-match" description:"exclude file name (regex)"`
MatchDir string `long:"match-d" description:"include dir name (regex)"`
NotMatchDir string `long:"not-match-d" description:"exclude dir name (regex)"`
Fullpath bool `long:"fullpath" description:"apply match/not-match options to full file paths instead of base names"`
Debug bool `long:"debug" description:"dump debug log for developer"`
SkipDuplicated bool `long:"skip-duplicated" description:"skip duplicated files"`
ShowLang bool `long:"show-lang" description:"print about all languages and extensions"`
Expand Down Expand Up @@ -289,6 +290,7 @@ func main() {

clocOpts.Debug = opts.Debug
clocOpts.SkipDuplicated = opts.SkipDuplicated
clocOpts.Fullpath = opts.Fullpath

processor := gocloc.NewProcessor(languages, clocOpts)
result, err := processor.Analyze(paths)
Expand Down
1 change: 1 addition & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ClocOptions struct {
ReMatch *regexp.Regexp
ReNotMatchDir *regexp.Regexp
ReMatchDir *regexp.Regexp
Fullpath bool

// OnCode is triggered for each line of code.
OnCode func(line string)
Expand Down
9 changes: 7 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ func checkDefaultIgnore(path string, info os.FileInfo, isVCS bool) bool {

func checkOptionMatch(path string, info os.FileInfo, opts *ClocOptions) bool {
// check match directory & file options
if opts.ReNotMatch != nil && opts.ReNotMatch.MatchString(info.Name()) {
targetFile := info.Name()
if opts.Fullpath {
targetFile = path
}

if opts.ReNotMatch != nil && opts.ReNotMatch.MatchString(targetFile) {
return false
}
if opts.ReMatch != nil && !opts.ReMatch.MatchString(info.Name()) {
if opts.ReMatch != nil && !opts.ReMatch.MatchString(targetFile) {
return false
}

Expand Down

0 comments on commit 8d10564

Please sign in to comment.