Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat(completion): Enable flexible argument ordering
Maximilian Roos38d0ff0aad62
diff --git a/src/completion.rs b/src/completion.rsindex fbfbc33a8..8e7bb1aa7 100644--- a/src/completion.rs+++ b/src/completion.rs@@ -102,11 +102,19 @@ fn completion_command() -> Command {adjust_completion_command(Cli::command())}-// Mark positional target args as `.last(true)` to allow them after all flags.-// This enables flexible argument ordering: `wt merge --no-squash main` instead of-// requiring the more restrictive `wt merge main --no-squash`.+// Mark positional args as `.last(true)` to allow them after all flags.+// This enables flexible argument ordering like:+// - `wt switch --create --execute=cmd --base=main feature` instead of `wt switch feature --create --execute=cmd --base=main`+// - `wt merge --no-squash main` instead of `wt merge main --no-squash`+// - `wt remove --no-delete-branch feature` instead of `wt remove feature --no-delete-branch`fn adjust_completion_command(cmd: Command) -> Command {- cmd.mut_subcommand("merge", |merge| {+ cmd.mut_subcommand("switch", |switch| {+ switch.mut_arg("branch", |arg| arg.last(true))+ })+ .mut_subcommand("remove", |remove| {+ remove.mut_arg("worktrees", |arg| arg.last(true))+ })+ .mut_subcommand("merge", |merge| {merge.mut_arg("target", |arg| arg.last(true))}).mut_subcommand("beta", |beta| {diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rsindex 7ae8e52ce..70f639866 100644--- a/tests/integration_tests/completion.rs+++ b/tests/integration_tests/completion.rs@@ -1068,3 +1068,108 @@ fn test_complete_merge_with_flags() {assert!(branches.iter().any(|b| b.contains("hotfix")));assert!(branches.iter().any(|b| b.contains("main")));}++#[test]+fn test_complete_switch_base_after_execute_equals() {+ let temp = TestRepo::new();+ temp.commit("initial");++ // Create branches+ Command::new("git")+ .args(["branch", "develop"])+ .current_dir(temp.root_path())+ .output()+ .unwrap();++ Command::new("git")+ .args(["branch", "production"])+ .current_dir(temp.root_path())+ .output()+ .unwrap();++ // Test: wt switch --create --execute=claude --base <cursor>+ // This is the reported failing case - should complete branches for --base+ let output = temp+ .completion_cmd(&["wt", "switch", "--create", "--execute=claude", "--base", ""])+ .output()+ .unwrap();++ assert!(output.status.success());+ let stdout = String::from_utf8_lossy(&output.stdout);+ let branches = value_suggestions(&stdout);++ // Should show all branches as potential base+ assert!(+ branches.iter().any(|b| b.contains("develop")),+ "Should complete develop branch for --base flag, got:\n{stdout}"+ );+ assert!(+ branches.iter().any(|b| b.contains("production")),+ "Should complete production branch for --base flag, got:\n{stdout}"+ );+ assert!(+ branches.iter().any(|b| b.contains("main")),+ "Should complete main branch for --base flag, got:\n{stdout}"+ );+}++#[test]+fn test_complete_switch_flexible_argument_ordering() {+ let temp = TestRepo::new();+ temp.commit("initial");++ Command::new("git")+ .args(["branch", "develop"])+ .current_dir(temp.root_path())+ .output()+ .unwrap();++ // Test that .last(true) allows positional before flags+ // wt switch feature --base <cursor>+ let output = temp+ .completion_cmd(&["wt", "switch", "feature", "--base", ""])+ .output()+ .unwrap();++ assert!(output.status.success());+ let stdout = String::from_utf8_lossy(&output.stdout);+ let branches = value_suggestions(&stdout);++ // Should complete --base value even when positional comes first+ assert!(+ branches.iter().any(|b| b.contains("develop")),+ "Should complete branches for --base even after positional arg, got:\n{stdout}"+ );+ assert!(+ branches.iter().any(|b| b.contains("main")),+ "Should complete branches for --base even after positional arg, got:\n{stdout}"+ );+}++#[test]+fn test_complete_remove_flexible_argument_ordering() {+ let mut temp = TestRepo::new();+ temp.commit("initial");++ // Create two worktrees+ temp.add_worktree("feature-worktree", "feature");+ temp.add_worktree("bugfix-worktree", "bugfix");++ // Test that .last(true) allows positional before flags+ // wt remove feature --no-delete-branch <cursor>+ // Since remove accepts multiple worktrees, should suggest more worktrees+ let output = temp+ .completion_cmd(&["wt", "remove", "feature", "--no-delete-branch", ""])+ .output()+ .unwrap();++ assert!(output.status.success());+ let stdout = String::from_utf8_lossy(&output.stdout);+ let suggestions = value_suggestions(&stdout);++ // Should suggest additional worktrees (remove accepts Vec<String>)+ assert!(+ suggestions.iter().any(|s| s.contains("bugfix")),+ "Should suggest additional worktrees after positional and flag, got:\n{stdout}"+ );+}