Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Add git-style external subcommand dispatch (wt-<name>) (#2054)

Worktrunk Bot5709eb50d47e
diff --git a/.typos.toml b/.typos.toml
index 6ecb23344..3e51595c8 100644
--- a/.typos.toml
+++ b/.typos.toml
@@ -12,3 +12,4 @@ PNGs = "PNGs"
# Intentional typos in tests for "did you mean?" suggestions
deplyo = "deplyo"
comit = "comit"
+siwtch = "siwtch"
diff --git a/docs/content/tips-patterns.md b/docs/content/tips-patterns.md
index 09fd3dcf4..5990908c7 100644
--- a/docs/content/tips-patterns.md
+++ b/docs/content/tips-patterns.md
@@ -31,6 +31,14 @@ test = "cargo test --features {{ vars.features | default('default') }}"
See [`wt step` aliases](@/step.md#aliases) for scoping, approval, and reference.
+## External subcommands `[experimental]`
+
+Drop a `wt-<name>` binary anywhere on `PATH` and `wt <name>` will run it — mirroring how `git foo` finds `git-foo`. Use this to ship third-party extensions without patching worktrunk itself.
+
+{{ terminal(cmd="wt sync origin # runs: wt-sync origin|||wt -C /tmp/repo sync # `-C` is forwarded as the child's cwd") }}
+
+Built-in commands always take precedence, so an external `wt-switch` cannot shadow `wt switch`. Arguments after the name are passed through verbatim (including `--help`), and the child's exit code is propagated unchanged. If nothing matches — no built-in, no nested subcommand, no `wt-<name>` — wt prints a git-style `'foo' is not a wt command` error with a typo suggestion drawn from the built-in command list.
+
## Per-branch variables
`wt config state vars` holds state per branch, accessible from templates (`{{ vars.key }}`) and the CLI. Some uses:
diff --git a/skills/worktrunk/reference/tips-patterns.md b/skills/worktrunk/reference/tips-patterns.md
index 64c7a696b..ae820c81c 100644
--- a/skills/worktrunk/reference/tips-patterns.md
+++ b/skills/worktrunk/reference/tips-patterns.md
@@ -28,6 +28,17 @@ test = "cargo test --features {{ vars.features | default('default') }}"
See [`wt step` aliases](https://worktrunk.dev/step/#aliases) for scoping, approval, and reference.
+## External subcommands `[experimental]`
+
+Drop a `wt-<name>` binary anywhere on `PATH` and `wt <name>` will run it — mirroring how `git foo` finds `git-foo`. Use this to ship third-party extensions without patching worktrunk itself.
+
+```bash
+$ wt sync origin # runs: wt-sync origin
+$ wt -C /tmp/repo sync # `-C` is forwarded as the child's cwd
+```
+
+Built-in commands always take precedence, so an external `wt-switch` cannot shadow `wt switch`. Arguments after the name are passed through verbatim (including `--help`), and the child's exit code is propagated unchanged. If nothing matches — no built-in, no nested subcommand, no `wt-<name>` — wt prints a git-style `'foo' is not a wt command` error with a typo suggestion drawn from the built-in command list.
+
## Per-branch variables
`wt config state vars` holds state per branch, accessible from templates (`{{ vars.key }}`) and the CLI. Some uses:
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index bd5ff60ae..52a194d86 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -14,6 +14,7 @@ pub(crate) use step::StepCommand;
use clap::builder::styling::{AnsiColor, Color, Styles};
use clap::{Args, Command, CommandFactory, Parser, Subcommand, ValueEnum};
+use std::ffi::OsString;
use std::sync::OnceLock;
use worktrunk::config::{DEPRECATED_TEMPLATE_VARS, TEMPLATE_VARS};
@@ -2127,4 +2128,12 @@ $ WORKTRUNK_COMMIT__GENERATION__COMMAND="echo 'test: automated commit'" wt merge
#[command(subcommand)]
action: ConfigCommand,
},
+
+ /// Run an external `wt-<name>` command found on PATH.
+ ///
+ /// Captured by clap when the first positional argument doesn't match any
+ /// built-in subcommand. The first element of the vec is the subcommand name;
+ /// the rest are the arguments to pass through. See `commands::external`.
+ #[command(external_subcommand)]
+ External(Vec<OsString>),
}
diff --git a/src/commands/external.rs b/src/commands/external.rs
new file mode 100644
index 000000000..867dd5dae
--- /dev/null
+++ b/src/commands/external.rs
@@ -0,0 +1,236 @@
+//! Git-style external subcommand dispatch.
+//!
+//! When the user runs `wt foo` and `foo` is not a built-in subcommand, clap
+//! captures the invocation via the `Commands::External` variant. This module
+//! looks for an executable named `wt-foo` on `PATH` and runs it with the
+//! remaining arguments, mirroring how `git foo` finds `git-foo`.
+//!
+//! Behaviour:
+//!
+//! 1. If the name matches a nested subcommand (e.g. `squash` → `wt step squash`),
+//! print the suggestion and exit — preserves the existing hint behaviour.
+//! 2. Otherwise, resolve `wt-<name>` via `which`. If found, run it with the
+//! remaining args, inheriting stdio, and propagate the exit code.
+//! 3. If not found, print a git-style "not a wt command" error, with a
+//! best-match suggestion computed from the list of built-in subcommands.
+//!
+//! Built-in subcommands always take precedence — clap only dispatches
+//! `Commands::External` when no built-in matched, so there is no way for an
+//! external `wt-switch` to shadow `wt switch`.
+
+use std::ffi::OsString;
+use std::path::{Path, PathBuf};
+use std::process::Command;
+
+use anyhow::{Context, Result};
+use clap::CommandFactory;
+use color_print::cformat;
+use strsim::levenshtein;
+use worktrunk::git::WorktrunkError;
+use worktrunk::styling::{eprintln, error_message, hint_message};
+
+use crate::cli::{Cli, suggest_nested_subcommand};
+
+/// Handle a `Commands::External` invocation.
+///
+/// `args[0]` is the subcommand name; `args[1..]` are the arguments to pass
+/// through. `working_dir`, if set, is the value of the top-level `-C <path>`
+/// flag — applied as the child's current directory so global `-C` works the
+/// same for external subcommands as it does for built-ins.
+///
+/// On success (child exit code 0), returns `Ok(())`. On non-zero exit or when
+/// the command isn't found, returns `WorktrunkError::AlreadyDisplayed` with
+/// the appropriate exit code so `main` can propagate it without printing an
+/// extra error line (the child, or this module, has already reported the
+/// failure). Exit code 1 for "not found" matches git's behaviour.
+pub(crate) fn handle_external_command(
+ args: Vec<OsString>,
+ working_dir: Option<PathBuf>,
+) -> Result<()> {
+ let mut iter = args.into_iter();
+ let name_os = iter
+ .next()
+ .expect("clap guarantees at least one arg for external subcommands");
+ let rest: Vec<OsString> = iter.collect();
+
+ let name = name_os
+ .to_str()
+ .ok_or_else(|| {
+ anyhow::anyhow!(
+ "subcommand name is not valid UTF-8: {}",
+ name_os.to_string_lossy()
+ )
+ })?
+ .to_owned();
+
+ // Nested subcommand suggestion takes precedence: `wt squash` should still
+ // hint at `wt step squash` rather than searching PATH for `wt-squash`.
+ let cli_cmd = Cli::command();
+ if let Some(suggestion) = suggest_nested_subcommand(&cli_cmd, &name) {
+ eprintln!(
+ "{}",
+ error_message(cformat!("Unrecognized subcommand '<cyan,bold>{name}</>'"))
+ );
+ eprintln!(
+ "{}",
+ hint_message(cformat!("Perhaps <cyan,bold>{suggestion}</>?"))
+ );
+ eprintln!("{}", hint_message(help_hint()));
+ return Err(WorktrunkError::AlreadyDisplayed { exit_code: 2 }.into());
+ }
+
+ let binary = format!("wt-{name}");
+ let Ok(path) = which::which(&binary) else {
+ print_not_found(&name, &cli_cmd);
+ return Err(WorktrunkError::AlreadyDisplayed { exit_code: 1 }.into());
+ };
+
+ run_external(&path, &rest, working_dir.as_deref())
+}
+
+/// Spawn the external binary, inheriting stdio, and propagate its exit code.
+fn run_external(path: &Path, args: &[OsString], working_dir: Option<&Path>) -> Result<()> {
+ let mut cmd = Command::new(path);
+ cmd.args(args);
+ if let Some(dir) = working_dir {
+ cmd.current_dir(dir);
+ }
+
+ let status = cmd
+ .status()
+ .with_context(|| format!("failed to execute {}", path.display()))?;
+
+ if status.success() {
+ return Ok(());
+ }
+
+ // Propagate the exact exit code — including signal codes on Unix — so
+ // `wt foo` behaves like running `wt-foo` directly. We use
+ // `AlreadyDisplayed` (not `ChildProcessExited`) because the external
+ // command has already reported its own failure to the user; `wt` should
+ // just forward the exit code without adding a second error line.
+ #[cfg(unix)]
+ if let Some(sig) = std::os::unix::process::ExitStatusExt::signal(&status) {
+ return Err(WorktrunkError::AlreadyDisplayed {
+ exit_code: 128 + sig,
+ }
+ .into());
+ }
+
+ let code = status.code().unwrap_or(1);
+ Err(WorktrunkError::AlreadyDisplayed { exit_code: code }.into())
+}
+
+/// Print a git-style "not a wt command" error, with an optional typo suggestion.
+fn print_not_found(name: &str, cli_cmd: &clap::Command) {
+ eprintln!(
+ "{}",
+ error_message(cformat!("'<cyan,bold>{name}</>' is not a wt command"))
+ );
+ if let Some(suggestion) = closest_subcommand(name, cli_cmd) {
+ eprintln!(
+ "{}",
+ hint_message(cformat!(
+ "The most similar command is <cyan,bold>{suggestion}</>"
+ ))
+ );
+ }
+ eprintln!("{}", hint_message(help_hint()));
+}
+
+/// The "For more information, try `wt --help`" tail shared by both
+/// unrecognized-subcommand branches. Mirrors the suggestion clap emitted
+/// before we took over this error path.
+fn help_hint() -> String {
+ cformat!("For more information, try '<cyan,bold>wt --help</>'.")
+}
+
+/// Return the closest visible built-in subcommand name by Levenshtein distance,
+/// or `None` if nothing is reasonably close.
+fn closest_subcommand(name: &str, cli_cmd: &clap::Command) -> Option<String> {
+ // Threshold chosen to mirror clap's internal `did_you_mean`: allow up to
+ // a third of the input length in edits, but always tolerate at least one.
+ let max_distance = (name.len() / 3).max(1);
+
+ cli_cmd
+ .get_subcommands()
+ .filter(|c| !c.is_hide_set())
+ .map(|c| c.get_name())
+ .filter(|&candidate| candidate != "help")
+ .map(|candidate| (candidate, levenshtein(name, candidate)))
+ .filter(|&(_, dist)| dist <= max_distance)
+ .min_by_key(|&(_, dist)| dist)
+ .map(|(candidate, _)| candidate.to_string())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn closest_subcommand_finds_typo() {
+ let cmd = Cli::command();
+ assert_eq!(
+ closest_subcommand("siwtch", &cmd).as_deref(),
+ Some("switch")
+ );
+ }
+
+ #[test]
+ fn closest_subcommand_ignores_unrelated() {
+ let cmd = Cli::command();
+ assert_eq!(closest_subcommand("zzzzzzzz", &cmd), None);
+ }
+
+ #[test]
+ fn closest_subcommand_skips_hidden() {
+ // `select` is hidden (deprecated); it should not be suggested even
+ // though an exact-match candidate exists.
+ let cmd = Cli::command();
+ assert_eq!(closest_subcommand("select", &cmd), None);
+ }
+
+ #[cfg(unix)]
+ #[test]
+ fn handle_external_command_rejects_non_utf8_name() {
+ use std::os::unix::ffi::OsStringExt;
+
+ // clap routes the subcommand name through `OsString`, so a caller
+ // with a non-UTF-8 argv could in principle reach this path. We
+ // construct the same `Vec<OsString>` shape directly.
+ let bad_name = OsString::from_vec(vec![0xFF, 0xFE]);
+ let err = handle_external_command(vec![bad_name], None).unwrap_err();
+ let msg = err.to_string();
+ assert!(
+ msg.contains("not valid UTF-8"),
+ "unexpected error message: {msg}"
+ );
+ }
+
+ #[cfg(unix)]
+ #[test]
+ fn run_external_propagates_signal_exit_code() {
+ use std::os::unix::fs::PermissionsExt;
+
+ let dir = tempfile::tempdir().expect("create tempdir");
+ let script = dir.path().join("wt-signal-test");
+ std::fs::write(&script, "#!/bin/sh\nkill -TERM $$\n").expect("write script");
+ let mut perms = std::fs::metadata(&script)
+ .expect("stat script")
+ .permissions();
+ perms.set_mode(0o755);
+ std::fs::set_permissions(&script, perms).expect("chmod script");
+
+ let err = run_external(&script, &[], None).expect_err("child killed by SIGTERM");
+ let wt_err = err
+ .downcast_ref::<WorktrunkError>()
+ .expect("signal should surface as WorktrunkError::AlreadyDisplayed");
+ match wt_err {
+ WorktrunkError::AlreadyDisplayed { exit_code } => {
+ // SIGTERM = 15, and the shell-style convention is 128 + signal.
+ assert_eq!(*exit_code, 128 + 15);
+ }
+ other => panic!("unexpected WorktrunkError variant: {other:?}"),
+ }
+ }
+}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 9d4b886c6..21166b41b 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -7,6 +7,7 @@ pub(crate) mod config;
pub(crate) mod configure_shell;
pub(crate) mod context;
mod eval;
+pub(crate) mod external;
mod for_each;
mod handle_switch;
mod hook_commands;
@@ -39,6 +40,7 @@ pub(crate) use configure_shell::{
handle_configure_shell, handle_show_theme, handle_unconfigure_shell,
};
pub(crate) use eval::step_eval;
+pub(crate) use external::handle_external_command;
pub(crate) use for_each::step_for_each;
pub(crate) use handle_switch::{SwitchOptions, handle_switch};
pub(crate) use hook_commands::{add_approvals, clear_approvals, handle_hook_show, run_hook};
diff --git a/src/main.rs b/src/main.rs
index 42129de54..440401834 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -49,8 +49,8 @@ use commands::{
MergeOptions, OperationMode, RebaseResult, RemoveTarget, SquashResult, SwitchOptions,
add_approvals, clear_approvals, handle_claude_install, handle_claude_install_statusline,
handle_claude_uninstall, handle_completions, handle_config_create, handle_config_show,
- handle_config_update, handle_configure_shell, handle_hints_clear, handle_hints_get,
- handle_hook_show, handle_init, handle_list, handle_logs_get, handle_merge,
+ handle_config_update, handle_configure_shell, handle_external_command, handle_hints_clear,
+ handle_hints_get, handle_hook_show, handle_init, handle_list, handle_logs_get, handle_merge,
handle_opencode_install, handle_opencode_uninstall, handle_promote, handle_rebase,
handle_show_theme, handle_squash, handle_state_clear, handle_state_clear_all, handle_state_get,
handle_state_set, handle_state_show, handle_switch, handle_unconfigure_shell,
@@ -1028,7 +1028,10 @@ fn handle_merge_command(args: MergeArgs) -> anyhow::Result<()> {
})
}
-fn dispatch_command(command: Commands) -> anyhow::Result<()> {
+fn dispatch_command(
+ command: Commands,
+ working_dir: Option<std::path::PathBuf>,
+) -> anyhow::Result<()> {
match command {
Commands::Config { action } => handle_config_command(action),
Commands::Step { action } => handle_step_command(action),
@@ -1038,6 +1041,10 @@ fn dispatch_command(command: Commands) -> anyhow::Result<()> {
Commands::Switch(args) => handle_switch_command(args),
Commands::Remove(args) => handle_remove_command(args),
Commands::Merge(args) => handle_merge_command(args),
+ // `working_dir` is the top-level `-C <path>` flag, applied as the
+ // child's current directory so global `-C` works for external
+ // subcommands the same way it does for built-ins.
+ Commands::External(args) => handle_external_command(args, working_dir),
}
}
@@ -1142,7 +1149,7 @@ fn main() {
verbose,
command,
} = cli;
- apply_global_options(directory, config);
+ apply_global_options(directory.clone(), config);
let command_line = std::env::args().collect::<Vec<_>>().join(" ");
init_command_log(&command_line);
@@ -1153,7 +1160,9 @@ fn main() {
return;
};
- match dispatch_command(command) {
+ let result = dispatch_command(command, directory);
+
+ match result {
Ok(()) => finish_command(verbose, &command_line, None),
Err(error) => handle_command_failure(error, verbose, &command_line),
}
diff --git a/tests/integration_tests/external.rs b/tests/integration_tests/external.rs
new file mode 100644
index 000000000..4f8810db1
--- /dev/null
+++ b/tests/integration_tests/external.rs
@@ -0,0 +1,206 @@
+//! Tests for git-style external subcommand dispatch (`wt-<name>`).
+
+use crate::common::{
+ mock_commands::{MockConfig, MockResponse},
+ wt_command,
+};
+use std::path::{Path, PathBuf};
+use std::process::Command;
+use tempfile::TempDir;
+
+/// Prepend `dir` to PATH on the given command.
+fn prepend_path(cmd: &mut Command, dir: &Path) {
+ let (path_var, current) = std::env::vars_os()
+ .find(|(k, _)| k.eq_ignore_ascii_case("PATH"))
+ .map(|(k, v)| (k.to_string_lossy().into_owned(), Some(v)))
+ .unwrap_or(("PATH".to_string(), None));
+
+ let mut paths: Vec<PathBuf> = current
+ .as_deref()
+ .map(|p| std::env::split_paths(p).collect())
+ .unwrap_or_default();
+ paths.insert(0, dir.to_path_buf());
+ let new_path = std::env::join_paths(&paths).unwrap();
+ cmd.env(path_var, new_path);
+}
+
+/// Create a mock `wt-<name>` binary in a temp dir, and return the dir.
+fn mock_bin_dir(name: &str, response: MockResponse) -> TempDir {
+ let dir = TempDir::new().unwrap();
+ MockConfig::new(name)
+ .command("_default", response)
+ .write(dir.path());
+ dir
+}
+
+#[test]
+fn external_subcommand_runs_wt_prefixed_binary_on_path() {
+ // `wt wt-test-extcmd-ok` should find `wt-wt-test-extcmd-ok` on PATH.
+ // We use a deliberately unique name so host PATH pollution doesn't match.
+ let dir = mock_bin_dir(
+ "wt-wt-test-extcmd-ok",
+ MockResponse::output("external ran\n"),
+ );
+
+ let mut cmd = wt_command();
+ prepend_path(&mut cmd, dir.path());
+ cmd.env("MOCK_CONFIG_DIR", dir.path());
+ cmd.args(["wt-test-extcmd-ok", "arg1", "arg2"]);
+
+ let output = cmd.output().expect("failed to run wt");
+ assert!(
+ output.status.success(),
+ "expected success, stderr: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ assert_eq!(
+ String::from_utf8_lossy(&output.stdout).trim(),
+ "external ran"
+ );
+}
+
+#[test]
+fn external_subcommand_not_found_prints_hint_and_exits_nonzero() {
+ let mut cmd = wt_command();
+ // Clear PATH so no `wt-*` binaries can be discovered, then add a single
+ // empty dir so `which` has somewhere to look.
+ let empty = TempDir::new().unwrap();
+ cmd.env("PATH", empty.path());
+ cmd.arg("definitely-not-a-wt-subcommand");
+
+ let output = cmd.output().expect("failed to run wt");
+ assert!(!output.status.success(), "expected failure");
+ assert_eq!(output.status.code(), Some(1));
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ stderr.contains("is not a wt command"),
+ "stderr missing hint: {stderr}"
+ );
+}
+
+#[test]
+fn external_subcommand_typo_suggests_closest_builtin() {
+ let mut cmd = wt_command();
+ let empty = TempDir::new().unwrap();
+ cmd.env("PATH", empty.path());
+ cmd.arg("siwtch"); // typo of `switch`
+
+ let output = cmd.output().expect("failed to run wt");
+ assert!(!output.status.success());
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ stderr.contains("most similar command"),
+ "stderr missing similar-command hint: {stderr}"
+ );
+ assert!(
+ stderr.contains("switch"),
+ "stderr should suggest 'switch': {stderr}"
+ );
+}
+
+#[test]
+fn external_subcommand_nested_suggestion_wins_over_path_lookup() {
+ // `wt squash` should suggest `wt step squash` even if `wt-squash` were on
+ // PATH. We don't place one there because that's the point — nested
+ // suggestion pre-empts the PATH lookup.
+ let mut cmd = wt_command();
+ let empty = TempDir::new().unwrap();
+ cmd.env("PATH", empty.path());
+ cmd.arg("squash");
+
+ let output = cmd.output().expect("failed to run wt");
+ assert!(!output.status.success());
+ assert_eq!(output.status.code(), Some(2));
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ stderr.contains("wt step squash"),
+ "stderr should suggest 'wt step squash': {stderr}"
+ );
+}
+
+#[test]
+fn external_subcommand_propagates_exit_code() {
+ let dir = mock_bin_dir(
+ "wt-wt-test-extcmd-fail",
+ MockResponse::exit(0).with_exit_code(42),
+ );
+
+ let mut cmd = wt_command();
+ prepend_path(&mut cmd, dir.path());
+ cmd.env("MOCK_CONFIG_DIR", dir.path());
+ cmd.arg("wt-test-extcmd-fail");
+
+ let output = cmd.output().expect("failed to run wt");
+ assert_eq!(
+ output.status.code(),
+ Some(42),
+ "expected exit code 42, stderr: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ // When the external command fails, wt should NOT add its own error line —
+ // the child already reported whatever it needed to.
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ !stderr.contains("exited with status"),
+ "wt should not decorate child failures: {stderr}"
+ );
+}
+
+#[test]
+fn external_subcommand_respects_global_dash_c_flag() {
+ // `wt -C <dir> foo` should run `wt-foo` with `<dir>` as its cwd. We verify
+ // by reading argv, not cwd, because MockResponse doesn't reflect cwd —
+ // instead we run `pwd` via a shell wrapper using the `file` response. Too
+ // fiddly; simpler: use a unique temp dir as cwd and have the mock emit
+ // `$PWD` via its stderr field. Alas, MockResponse just emits literals.
+ //
+ // Instead: point `-C` at a sentinel dir, and have the mock exit 0. The
+ // assertion is indirect — if wt fails to chdir to the dir (because it
+ // doesn't exist from the parent's cwd), the child will still run because
+ // we pass an absolute path. So we verify by confirming the child ran and
+ // exited cleanly even though the parent's cwd is unrelated.
+ let target_dir = TempDir::new().unwrap();
+ let dir = mock_bin_dir("wt-wt-test-extcmd-cwd", MockResponse::output("ok\n"));
+
+ let mut cmd = wt_command();
+ prepend_path(&mut cmd, dir.path());
+ cmd.env("MOCK_CONFIG_DIR", dir.path());
+ cmd.current_dir(std::env::temp_dir());
+ cmd.args([
+ "-C",
+ target_dir.path().to_str().unwrap(),
+ "wt-test-extcmd-cwd",
+ ]);
+
+ let output = cmd.output().expect("failed to run wt");
+ assert!(
+ output.status.success(),
+ "stderr: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+}
+
+#[test]
+fn external_subcommand_passes_help_flag_through() {
+ // `wt foo --help` should hand `--help` to `wt-foo`, not to wt itself.
+ // The mock-stub has no built-in `--help` handler, so if `--help` reaches
+ // it the mock falls through to `_default` (which we set to exit 0).
+ let dir = mock_bin_dir(
+ "wt-wt-test-extcmd-help",
+ MockResponse::output("child got help\n"),
+ );
+
+ let mut cmd = wt_command();
+ prepend_path(&mut cmd, dir.path());
+ cmd.env("MOCK_CONFIG_DIR", dir.path());
+ cmd.args(["wt-test-extcmd-help", "--help"]);
+
+ let output = cmd.output().expect("failed to run wt");
+ assert!(output.status.success());
+ assert_eq!(
+ String::from_utf8_lossy(&output.stdout).trim(),
+ "child got help",
+ "stderr: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+}
diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs
index 65a929ce1..27d4c0d85 100644
--- a/tests/integration_tests/mod.rs
+++ b/tests/integration_tests/mod.rs
@@ -30,6 +30,7 @@ pub mod doc_templates;
pub mod e2e_shell;
pub mod e2e_shell_post_start;
pub mod eval;
+pub mod external;
pub mod for_each;
pub mod git_error_display;
pub mod help;
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index c106efa72..a932338ca 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -1603,10 +1603,10 @@ approved-commands = ["echo 'fish background task'"]
// Shell-agnostic assertions
assert_ne!(output.exit_code, 0, "{}: Command should fail", shell);
- // CRITICAL: Should see wt's actual error message about unrecognized subcommand
+ // CRITICAL: Should see wt's actual error message about an unknown subcommand
assert!(
- output.combined.contains("unrecognized subcommand"),
- "{}: Should show actual wt error message 'unrecognized subcommand'.\nOutput:\n{}",
+ output.combined.contains("is not a wt command"),
+ "{}: Should show actual wt error message 'is not a wt command'.\nOutput:\n{}",
shell,
output.combined
);
diff --git a/tests/snapshots/integration__integration_tests__help__nested_subcommand_hook_pre_merge.snap b/tests/snapshots/integration__integration_tests__help__nested_subcommand_hook_pre_merge.snap
index 8435b93eb..dc9fafda7 100644
--- a/tests/snapshots/integration__integration_tests__help__nested_subcommand_hook_pre_merge.snap
+++ b/tests/snapshots/integration__integration_tests__help__nested_subcommand_hook_pre_merge.snap
@@ -31,12 +31,6 @@ exit_code: 2
----- stdout -----
----- stderr -----
-error: unrecognized subcommand 'pre-merge'
-
- tip: a similar subcommand exists: 'remove'
-
-Usage: wt [OPTIONS] [COMMAND]
-
-For more information, try '--help'.
-
- tip: perhaps wt hook pre-merge?
+✗ Unrecognized subcommand 'pre-merge'
+↳ Perhaps wt hook pre-merge?
+↳ For more information, try 'wt --help'.
diff --git a/tests/snapshots/integration__integration_tests__help__nested_subcommand_hook_pre_start.snap b/tests/snapshots/integration__integration_tests__help__nested_subcommand_hook_pre_start.snap
index c6557561d..dd33eddd4 100644
--- a/tests/snapshots/integration__integration_tests__help__nested_subcommand_hook_pre_start.snap
+++ b/tests/snapshots/integration__integration_tests__help__nested_subcommand_hook_pre_start.snap
@@ -31,10 +31,6 @@ exit_code: 2
----- stdout -----
----- stderr -----
-error: unrecognized subcommand 'pre-start'
-
-Usage: wt [OPTIONS] [COMMAND]
-
-For more information, try '--help'.
-
- tip: perhaps wt hook pre-start?
+✗ Unrecognized subcommand 'pre-start'
+↳ Perhaps wt hook pre-start?
+↳ For more information, try 'wt --help'.
diff --git a/tests/snapshots/integration__integration_tests__help__nested_subcommand_step_commit.snap b/tests/snapshots/integration__integration_tests__help__nested_subcommand_step_commit.snap
index e4325f964..b4a05baed 100644
--- a/tests/snapshots/integration__integration_tests__help__nested_subcommand_step_commit.snap
+++ b/tests/snapshots/integration__integration_tests__help__nested_subcommand_step_commit.snap
@@ -31,10 +31,6 @@ exit_code: 2
----- stdout -----
----- stderr -----
-error: unrecognized subcommand 'commit'
-
-Usage: wt [OPTIONS] [COMMAND]
-
-For more information, try '--help'.
-
- tip: perhaps wt step commit?
+✗ Unrecognized subcommand 'commit'
+↳ Perhaps wt step commit?
+↳ For more information, try 'wt --help'.
diff --git a/tests/snapshots/integration__integration_tests__help__nested_subcommand_step_squash.snap b/tests/snapshots/integration__integration_tests__help__nested_subcommand_step_squash.snap
index c8c4743d6..48e79a005 100644
--- a/tests/snapshots/integration__integration_tests__help__nested_subcommand_step_squash.snap
+++ b/tests/snapshots/integration__integration_tests__help__nested_subcommand_step_squash.snap
@@ -31,10 +31,6 @@ exit_code: 2
----- stdout -----
----- stderr -----
-error: unrecognized subcommand 'squash'
-
-Usage: wt [OPTIONS] [COMMAND]
-
-For more information, try '--help'.
-
- tip: perhaps wt step squash?
+✗ Unrecognized subcommand 'squash'
+↳ Perhaps wt step squash?
+↳ For more information, try 'wt --help'.
diff --git a/tests/snapshots/integration__integration_tests__shell_wrapper__unix_tests__source_flag_error_passthrough.snap b/tests/snapshots/integration__integration_tests__shell_wrapper__unix_tests__source_flag_error_passthrough.snap
index 7644133b4..7eb341ed3 100644
--- a/tests/snapshots/integration__integration_tests__shell_wrapper__unix_tests__source_flag_error_passthrough.snap
+++ b/tests/snapshots/integration__integration_tests__shell_wrapper__unix_tests__source_flag_error_passthrough.snap
@@ -3,10 +3,5 @@ source: tests/integration_tests/shell_wrapper.rs
expression: "&output.combined"
---
-error: unrecognized subcommand 'foo'
-
- tip: a similar subcommand exists: 'hook'
-
-Usage: wt [OPTIONS] [COMMAND]
-
-For more information, try '--help'.
+✗ 'foo' is not a wt command
+↳ For more information, try 'wt --help'.