google / addlicense

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

Support CMake files #67

Closed srgbtl closed 3 years ago

srgbtl commented 3 years ago

Add support for CMake files: CMakeLists.txt, file.cmake, file.cmake.in

willnorris commented 3 years ago

Instead of forcing this into the existing switch statement, which makes it a little awkward, what about moving it out of the switch statement altogether? I'm refactoring the licenseHeader func in #90, which should make it pretty simple to add something like...

switch fileExtension(base) {
  // existing logic
}

// handle various cmake files
if base == "cmakelists.txt" || strings.HasSuffix(base, ".cmake.in") || strings.HasSuffix(base, ".cmake") {
  return executeTemplate(tmpl, data, "", "# ", "")
}

return nil, nil

Once #90 lands, would you be willing to rebase your changes and try something like that? I've also added some new tests, so you'd just need to add a section here, rather than adding all the testdata/* files, which is a bit more straightforward.

srgbtl commented 3 years ago

@googlebot I consent.