Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: add --dry-run flag to shell install/uninstall commands (#543)
Maximilian Roosa07e4a3aff89
diff --git a/src/cli/config.rs b/src/cli/config.rsindex b73faccff..6f6424a29 100644--- a/src/cli/config.rs+++ b/src/cli/config.rs@@ -69,6 +69,10 @@ Use --yes to skip confirmation."##[arg(short, long)]yes: bool,+ /// Show what would be changed+ #[arg(long)]+ dry_run: bool,+/// Command name for shell integration (defaults to binary name)////// Use this to create shell integration for an alternate command name.@@ -113,6 +117,10 @@ Detects various forms of the integration pattern regardless of:/// Skip confirmation prompt#[arg(short, long)]yes: bool,++ /// Show what would be changed+ #[arg(long)]+ dry_run: bool,},/// Show output theme samplesdiff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rsindex 743fa8998..1dae2e96c 100644--- a/src/commands/configure_shell.rs+++ b/src/commands/configure_shell.rs@@ -107,6 +107,7 @@ impl ConfigAction {pub fn handle_configure_shell(shell_filter: Option<Shell>,skip_confirmation: bool,+ dry_run: bool,cmd: String,) -> Result<ScanResult, String> {// First, do a dry-run to see what would be changed@@ -145,6 +146,17 @@ pub fn handle_configure_shell(});}+ // For --dry-run, show preview and return without prompting or applying+ if dry_run {+ show_install_preview(&preview.configured, &completion_preview, &cmd);+ return Ok(ScanResult {+ configured: preview.configured,+ completion_results: completion_preview,+ skipped: preview.skipped,+ zsh_needs_compinit: false,+ });+ }+// Show what will be done and ask for confirmation (unless --yes flag is used)if !skip_confirmation&& !prompt_for_install(@@ -545,6 +557,50 @@ pub fn show_install_preview(}}+/// Display what will be uninstalled (shell extensions and completions)+///+/// Shows the files that will be modified without prompting.+/// Used for --dry-run mode.+///+/// Note: I/O errors are intentionally ignored - preview is best-effort+/// and shouldn't block the flow.+pub fn show_uninstall_preview(+ results: &[UninstallResult],+ completion_results: &[CompletionUninstallResult],+) {+ use anstyle::Style;++ let bold = Style::new().bold();++ for result in results {+ let shell = result.shell;+ let path = format_path_for_display(&result.path);+ // Bash/Zsh: inline completions; Fish: separate completion file+ let what = if matches!(shell, Shell::Fish) {+ "shell extension"+ } else {+ "shell extension & completions"+ };++ let _ = output::print(format!(+ "{} {} {what} for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",+ result.action.symbol(),+ result.action.description(),+ ));+ }++ for result in completion_results {+ let shell = result.shell;+ let path = format_path_for_display(&result.path);++ let _ = output::print(format!(+ "{} {} completions for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",+ result.action.symbol(),+ result.action.description(),+ ));+ }+}+/// Prompt for install with [y/N/?] options////// - `y` or `yes`: Accept and return true@@ -697,6 +753,7 @@ pub fn process_shell_completions(pub fn handle_unconfigure_shell(shell_filter: Option<Shell>,skip_confirmation: bool,+ dry_run: bool,cmd: &str,) -> Result<UninstallScanResult, String> {// First, do a dry-run to see what would be changed@@ -707,6 +764,12 @@ pub fn handle_unconfigure_shell(return Ok(preview);}+ // For --dry-run, show preview and return without prompting or applying+ if dry_run {+ show_uninstall_preview(&preview.results, &preview.completion_results);+ return Ok(preview);+ }+// Show what will be done and ask for confirmation (unless --yes flag is used)if !skip_confirmation&& !prompt_for_uninstall_confirmation(&preview.results, &preview.completion_results)?diff --git a/src/main.rs b/src/main.rsindex 44b65a5a1..526f8fded 100644--- a/src/main.rs+++ b/src/main.rs@@ -849,10 +849,15 @@ fn main() {let cmd = cmd.unwrap_or_else(binary_name);handle_init(shell, cmd).map_err(|e| anyhow::anyhow!("{}", e))}- ConfigShellCommand::Install { shell, yes, cmd } => {+ ConfigShellCommand::Install {+ shell,+ yes,+ dry_run,+ cmd,+ } => {// Auto-write to shell config files and completionslet cmd = cmd.unwrap_or_else(binary_name);- handle_configure_shell(shell, yes, cmd)+ handle_configure_shell(shell, yes, dry_run, cmd).map_err(|e| anyhow::anyhow!("{}", e)).and_then(|scan_result| {// Exit with error if no shells configured@@ -864,14 +869,27 @@ fn main() {}.into());}+ // For --dry-run, preview was already shown by handler+ if dry_run {+ return Ok(());+ }crate::output::print_shell_install_result(&scan_result)})}- ConfigShellCommand::Uninstall { shell, yes } => {+ ConfigShellCommand::Uninstall {+ shell,+ yes,+ dry_run,+ } => {let explicit_shell = shell.is_some();- handle_unconfigure_shell(shell, yes, &binary_name())+ handle_unconfigure_shell(shell, yes, dry_run, &binary_name()).map_err(|e| anyhow::anyhow!("{}", e)).and_then(|scan_result| {+ // For --dry-run, preview was already shown by handler+ if dry_run {+ return Ok(());+ }+let shell_count = scan_result.results.len();let completion_count = scan_result.completion_results.len();let total_changes = shell_count + completion_count;diff --git a/src/output/shell_integration.rs b/src/output/shell_integration.rsindex 70ace7f25..0f0acdec5 100644--- a/src/output/shell_integration.rs+++ b/src/output/shell_integration.rs@@ -387,7 +387,7 @@ pub fn prompt_shell_integration(}// Install for all shells with config files (same as `wt config shell install`)- let install_result = handle_configure_shell(None, true, binary_name.to_string())+ let install_result = handle_configure_shell(None, true, false, binary_name.to_string()).map_err(|e| anyhow::anyhow!("Failed to configure shell integration: {e}"))?;print_shell_install_result(&install_result)?;