Skip to content

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

fix(completion): stop offering --dry-run and --var after an alias (#4329)

Worktrunk Botefb4e8b9e2c2
diff --git a/src/completion.rs b/src/completion.rs
index c0947f9cf..ea7357afc 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -573,10 +573,9 @@ pub(crate) fn inject_hook_subcommands(cmd: Command) -> Command {
})
}
-/// Build a completion stub `clap::Command` for a hook type. Same shape as
-/// `build_alias_completion_command` — declares the known flags (so they show
-/// up in `wt hook pre-merge --<Tab>` completions) and wires the name completer
-/// for the first positional (hook command name filter).
+/// Build a completion stub `clap::Command` for a hook type. Declares the known
+/// flags (so they show up in `wt hook pre-merge --<Tab>` completions) and wires
+/// the name completer for the first positional (hook command name filter).
fn build_hook_completion_command(name: &'static str) -> Command {
let about: &'static str = Box::leak(format!("Run {name} hooks").into_boxed_str());
Command::new(name)
@@ -756,6 +755,11 @@ fn mirror_alias_command(leaf: Command, alias_name: &str, rep: &CommandConfig) ->
/// Build a completion stub `clap::Command` for an alias. Leaks strings since
/// completion is a short-lived subprocess that exits after printing candidates.
+///
+/// The stub declares no flags of its own. An alias's flags are its template
+/// variables (`--KEY=VALUE`), which vary per alias: `AliasOptions::parse`
+/// rejects `--dry-run` unless the template references `dry_run`, and forwards
+/// `--var` to the alias as a plain argument.
fn build_alias_completion_command(name: &str, cmd_config: &CommandConfig) -> Command {
// Use the first command's template for the help text
let first_template = cmd_config
@@ -766,16 +770,7 @@ fn build_alias_completion_command(name: &str, cmd_config: &CommandConfig) -> Com
let help = truncate_template(first_template);
let name: &'static str = Box::leak(name.to_string().into_boxed_str());
let about: &'static str = Box::leak(format!("alias: {help}").into_boxed_str());
- Command::new(name)
- .about(about)
- .arg(clap::Arg::new("dry-run").long("dry-run"))
- .arg(clap::Arg::new("yes").short('y').long("yes"))
- .arg(
- clap::Arg::new("var")
- .long("var")
- .num_args(1)
- .action(clap::ArgAction::Append),
- )
+ Command::new(name).about(about)
}
/// Load aliases from user and project config for completion. Outside a git
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index e49817e21..20670ed5e 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -1861,8 +1861,11 @@ deploy = "make deploy"
assert!(subcommands.contains(&"deploy"));
}
+/// The generic alias stub offers no `--dry-run` (an error after an alias; the
+/// dry run is `wt config alias dry-run`) or `--var` (forwarded to the alias as
+/// a plain argument).
#[rstest]
-fn test_complete_step_alias_shows_flags(repo: TestRepo) {
+fn test_complete_step_alias_offers_no_misleading_flags(repo: TestRepo) {
repo.commit("initial");
repo.write_project_config(
r#"
@@ -1880,12 +1883,9 @@ deploy = "make deploy"
assert!(output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
- assert!(
- stdout.contains("--dry-run"),
- "Missing --dry-run flag: {stdout}"
- );
- assert!(stdout.contains("--yes"), "Missing --yes flag: {stdout}");
- assert!(stdout.contains("--var"), "Missing --var flag: {stdout}");
+ for flag in ["--dry-run", "--var"] {
+ assert!(!stdout.contains(flag), "Unexpected {flag} flag: {stdout}");
+ }
}
// --- Alias argument-completion mirroring -------------------------------------