Skip to content

feat(cli): add a Rust anydoc binary for cargo install - #29

Open
LeoLin990405 wants to merge 1 commit into
firecrawl:mainfrom
LeoLin990405:feat/rust-cli-binary
Open

feat(cli): add a Rust anydoc binary for cargo install#29
LeoLin990405 wants to merge 1 commit into
firecrawl:mainfrom
LeoLin990405:feat/rust-cli-binary

Conversation

@LeoLin990405

@LeoLin990405 LeoLin990405 commented Aug 6, 2026

Copy link
Copy Markdown

Closes #24.

Adds src/bin/anydoc.rs so cargo install anydoc yields the same CLI the npm package ships. The two front ends stay interchangeable — same options (-o/--output, -f/--format, -h, -V, --, - for stdin, --opt=value inline form), same help text, same exit codes (0 success / 1 conversion / 2 usage), and the same tolerances: stdin-on-a-TTY is a usage error, early-closed stdout (anydoc big.xlsx | head) exits 0.

Design notes:

  • No new dependencies. Argument parsing is hand-rolled to mirror node/cli.js line for line rather than pulling in clap; --format validates through the existing Format::from_extension, so extension aliases (xls, docm, ppsx, …) resolve identically to the npm CLI.
  • The one deliberate divergence: when a file can't be read, the error names the path (anydoc: report.docx: No such file or directory…) — the library-level ConvertError::Io message doesn't carry it, and on the CLI the filename is the useful part.
  • Cargo.toml needs no changes: the bin is auto-discovered, include = ["/src", …] already packages it, and library consumers (cargo add) never build it.
  • README gains a half-sentence pointing at cargo install anydoc in the CLI section.

Testing:

  • tests/cli.rs drives the built binary end to end via CARGO_BIN_EXE_anydoc: file conversion, stdin with a named format, --format=csv inline form, alias resolution, --output, and every usage-error path (15 tests).
  • cargo fmt --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, and cargo test --locked all pass locally (182 lib + 15 CLI + snapshot/robustness suites).
  • Manually verified: docx/epub/csv fixtures convert byte-identically to the npm CLI paths, and anydoc - --format csv < big.csv | head -c 80 exits 0 on the closed pipe.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Add src/bin/anydoc.rs so `cargo install anydoc` yields the same CLI the
npm package ships: identical options, help text, stdin handling, exit
codes (0/1/2), and early-EPIPE tolerance as node/cli.js. No new
dependencies; argument parsing is hand-rolled to match the npm front
end, and --format validates through Format::from_extension so extension
aliases resolve identically.

End-to-end coverage in tests/cli.rs drives the built binary through the
conversion paths (file, stdin, named format, --output) and every usage
error.

Closes firecrawl#24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust CLI binary

1 participant