Skip to content

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

Remove deprecated `completion` command

Maximilian Roosa7099a282d7b
diff --git a/src/main.rs b/src/main.rs
index 0d54f76c9..53a6d25d3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,7 @@
use anstyle::{AnsiColor, Color, Style};
-use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
+use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::{Shell as CompletionShell, generate};
use rayon::prelude::*;
-use std::io;
use std::process;
use worktrunk::config::{format_worktree_path, load_config};
use worktrunk::error_format::{format_error, format_error_with_bold, format_hint, format_warning};
@@ -96,14 +95,6 @@ enum Commands {
hook_type: String,
},
- /// Generate shell completion script (deprecated - use init instead)
- #[command(hide = true)]
- Completion {
- /// Shell to generate completions for
- #[arg(value_enum)]
- shell: Shell,
- },
-
/// Internal completion helper (hidden)
#[command(hide = true)]
Complete {
@@ -113,13 +104,6 @@ enum Commands {
},
}
-#[derive(ValueEnum, Clone, Copy)]
-enum Shell {
- Bash,
- Fish,
- Zsh,
-}
-
fn main() {
let cli = Cli::parse();
@@ -151,10 +135,6 @@ fn main() {
} => handle_push(target.as_deref(), allow_merge_commits),
Commands::Merge { target, keep } => handle_merge(target.as_deref(), keep),
Commands::Hook { hook_type } => handle_hook(&hook_type).map_err(GitError::CommandFailed),
- Commands::Completion { shell } => {
- handle_completion(shell);
- Ok(())
- }
Commands::Complete { args } => handle_complete(args),
};
@@ -904,16 +884,6 @@ fn handle_hook(hook_type: &str) -> Result<(), String> {
}
}
-fn handle_completion(shell: Shell) {
- let mut cmd = Cli::command();
- let completion_shell = match shell {
- Shell::Bash => CompletionShell::Bash,
- Shell::Fish => CompletionShell::Fish,
- Shell::Zsh => CompletionShell::Zsh,
- };
- generate(completion_shell, &mut cmd, "wt", &mut io::stdout());
-}
-
#[derive(Debug, PartialEq)]
enum CompletionContext {
SwitchBranch,
@@ -933,19 +903,18 @@ fn parse_completion_context(args: &[String]) -> CompletionContext {
let subcommand = &args[1];
- match subcommand.as_str() {
- "switch" => {
- // Check if we're completing --base flag value
- if args.len() >= 3 {
- for arg in args.iter().skip(2).take(args.len() - 3) {
- if arg == "--base" || arg == "-b" {
- // We're completing the value after --base
- return CompletionContext::BaseFlag;
- }
- }
- }
- CompletionContext::SwitchBranch
+ // Check if the previous argument was a flag that expects a value
+ // If so, we're completing that flag's value
+ if args.len() >= 3 {
+ let prev_arg = &args[args.len() - 2];
+ if prev_arg == "--base" || prev_arg == "-b" {
+ return CompletionContext::BaseFlag;
}
+ }
+
+ // Otherwise, complete based on the subcommand's positional argument
+ match subcommand.as_str() {
+ "switch" => CompletionContext::SwitchBranch,
"push" => CompletionContext::PushTarget,
"merge" => CompletionContext::MergeTarget,
_ => CompletionContext::Unknown,
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index 9f6e26c47..c332f9369 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -2,38 +2,6 @@ use crate::common::TestRepo;
use assert_cmd::Command;
use std::process::Command as StdCommand;
-#[test]
-fn test_completion_command_static() {
- // Test that static completion generates valid Fish script
- let mut cmd = Command::cargo_bin("wt").unwrap();
- let output = cmd.arg("completion").arg("fish").output().unwrap();
-
- assert!(output.status.success());
- let stdout = String::from_utf8_lossy(&output.stdout);
-
- // Check for expected Fish completion functions
- assert!(stdout.contains("__fish_wt_needs_command"));
- assert!(stdout.contains("complete -c wt"));
- assert!(stdout.contains("switch"));
- assert!(stdout.contains("remove"));
- assert!(stdout.contains("push"));
- assert!(stdout.contains("merge"));
-}
-
-#[test]
-fn test_completion_command_bash() {
- let mut cmd = Command::cargo_bin("wt").unwrap();
- let output = cmd.arg("completion").arg("bash").output().unwrap();
-
- assert!(output.status.success());
- let stdout = String::from_utf8_lossy(&output.stdout);
-
- // Check for Bash completion structure
- assert!(stdout.contains("_wt()"));
- assert!(stdout.contains("COMPREPLY"));
- assert!(stdout.contains("complete"));
-}
-
#[test]
fn test_complete_switch_shows_branches() {
let temp = TestRepo::new();
@@ -208,19 +176,6 @@ fn test_init_fish_includes_no_file_flag() {
assert!(stdout.contains("-f -a '(__wt_complete)'"));
}
-#[test]
-fn test_completion_command_zsh() {
- let mut cmd = Command::cargo_bin("wt").unwrap();
- let output = cmd.arg("completion").arg("zsh").output().unwrap();
-
- assert!(output.status.success());
- let stdout = String::from_utf8_lossy(&output.stdout);
-
- // Check for Zsh completion structure
- assert!(stdout.contains("_wt"));
- assert!(stdout.contains("compdef"));
-}
-
#[test]
fn test_complete_base_flag_short_form() {
let temp = TestRepo::new();
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snap
index c9ac9fa96..4f4b75c4b 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap
@@ -6,6 +6,7 @@ info:
- init
- bash
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -93,9 +94,6 @@ _wt() {
wt,complete)
cmd="wt__complete"
;;
- wt,completion)
- cmd="wt__completion"
- ;;
wt,hook)
cmd="wt__hook"
;;
@@ -124,7 +122,7 @@ _wt() {
case "${cmd}" in
wt)
- opts="-h -V --help --version init list switch remove push merge hook completion complete"
+ opts="-h -V --help --version init list switch remove push merge hook complete"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -151,20 +149,6 @@ _wt() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
- wt__completion)
- opts="-h --help bash fish zsh"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
wt__hook)
opts="-h --help <HOOK_TYPE>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash_all_options.snap b/tests/snapshots/integration__integration_tests__init__init_bash_all_options.snap
index ef58bc592..195458040 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash_all_options.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash_all_options.snap
@@ -10,6 +10,7 @@ info:
- "--hook"
- prompt
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -110,9 +111,6 @@ _wt() {
wt,complete)
cmd="wt__complete"
;;
- wt,completion)
- cmd="wt__completion"
- ;;
wt,hook)
cmd="wt__hook"
;;
@@ -141,7 +139,7 @@ _wt() {
case "${cmd}" in
wt)
- opts="-h -V --help --version init list switch remove push merge hook completion complete"
+ opts="-h -V --help --version init list switch remove push merge hook complete"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -168,20 +166,6 @@ _wt() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
- wt__completion)
- opts="-h --help bash fish zsh"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
wt__hook)
opts="-h --help <HOOK_TYPE>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap
index 58f89f3fb..bd22d33bd 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap
@@ -8,6 +8,7 @@ info:
- "--cmd"
- wt
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -95,9 +96,6 @@ _wt() {
wt,complete)
cmd="wt__complete"
;;
- wt,completion)
- cmd="wt__completion"
- ;;
wt,hook)
cmd="wt__hook"
;;
@@ -126,7 +124,7 @@ _wt() {
case "${cmd}" in
wt)
- opts="-h -V --help --version init list switch remove push merge hook completion complete"
+ opts="-h -V --help --version init list switch remove push merge hook complete"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -153,20 +151,6 @@ _wt() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
- wt__completion)
- opts="-h --help bash fish zsh"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
wt__hook)
opts="-h --help <HOOK_TYPE>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash_prompt_hook.snap b/tests/snapshots/integration__integration_tests__init__init_bash_prompt_hook.snap
index 440317f7b..8efcd6453 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash_prompt_hook.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash_prompt_hook.snap
@@ -8,6 +8,7 @@ info:
- "--hook"
- prompt
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -108,9 +109,6 @@ _wt() {
wt,complete)
cmd="wt__complete"
;;
- wt,completion)
- cmd="wt__completion"
- ;;
wt,hook)
cmd="wt__hook"
;;
@@ -139,7 +137,7 @@ _wt() {
case "${cmd}" in
wt)
- opts="-h -V --help --version init list switch remove push merge hook completion complete"
+ opts="-h -V --help --version init list switch remove push merge hook complete"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
@@ -166,20 +164,6 @@ _wt() {
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
- wt__completion)
- opts="-h --help bash fish zsh"
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- fi
- case "${prev}" in
- *)
- COMPREPLY=()
- ;;
- esac
- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
- return 0
- ;;
wt__hook)
opts="-h --help <HOOK_TYPE>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snap
index 63ba0e1ba..cc98f1099 100644
--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap
@@ -6,6 +6,7 @@ info:
- init
- fish
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -118,7 +119,6 @@ complete -c wt -n "__fish_wt_using_subcommand push" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand merge" -s k -l keep -d 'Keep worktree after merging (don\'t remove)'
complete -c wt -n "__fish_wt_using_subcommand merge" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand hook" -s h -l help -d 'Print help'
-complete -c wt -n "__fish_wt_using_subcommand completion" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand complete" -s h -l help -d 'Print help'
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__init__init_fish_prompt_hook.snap b/tests/snapshots/integration__integration_tests__init__init_fish_prompt_hook.snap
index adf878a8c..2bda04329 100644
--- a/tests/snapshots/integration__integration_tests__init__init_fish_prompt_hook.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_fish_prompt_hook.snap
@@ -8,6 +8,7 @@ info:
- "--hook"
- prompt
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -126,7 +127,6 @@ complete -c wt -n "__fish_wt_using_subcommand push" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand merge" -s k -l keep -d 'Keep worktree after merging (don\'t remove)'
complete -c wt -n "__fish_wt_using_subcommand merge" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand hook" -s h -l help -d 'Print help'
-complete -c wt -n "__fish_wt_using_subcommand completion" -s h -l help -d 'Print help'
complete -c wt -n "__fish_wt_using_subcommand complete" -s h -l help -d 'Print help'
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
index 315525412..17f43988e 100644
--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
@@ -6,6 +6,7 @@ info:
- init
- zsh
env:
+ CLICOLOR_FORCE: "1"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
@@ -160,13 +161,6 @@ _arguments "${_arguments_options[@]}" : \
':hook_type -- Hook type:_default' \
&& ret=0
;;
-(completion)
-_arguments "${_arguments_options[@]}" : \
-'-h[Print help]' \
-'--help[Print help]' \
-':shell -- Shell to generate completions for:(bash fish zsh)' \
-&& ret=0
-;;
(complete)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
@@ -189,7 +183,6 @@ _wt_commands() {
'push:Push changes between worktrees' \
'merge:Merge worktree into target branch' \
'hook:Hook commands (for shell integration)' \
-'completion:Generate shell completion script (deprecated - use init instead)' \
'complete:Internal completion helper (hidden)' \
)
_describe -t commands 'wt commands' commands "$@"
@@ -199,11 +192,6 @@ _wt__complete_commands() {
local commands; commands=()
_describe -t commands 'wt complete commands' commands "$@"
}
-(( $+functions[_wt__completion_commands] )) ||
-_wt__completion_commands() {
- local commands; commands=()
- _describe -t commands 'wt completion commands' commands "$@"
-}
(( $+functions[_wt__hook_commands] )) ||
_wt__hook_commands() {
local commands; commands=()