in main.go [193:218]
func addOrCheckLicense(path, ext, license string, headerBytes []byte, info fs.DirEntry, dry bool, out io.Writer) error {
if info.IsDir() || filepath.Ext(path) != ext {
return nil
}
f, e := os.Open(path)
if e != nil {
return &Error{err: e, code: exitFailedToOpenWalkFile}
}
defer f.Close()
if licensing.ContainsHeader(f, licensing.Headers[license]) {
return nil
}
if dry {
reportFile(out, path)
return &Error{code: exitSourceNeedsToBeRewritten}
}
if err := licensing.RewriteFileWithHeader(path, headerBytes); err != nil {
return &Error{err: err, code: errFailedRewrittingFile}
}
return nil
}