Skip to content

fix(cli): consistent input, output and error handling across the CLIs - #286

Merged
DrunkOnJava merged 2 commits into
mainfrom
feat/cli-ergonomics
Sep 22, 2026
Merged

DrunkOnJava merged 2 commits into
mainfrom
feat/cli-ergonomics

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

The 18 CLIs now take input, write output and report errors the same way: positional input with a sensible default output, one error: <message> line that names the file, --json everywhere a JSON format exists, worked examples in every --help, and no panic backtrace when output is piped into head.

Motivation

The CLIs grew one at a time and a first-time user trips over the seams:

  • The README shows rvt-gltf my-project.rvt -o out.glb and rvt-sheet my-project.rvt -o out.svg; both binaries rejected that and demanded --src / --dst.
  • rvt-ifc, rvt-doc and rvt-elements returned anyhow::Result from main, so failures printed Rust's Debug form (Error: …); rvt-gltf printed rvt-gltf: open …; the rest error: ….
  • JSON output was --json on some tools and -f json on others.
  • rvt-schema model.rfa --json | head (or any large output into a closed pipe) ended in failed printing to stdout: Broken pipe plus a RUST_BACKTRACE hint.

Changes

  • rvt-gltf, rvt-sheet: positional INPUT, -o/--output defaulting to the input with .glb / .svg; --src/-s (hidden) and --dst/-d (alias of --output) still work; refuse to overwrite the input.
  • rvt-ifc, rvt-doc, rvt-elements: main returns ExitCode and prints error: <message> (exit 1). Open errors name the file once (the path comes from the library since feat(metadata): read worksharing, last save and document identity, and inventory folders with rvt-info #284).
  • --json shorthand on rvt-schema, rvt-history, rvt-corpus (+ doctor), rvt-elem-table, rvt-capabilities; combining it with --format is a usage error (exit 2).
  • src/cli.rs (new): exit_quietly_on_broken_pipe() — a panic hook that turns exactly println!'s closed-pipe panic (os error 32 Unix, os error 232 Windows) into exit 141 and leaves every other panic, including a full disk behind a redirect, to the default report. Called first in all 18 mains. Safe code, no new dependency.
  • Every --help ends with an Examples: block; each example was run against the phi-ag family corpus before being written down (that run caught one wrong example: rvt-write --dry-run still needs --dst).
  • rvt-history / rvt-elem-table document their positional FILE.
  • CHANGELOG entry under Fixed.

Testing

  • tools/check-local.sh with RVT_SAMPLES_DIR: fmt, clippy -D warnings, rustdoc -D warnings; workspace tests 1,291 passed, 1 failed — the failure is rvt_ifc_diagnostics_cli::rvt_ifc_cli_strict_mode_fails_before_writing_ifc_but_keeps_diagnostics, which fails identically on main and on the commit before feat(metadata): read worksharing, last save and document identity, and inventory folders with rvt-info #284 whenever the family corpus is present (it expects confidence scaffold, the 2024 sample now yields typed_no_geometry). CI never runs that file, so it went unnoticed; the follow-up PR fixes it together with the CI gap that hid it.
  • cargo +1.85.0 check --profile ci --all-targets (MSRV)
  • New tests/cli_ergonomics.rs (7 tests): positional input + default output, -o, legacy --src/--dst and -s/-d, overwrite refusal, one error: line naming the missing file exactly once for five CLIs, --json == --format json and the clash is exit 2, every --help has examples, closed stdout pipe exits 141 without "panicked" (corpus-gated)
  • Unit tests for the closed-pipe matcher (Unix / Windows messages recognised; disk-full and unrelated panics left alone)
  • N/A: IFC / glTF / SVG output unchanged

Audit-honesty checklist

  • README / docs reflect the current state after this PR — the README's positional examples now actually work
  • N/A: no capability-status change
  • No new limitation
  • Commit messages describe WHAT changed and WHY
  • No emojis in code, docs, or commit messages
  • No private paths, personal email addresses, or internal jargon in committed files
  • N/A: not a reverse-engineering finding

Legal and contribution hygiene

  • I agree this work is licensable under Apache-2.0 (see CONTRIBUTING.md)
  • This PR contains no Autodesk proprietary source, decompiled internals, or NDA'd SDK content (see CLEANROOM.md)
  • Test fixtures: tier-1 synthetic files only (plus the phi-ag family sample, gated, for the pipe test)

Breaking changes

None for invocations: every previous flag still parses. rvt-ifc, rvt-doc and rvt-elements print error: … instead of Error: … (exit code unchanged, 1).

Screenshots or output samples

$ rvt-gltf model.rvt --verbose
rvt-gltf: wrote 860 bytes (0 building elements) to model.glb
$ rvt-gltf model.rvt -o model.rvt
error: refusing to overwrite the input model.rvt; pass -o <path>
$ rvt-ifc nope.rvt
error: I/O error: nope.rvt: No such file or directory (os error 2)
$ rvt-ifc --help
...
Examples:
  rvt-ifc model.rvt                     writes model.ifc next to the input
  rvt-ifc model.rvt -o out.ifc --diagnostics out.diagnostics.json
  rvt-ifc model.rvt --mode geometry

Related issues

None


Note

Low Risk
User-facing CLI parsing and error/pipe handling only; export and decode paths are untouched aside from clearer error messages.

Overview
Standardizes how the shipped binaries accept input, write output, report failures, and behave when stdout is closed early—without changing IFC, glTF, or SVG export logic.

rvt-gltf and rvt-sheet now match the README: positional model path, default model.glb / model.svg beside the input, -o, and hidden legacy --src / --dst (aliases still work). Shared resolve_paths refuses to overwrite the input. Errors use error: … instead of tool-prefixed lines.

rvt-ifc, rvt-doc, and rvt-elements return ExitCode from main and print a single error: <message> (exit 1) instead of anyhow’s Error: debug form.

Several tools gain --json as shorthand for --format json (conflicts with -f → usage error exit 2). Every --help adds an Examples: block.

New rvt::cli::exit_quietly_on_broken_pipe (in src/cli.rs) is invoked first in all shipped main functions so piping into head exits 141 without a broken-pipe panic; other panics are unchanged. tests/cli_ergonomics.rs locks in positional/legacy flags, overwrite refusal, error shape, --json, help examples, and the quiet pipe exit.

Reviewed by Cursor Bugbot for commit 17b8896. Configure here.

rvt-gltf and rvt-sheet take the model as a positional argument and write
model.glb / model.svg next to it unless -o says otherwise, the form the
README already showed but the binaries rejected; --src / --dst (and -s /
-d) still work, and both refuse to overwrite their input. rvt-ifc,
rvt-doc and rvt-elements stop returning anyhow errors from main (which
printed the Debug "Error:" form): every CLI reports "error: <message>",
names the file once, and exits 1. rvt-schema, rvt-history, rvt-corpus
(and doctor), rvt-elem-table and rvt-capabilities accept --json for
--format json, as a usage error when combined with --format.

Piping any CLI into head no longer ends in "failed printing to stdout:
Broken pipe" and a panic backtrace: rvt::cli::exit_quietly_on_broken_pipe
turns exactly that panic into exit status 141 (what a shell reports for
SIGPIPE) on Unix and Windows pipes and leaves every other panic alone.
Every --help ends with worked examples, each run against the family
corpus first.
@cursor

cursor Bot commented Sep 22, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_f6588aa5-5501-451a-857b-10537356c083)

@DrunkOnJava
DrunkOnJava enabled auto-merge (squash) September 22, 2026 19:23
@DrunkOnJava
DrunkOnJava merged commit c5d9199 into main Sep 22, 2026
21 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/cli-ergonomics branch September 22, 2026 19:25
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.

1 participant