Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor: Use Shell enum for init command instead of String
Maximilian Roosb5cc7dc3aef4
diff --git a/src/commands/init.rs b/src/commands/init.rsindex bc6eb4601..5bd60aa8b 100644--- a/src/commands/init.rs+++ b/src/commands/init.rs@@ -3,9 +3,11 @@ use clap_complete::{Shell as CompletionShell, generate};use worktrunk::shell;use worktrunk::styling::{ERROR, ERROR_EMOJI, println};-pub fn handle_init(shell_name: &str, cmd_name: &str, cli_cmd: &mut Command) -> Result<(), String> {- let shell = shell_name.parse::<shell::Shell>()?;-+pub fn handle_init(+ shell: shell::Shell,+ cmd_name: &str,+ cli_cmd: &mut Command,+) -> Result<(), String> {let init = shell::ShellInit::new(shell, cmd_name.to_string());// Generate shell integration codediff --git a/src/main.rs b/src/main.rsindex 0e4b729dd..a9d1db690 100644--- a/src/main.rs+++ b/src/main.rs@@ -88,8 +88,8 @@ enum DevCommand {enum Commands {/// Generate shell integration codeInit {- /// Shell to generate code for (bash, fish, zsh)- shell: String,+ /// Shell to generate code for+ shell: Shell,/// Command prefix (default: wt)#[arg(long, default_value = "wt")]@@ -333,7 +333,7 @@ fn main() {let result = match cli.command {Commands::Init { shell, cmd } => {let mut cli_cmd = Cli::command();- handle_init(&shell, &cmd, &mut cli_cmd).git_err()+ handle_init(shell, &cmd, &mut cli_cmd).git_err()}Commands::ConfigureShell { shell, cmd, yes } => {handle_configure_shell(shell, &cmd, yes)diff --git a/tests/integration_tests/init.rs b/tests/integration_tests/init.rsindex b7b2e08c3..1ad104c14 100644--- a/tests/integration_tests/init.rs+++ b/tests/integration_tests/init.rs@@ -60,11 +60,14 @@ fn test_init_invalid_shell() {assert_cmd_snapshot!(cmd, @r"success: false- exit_code: 1+ exit_code: 2----- stdout ---------- stderr ------ Unsupported shell: invalid-shell+ [1m[31merror:[0m invalid value '[33minvalid-shell[0m' for '[1m<SHELL>[0m'+ [possible values: [32mbash[0m, [32melvish[0m, [32mfish[0m, [32mnushell[0m, [32moil[0m, [32mpowershell[0m, [32mxonsh[0m, [32mzsh[0m]++ For more information, try '[1m--help[0m'.");});}diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex 6e5f02774..2bef8bfca 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpYBjef2/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpSZbFNE/test-config.toml---success: trueexit_code: 0@@ -340,7 +340,7 @@ _wt() {return 0;;wt__init)- opts="-v -h --cmd --verbose --help <SHELL>"+ opts="-v -h --cmd --verbose --help bash elvish fish nushell oil powershell xonsh zsh"if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; thenCOMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )return 0diff --git a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snapindex 09510696e..3fd165387 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@@ -18,7 +18,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpCXsTxF/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpEXV3PM/test-config.toml---success: trueexit_code: 0@@ -342,7 +342,7 @@ _wt() {return 0;;wt__init)- opts="-v -h --cmd --verbose --help <SHELL>"+ opts="-v -h --cmd --verbose --help bash elvish fish nushell oil powershell xonsh zsh"if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; thenCOMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )return 0diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snapindex dcea75cfb..fecf23f2b 100644--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpNVNuYN/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp84YMkU/test-config.toml---success: trueexit_code: 0@@ -167,7 +167,7 @@ if type -q wtend# Register dynamic completions- complete -c wt -n '__fish_seen_subcommand_from init' -f -a '(__wt_complete)' -d 'Shell to generate code for (bash, fish, zsh)'+ complete -c wt -n '__fish_seen_subcommand_from init' -f -a '(__wt_complete)' -d 'Shell to generate code for'complete -c wt -n '__fish_seen_subcommand_from switch' -f -a '(__wt_complete)' -d 'Branch name or worktree path'complete -c wt -n '__fish_seen_subcommand_from remove' -f -a '(__wt_complete)' -d 'Worktree names or branches to remove (defaults to current worktree if none specified)'complete -c wt -n '__fish_seen_subcommand_from push' -f -a '(__wt_complete)' -d 'Target branch (defaults to default branch)'diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex f4eaf4aae..b4d3e835b 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -16,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpNfo5re/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpohHD45/test-config.toml---success: trueexit_code: 0@@ -159,7 +159,7 @@ _arguments "${_arguments_options[@]}" : \'--verbose[Enable verbose output (show git commands and debug info)]' \'-h[Print help]' \'--help[Print help]' \-':shell -- Shell to generate code for (bash, fish, zsh):_default' \+':shell -- Shell to generate code for:(bash elvish fish nushell oil powershell xonsh zsh)' \&& ret=0;;(configure-shell)