Skip to content

Route --help output to stdout - #2155

Merged
max-sixty merged 6 commits into
mainfrom
help-to-stdout
Apr 13, 2026
Merged

max-sixty merged 6 commits into
mainfrom
help-to-stdout

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Worktrunk sent all help output to stderr. This is an outlier versus most CLIs (cargo, curl, python, git <cmd> -h — all stdout) and versus --version, which moved to stdout in #2072 for the same reasons. Move help to stdout and canonicalize the shared pager function so its other callers (wt config show, wt hook show, wt config state) emit on stdout too.

The prior rationale — "stdout is reserved for data output" so wt config show | jq works — was already self-contradictory: config show went through the same pager helper and was landing on stderr.

What changed

  • src/help_pager.rs — removed the >&2 pager redirect and switched fallback prints from std::print! to the anstream-aware worktrunk::styling::print, so piped/redirected output is plain text rather than raw ANSI. Simplified the TTY guard to check stdout only (the stdout OR stderr check was a leftover from the redirect era).
  • src/help.rs — DisplayHelp fallback prints via styling::println.
  • src/commands/config/{show,state}.rs, src/commands/hook_commands.rs — pager fallbacks print to stdout.
  • Added test_help_goes_to_stdout and test_help_strips_ansi_when_piped as regression anchors (parallel to existing test_version_goes_to_stdout). Verified the ANSI test catches the bug by reverting temporarily.
  • Updated ~90 snapshots where content moved from the ----- stderr ----- section to ----- stdout -----.

User-visible behavior change

Scripts that did wt --help 2>/dev/null | x previously discarded help and piped nothing; they now pipe the help text. wt --help > file captures help instead of leaving the file blank. Both changes align Worktrunk with POSIX conventions. Terminal usage (pager on TTY) is unchanged.

This was written by Claude Code on behalf of @max-sixty

max-sixty and others added 4 commits April 12, 2026 19:05
Matches POSIX convention (cargo, curl, python, git <cmd> -h) and aligns
with --version (#2072). Previously help went to stderr with the rationale
"stdout is reserved for data output", but `show_help_in_pager` was shared
with `wt config show`, `wt hook show`, and `wt config state` — all data
outputs now also move to stdout, where they should have been.

User-visible behavior change: scripts doing `wt --help 2>/dev/null | x`
will see help on stdout rather than discarding it. `wt --help > file`
now captures help instead of producing a blank file.

Also simplified the pager TTY guard to check only stdout — the stderr
check was a leftover from the `>&2` redirect era.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
# Conflicts:
#	tests/snapshots/integration__integration_tests__help__help_config_shell.snap
#	tests/snapshots/integration__integration_tests__help__help_config_short.snap
#	tests/snapshots/integration__integration_tests__help__help_list_short.snap
#	tests/snapshots/integration__integration_tests__help__help_merge_short.snap
#	tests/snapshots/integration__integration_tests__help__help_no_args.snap
#	tests/snapshots/integration__integration_tests__help__help_remove_short.snap
#	tests/snapshots/integration__integration_tests__help__help_root_short.snap
#	tests/snapshots/integration__integration_tests__help__help_step_short.snap
#	tests/snapshots/integration__integration_tests__help__help_switch_short.snap
#	tests/snapshots/integration__integration_tests__step_alias__step_help_includes_aliases.snap
#	tests/snapshots/integration__integration_tests__step_alias__step_list_no_aliases.snap
#	tests/snapshots/integration__integration_tests__step_alias__step_list_with_aliases.snap
Main added new config_show deprecation snapshots and tweaked `-v` help
text; re-run captures content with our stdout routing applied.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Switch help_pager fallback prints from std::print! to the anstream-based
worktrunk::styling::print — stdlib prints the styled string verbatim,
so `wt --help > file` or `wt --help | less` was leaking raw escape
sequences instead of plain text.

Found by Codex review.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One stale docstring in src/help_pager.rs — the TTY check was simplified to stdout-only but the bullet list still mentions stderr.

Comment thread src/help_pager.rs Resolved
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

codecov/patch failed at 40% of diff hit (target 96.20%). Worktrunk's CLAUDE.md policy requires explicit approval to merge past a failing patch check, so flagging here.

The uncovered diff lines in src/help_pager.rs are the direct-print fallback branches that this PR rewords from eprint! to print!:

  • no-pager branch (detect_help_pager() returned None)
  • ShellConfig::get() error branch
  • pager spawn-failure branch
  • pager stdin write-failure

Each of these is s/eprint!/print!/ (plus /// stderr/stdout/ doc edits) on lines that were already uncovered on main — the behavior change is the output stream, not the logic, and the stream itself isn't testable in the same run via the existing fallback path (no pager + error simulation needs injection). The primary --help | cat and -h paths are covered by the two new tests in tests/integration_tests/help.rs.

I'd treat this as a false-positive-ish codecov/patch fail, but leaving the call to you.

The bullet list said "Neither stdout nor stderr is a TTY" but the check
was simplified to stdout only. Flagged by worktrunk-bot review on #2155.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
# Conflicts:
#	tests/integration_tests/config_state.rs
@max-sixty
max-sixty merged commit 5279d1f into main Apr 13, 2026
22 checks passed
@max-sixty
max-sixty deleted the help-to-stdout branch April 13, 2026 03:30
max-sixty added a commit that referenced this pull request Apr 13, 2026
Three tests in config_state.rs were asserting on stderr with empty inline
snapshots — they kept passing after PR #2155 moved state output from stderr
to stdout, but no longer verified anything. Switch the assertions to stdout
and capture the real content.

Co-Authored-By: Claude <[email protected]>
max-sixty added a commit that referenced this pull request Apr 13, 2026
Three tests in `tests/integration_tests/config_state.rs` were asserting
on `stderr` with empty inline snapshots — they kept passing after #2155
moved `wt config state` output from stderr to stdout, but no longer
verified anything. This swaps the assertions to `stdout` and captures
the real content.

Affected tests: `test_state_get_empty`, `test_state_get_logs_empty`,
`test_state_get_logs_dir_exists_no_log_files`.

> _This was written by Claude Code on behalf of Maximilian._

Co-authored-by: Claude <[email protected]>
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.

2 participants