Instruction file imported from mkhomutov/Persatrix (
.github/instructions/rust-cli.instructions.md). Copyright stays with the author.
Rust CLI
- Argument parsing:
clapv4 derive macros. See existingCommandenum incli/src/main.rs. - Exhaustive match: No catch-all
_on command enums. Adding a command must cause a compile error until all match arms are implemented. - Async runtime:
tokiowith#[tokio::main]. - Thin client: CLI is a REST client to the orchestrator at
--server(defaulthttp://localhost:8080). All business logic lives server-side. - Output:
tabledfor tables,indicatiffor progress bars,coloredfor terminal colors. - YAML:
serde_yml(maintained successor toserde_yaml). - Comments in plain English. Write comments a non-programmer could follow — say what the code does and why it matters, briefly. Full rules: Documentation Guide § Writing Style.
TDD (from v0.3.0 onward)
- Red-Green-Refactor: Write a failing
#[test](or#[tokio::test]) before implementing the function. Confirm the red state withcargo test -p persatrix(the package name incli/Cargo.toml) or simplycargo testfromcli/. - Unit test placement: Inline
#[cfg(test)] mod tests { ... }at the bottom of the source file being tested. - Integration tests: Place in
cli/tests/(create the directory on first use) as separate.rsfiles. These test CLI argument parsing and output formatting end-to-end without a live server (use a mock HTTP server ormockito). - HTTP calls: Mock the orchestrator REST API in unit tests — do not make real network calls. Inject the base URL via the
--serverflag or a test helper that bindsmockito.mockitois not currently declared incli/Cargo.toml; addmockito = "1"to[dev-dependencies]on first use (matches the lazy-add pattern called out in that file's comments). - New commands: Before adding a
Commandvariant, write at least one test that asserts the expected output format; implement until it passes.