tftio-kb 2.5.3

Personal knowledge base — typed AST with org-mode as projection, SQLite-backed
Documentation
#![cfg_attr(
    not(test),
    deny(clippy::unwrap_used, clippy::panic, clippy::indexing_slicing)
)]
//! `kb-parse-survey`: walk a directory of `.org` files, parse each one
//! with [`kb::parser`], and print a summary of what kb's parser can and
//! cannot handle — parse failures, mangled-pattern frequency, per-file
//! round-trip loss verdict, and exact-variant duplicate groups.
//! Read-only diagnostic — no DB, no network.
//!
//! Usage: `kb-parse-survey [--verbose|-v] <dir>`

use std::io::Write;
use std::process::ExitCode;

use kb::survey;

fn main() -> ExitCode {
    let args: Vec<String> = std::env::args().skip(1).collect();
    let mut verbose = false;
    let mut positional: Vec<String> = Vec::new();
    for arg in args {
        if arg == "--verbose" || arg == "-v" {
            verbose = true;
        } else {
            positional.push(arg);
        }
    }
    let dir = if let [d] = positional.as_slice() {
        d.clone()
    } else {
        eprintln!("usage: kb-parse-survey [--verbose] <dir>");
        return ExitCode::FAILURE;
    };

    let report = survey::run(&dir, verbose);
    let stdout = std::io::stdout();
    let mut handle = stdout.lock();
    if handle.write_all(report.as_bytes()).is_err() {
        return ExitCode::FAILURE;
    }
    ExitCode::SUCCESS
}