Crate file_header
source ·Expand description
Tools for checking for, or adding, headers (e.g. licenses, etc) in files.
See the license::spdx module for more on using licenses as headers.
Examples
Checking for a header:
// Copyright 2023 Google LLC.
// SPDX-License-Identifier: Apache-2.0
use file_header::*;
use std::path::Path;
let checker = SingleLineChecker::new("Foo License".to_string(), 10);
let header = Header::new(checker, "Foo License\nmore license text".to_string());
match check_headers_recursively(
Path::new("/some/dir"),
// check every file -- see `globset` crate for path patterns
|p| true,
header,
// check with 4 threads
4
) {
Ok(fr) => { println!("files without the header: {:?}", fr.no_header_files) }
Err(e) => { println!("got an error: {:?}", e) }
}
Modules
- License-specific header functionality
Structs
- Aggregated results for recursively checking a directory tree of files.
- A file header to check for, or add to, files.
- Checks for a pattern in the first several lines of each file.
Enums
- Errors that can occur when adding a header
- Errors that can occur when adding a header recursively
- Errors that can occur when checking for headers recursively
Traits
- Checks for headers in files, like licenses or author attribution.
Functions
- Add the provided
header
to any file inroot
that matchespath_predicate
and that doesn’t already have a header as determined bychecker
. Returns a list of paths that had headers added. - Recursively check for
header
in every file inroot
that matchespath_predicate
.