Skip to content

fix(cli): --out writes only to the file, not also to stdout - #371

Merged
PabloCodes7 merged 1 commit into
mainfrom
fix/out-flag-no-stdout-tee
Jul 16, 2026
Merged

PabloCodes7 merged 1 commit into
mainfrom
fix/out-flag-no-stdout-tee

Conversation

@PabloCodes7

Copy link
Copy Markdown
Contributor

--out is meant to redirect output to a file. But every command that takes --out shares one helper — _write_or_print — which, despite its name, wrote the file and still printed the whole report to stdout:

def _write_or_print(text, out):
    if out is not None:
        out.parent.mkdir(parents=True, exist_ok=True)
        out.write_text(text, encoding="utf-8")
    print(text, end="")   # ran even when out was set

So patchrail ci explain --log ci.log --out report.md flooded the terminal with the report a first-timer had just asked to send to a file, and a CI script capturing stdout while using --out got the report duplicated into its pipe (having to add > /dev/null to work around it).

Fix: --out is now silent on stdout — matching curl -o, gcc -o, openssl … -out and the helper's own name (_write_or_print = write or print). Running without --out prints to stdout exactly as before.

Shared by every --out command (ci explain/classify/classes, redact, evidence …, and the rest).

Before / after

# before:  report written to file AND dumped to terminal
$ patchrail ci explain --log ci.log --out report.md
# PatchRail CI Report
- Root cause: `node_dependency_install`
...            # <-- whole report on stdout too

# after:  file written, stdout clean
$ patchrail ci explain --log ci.log --out report.md
$ cat report.md
# PatchRail CI Report
...

Tests

  • New regression test test_ci_explain_out_writes_file_without_teeing_stdout: exit 0, stdout empty, file contains the report.
  • Full suite green (947 passed, 739 subtests) + ruff clean.

Marca: Pablo Guillén · PatchRail · getpatchrail.com

Every command that takes --out shares one helper, _write_or_print, which
despite its name wrote the file AND still printed the whole report to stdout.
So `patchrail ci explain --log ci.log --out report.md` flooded the terminal
with the report a first-timer had just asked to send to a file, and a CI
script capturing stdout while using --out got the report duplicated into its
pipe. Make --out silent on stdout, matching curl -o / gcc -o / openssl -out
and the helper's own name; running without --out prints exactly as before.
Add a regression test for `ci explain --out`.
@PabloCodes7
PabloCodes7 merged commit f7eb6b3 into main Jul 16, 2026
5 checks passed
@PabloCodes7
PabloCodes7 deleted the fix/out-flag-no-stdout-tee branch July 16, 2026 05:26
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