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
License-specific header functionality

Structs§

FileResults
Aggregated results for recursively checking a directory tree of files.
Header
A file header to check for, or add to, files.
SingleLineChecker
Checks for a pattern in the first several lines of each file.

Enums§

AddHeaderError
Errors that can occur when adding a header
AddHeadersRecursivelyError
Errors that can occur when adding a header recursively
CheckHeadersRecursivelyError
Errors that can occur when checking for headers recursively
DeleteHeaderError
Errors that can occur when deleting a header
DeleteHeadersRecursivelyError
Errors that can occur when adding a header recursively

Traits§

HeaderChecker
Checks for headers in files, like licenses or author attribution.

Functions§

add_headers_recursively
Add the provided header to any file in root that matches path_predicate and that doesn’t already have a header as determined by checker.
check_headers_recursively
Recursively check for header in every file in root that matches path_predicate.
delete_headers_recursively
Delete the provided header from any file in root that matches path_predicate and that already has a header as determined by header’s checker.