google / addlicense

A program which ensures source code files have copyright license headers by scanning directory patterns recursively
Apache License 2.0
724 stars 170 forks source link

How does pattern work? #38

Open DarthHater opened 4 years ago

DarthHater commented 4 years ago

Hello there,

I'm using this on nancy, and more or less, great tool!

However, it's a bit too nuclear with the . pattern, and adding licenses to files that we need to exclude (primarily GitHub templates, but we also don't really need licenses on files that really don't have IP (Dockerfile, gorelease.yml, etc...), so I was looking at using the pattern to basically only check and apply to **/*.go files, and maybe a couple others here and there. There isn't really much documentation I can see on pattern, so I figured I'd ask about usage, and then send y'all a PR with it included in the README for other goofballs like myself!

Cheers!

DarthHater commented 4 years ago

I took a deeper look last night and it doesn't look like this is actually implemented? If that's the case @nblair and I were thinking of doing so, if y'all would welcome a PR!

benjivesterby commented 4 years ago

This seems to be working for me with ./*.go and just individual filenames. What were you trying @DarthHater

DarthHater commented 4 years ago

Basically, I just want to exclude stuff like README.md, etc... that really don't need a license file. I'll give it a twirl with your suggestion!

gtrevg commented 4 years ago

@DarthHater For reference, there's a similar project: https://github.com/elastic/go-licenser

Although it has less features, it'll walk the whole tree for you from the starting path you give it and will only apply the license to files that have the extension as defined by the -ext flag. I think it may only work for .go files, though.

I ended up having to use this other tool because //go:generate doesn't play nicely with wild cards.

justmumu commented 1 year ago

Guys,

Glob usage can be different due to terminal differences. For example, if you are using zsh, */.go is just works. But you are on bash it does not by default.

I think the clearest way to use addlicense is using it with find command. As an example to identical with */.go: addlicense -check -v -l bsd -c "Bla Bla." $(find . -name "*.go" -type f -print0 | xargs -0)

gtrevg commented 1 year ago

@justmumu -- We ended up using addlicense with the same technique you describe.