Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: route `wt --version` output to stdout (#2073)
Worktrunk Bot8742c3a648f1
diff --git a/src/help.rs b/src/help.rsindex 2809ae81f..f01658611 100644--- a/src/help.rs+++ b/src/help.rs@@ -155,9 +155,10 @@ pub fn maybe_handle_help_with_pager() -> bool {process::exit(0);}ErrorKind::DisplayVersion => {- // Print to stderr - stdout is reserved for data/scripts- // Use eprint! because clap's Error Display already includes a trailing newline- eprint!("{}", err);+ // Print to stdout — POSIX convention, and scripts rely on+ // `version=$(wt --version)` working without redirection (#2072).+ // Use print! because clap's Error Display already includes a trailing newline.+ print!("{}", err);process::exit(0);}_ => {diff --git a/tests/integration_tests/help.rs b/tests/integration_tests/help.rsindex a6e3dfb5a..559d515ef 100644--- a/tests/integration_tests/help.rs+++ b/tests/integration_tests/help.rs@@ -110,6 +110,29 @@ fn test_version() {});}+/// `--version` must write to stdout, not stderr. This is the POSIX convention+/// and what scripts expect — e.g., `version=$(wt --version)` or test harnesses+/// that grep for a version string from stdout. See #2072.+#[test]+fn test_version_goes_to_stdout() {+ let output = wt_command()+ .arg("--version")+ .output()+ .expect("failed to run wt --version");++ let stdout = String::from_utf8_lossy(&output.stdout);+ let stderr = String::from_utf8_lossy(&output.stderr);++ assert!(+ stdout.contains("wt "),+ "wt --version should write to stdout, but stdout was: {stdout:?} (stderr: {stderr:?})"+ );+ assert!(+ stderr.trim().is_empty(),+ "wt --version should not write to stderr, but stderr was: {stderr:?}"+ );+}+#[test]fn test_help_md() {let mut settings = Settings::clone_current();diff --git a/tests/snapshots/integration__integration_tests__help__version.snap b/tests/snapshots/integration__integration_tests__help__version.snapindex 10026ad1d..48c768e09 100644--- a/tests/snapshots/integration__integration_tests__help__version.snap+++ b/tests/snapshots/integration__integration_tests__help__version.snap@@ -29,6 +29,6 @@ info:success: trueexit_code: 0----- stdout -----+wt [VERSION]----- stderr ------wt [VERSION]