fix(cli): accept flags before the PDF path and embed CMaps
Merged
AB
1mo ago+335+335+012345678901234567890123456789-91-91-01234567890123456789
Fixes #569
Summary
cargo install binaries failed the reported detect-pdf --json document.pdf command with IO error: No such file or directory (os error 2) because the first argument was always treated as the PDF path. --json was opened as a file, so every real path failed the same way. pdf2md --json document.pdf and pdf2md --password secret document.pdf had the same bug.
pdf2mdanddetect-pdfnow take the PDF path as the first non-option argument. Flags may come before or after it.--ends option parsing.- A missing input names the path (and, for a relative path, the working directory), so a genuinely absent file is distinguishable from a flag parsed as a path.
- Built-in CMaps are compiled into the binary. They were loaded at runtime from
CARGO_MANIFEST_DIR/external/bcmaps, which is the crates.io checkout forcargo installand does not exist inside a published wheel.PDF_INSPECTOR_BCMAPS_DIRstill overrides the embedded copies.
pdf2md document.pdf already opened that path. If the file is not in the working directory, the error now says so explicitly.
Test plan
-
cargo fmt -
cargo clippy -- -D warnings -
cargo test(1537 lib tests, CLI tests, integration tests) -
detect-pdf --json tests/fixtures/thermo-freon12.pdfreturnstext_based -
pdf2md --raw tests/fixtures/thermo-freon12.pdfprints markdown -
pdf2md document.pdfreportsdocument.pdf (working directory …): No such file or directorywhen that file is absent


Summary by cubic
Fixes detect-pdf --json file.pdf and pdf2md --json file.pdf failing with an IO error for every file, and embeds the built-in CMaps so cargo install binaries work without the crate source on disk.
- The PDF path is now the first non-option argument, so flags may come before or after it;
--ends option parsing. - A missing input error now names the path (plus the working directory for relative paths), so a genuinely absent file is distinguishable from a flag parsed as a path.
- Built-in CMaps are compiled into the binary instead of loaded at runtime;
PDF_INSPECTOR_BCMAPS_DIRstill overrides them.