feat(cli): add a Rust anydoc binary for cargo install - #29
Open
LeoLin990405 wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #24.
Adds
src/bin/anydoc.rssocargo install anydocyields the same CLI the npm package ships. The two front ends stay interchangeable — same options (-o/--output,-f/--format,-h,-V,--,-for stdin,--opt=valueinline 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:
node/cli.jsline for line rather than pulling in clap;--formatvalidates through the existingFormat::from_extension, so extension aliases (xls,docm,ppsx, …) resolve identically to the npm CLI.anydoc: report.docx: No such file or directory…) — the library-levelConvertError::Iomessage doesn't carry it, and on the CLI the filename is the useful part.Cargo.tomlneeds no changes: the bin is auto-discovered,include = ["/src", …]already packages it, and library consumers (cargo add) never build it.cargo install anydocin the CLI section.Testing:
tests/cli.rsdrives the built binary end to end viaCARGO_BIN_EXE_anydoc: file conversion, stdin with a named format,--format=csvinline form, alias resolution,--output, and every usage-error path (15 tests).cargo fmt --check,cargo clippy --workspace --all-targets --all-features -- -D warnings, andcargo test --lockedall pass locally (182 lib + 15 CLI + snapshot/robustness suites).anydoc - --format csv < big.csv | head -c 80exits 0 on the closed pipe.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.