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

Traits

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

Functions

  • 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. Returns a list of paths that had headers added.
  • Recursively check for header in every file in root that matches path_predicate.