exclude_from_backups 1.1.0

Mark files or directories as excluded from backups (for Time Machine on macOS). Can be used to prevent caches and temporary files from bloating backups. Includes both a library interface and a basic command-line executable.
Documentation
use exclude_from_backups as efb;
use std::env;
use std::path::Path;
use std::process::ExitCode;

fn main() -> ExitCode {
    let mut errors = false;
    let mut okay = false;
    for arg in env::args_os().skip(1) {
        let mut path = Path::new(&arg);

        if path.file_name().is_some_and(|f| f == "CACHEDIR.TAG") {
            path = path.parent().unwrap();
        }
        if let Err(err) = efb::exclude_from_backups(path) {
            eprintln!("{}: {}", path.display(), err);
            errors = true;
        } else {
            okay = true;
        }
    }

    if okay && !errors {
        ExitCode::SUCCESS
    } else {
        if !errors {
            let exe = std::env::current_exe();
            let exe = exe.as_deref().map(|e| e.display()).unwrap_or(Path::new("exclude_from_backups").display());
            eprintln!("usage: {exe} [paths to exclude]");
        }
        ExitCode::FAILURE
    }
}