AlDanial / cloc

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
GNU General Public License v2.0
19.78k stars 1.02k forks source link

Check that a file contains text #720

Closed Rspoon3 closed 1 year ago

Rspoon3 commented 1 year ago

Currently there is a way to exclude files that contain text using --exclude-content=<regex>. I’m looking for a way to do the opposite. I've tried cloc . --exclude-content='/^((?!import).)*$/s' but it doesn't give the desired results. I have also tried writing an ignored file using --ignored but that only gives the ignored reason, and not the line count.

I would like to request the ability to have a text include option. --include-content=<regex>. would be exactly what I’m looking for.

AlDanial commented 1 year ago

Give the version on master (https://github.com/AlDanial/cloc/blob/master/cloc) a try.

Rspoon3 commented 1 year ago

Maybe this is a dumb question, but how can I try that out? I'm on the latest version of macOS and have version 1.96 downloaded with Homebrew. There doesn't appear to be a straightforward way for me to point Homebrew at a specific branch. Is there a way I can download master and run it locally?

Rspoon3 commented 1 year ago

Ah I figured it out. Navigate to the downloaded master branch file, open the folder in terminal and use the following ./cloc /Users/richardwitherspoon/Desktop/My\ folder.

Rspoon3 commented 1 year ago

It works great! Exactly what I needed. Thank you!

AlDanial commented 1 year ago

glad to hear it

aaronpkelly commented 8 months ago

@AlDanial thanks for adding this feature... do you mind adding this to documentation? Maybe the README.md and the command line help?

AlDanial commented 8 months ago

@aaronpkelly : Thanks for pointing out the omission of --include-content in the README (the --exclude-content switch is already there). I'll add it.

fyi, both switches are already documented in the cloc's command line help.