pdf-untangle 0.0.1

Untangle garbled PDF text: layout-aware extraction that reconstructs reading order, strips page furniture, and splits documents into structured, citable sections
Documentation
//! pdf-untangle CLI — thin wrapper over the pdf_untangle library.

use std::path::PathBuf;
use std::process::ExitCode;

use clap::{Parser, Subcommand};
use pdf_untangle::profile;

#[derive(Parser)]
#[command(
    name = "pdf-untangle",
    version,
    about = "Untangle garbled PDF text into structured sections"
)]
struct Cli {
    #[command(subcommand)]
    command: Command,
}

#[derive(Subcommand)]
enum Command {
    /// Extract structured provisions using a profile (JSONL output).
    Extract {
        pdf: PathBuf,
        #[arg(long)]
        profile: String,
        /// Output path (default: stdout).
        #[arg(short, long)]
        out: Option<PathBuf>,
    },
    /// Emit clean, reading-ordered text (Layer 2 only; no profile needed).
    Text { pdf: PathBuf },
    /// Dump positioned runs/blocks for a page (profile-authoring aid).
    Inspect {
        pdf: PathBuf,
        #[arg(long, default_value_t = 1)]
        page: u32,
    },
    /// List built-in profiles.
    Profiles,
    /// Dry-run a profile: coverage + structure-integrity report (exit != 0 on loss).
    Check {
        pdf: PathBuf,
        #[arg(long)]
        profile: String,
    },
}

fn main() -> ExitCode {
    let cli = Cli::parse();
    match cli.command {
        Command::Profiles => {
            for name in profile::builtin_names() {
                match profile::Profile::builtin(name) {
                    Ok(p) => {
                        let draft = if p.draft {
                            "  (draft — citation template pending sign-off)"
                        } else {
                            ""
                        };
                        println!(
                            "{name}: {} / {} — \"{}\"{draft}",
                            p.jurisdiction, p.kind, p.citation_template
                        );
                    }
                    Err(e) => eprintln!("{name}: BROKEN — {e:#}"),
                }
            }
            ExitCode::SUCCESS
        }
        Command::Extract { .. }
        | Command::Text { .. }
        | Command::Inspect { .. }
        | Command::Check { .. } => {
            eprintln!(
                "not implemented yet: this subcommand lands with Phases 1-3 (docs/DESIGN.md). \
                 The scaffold currently ships the profile system and output model only."
            );
            ExitCode::from(2)
        }
    }
}