Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor to remove unused display variants
Maximilian Roos3a7abc2c70ab
diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rsindex a975058bc..5b987d078 100644--- a/src/commands/configure_shell.rs+++ b/src/commands/configure_shell.rs@@ -299,21 +299,18 @@ fn configure_shell_file(explicit_shell: bool,cmd: &str,) -> Result<Option<ConfigureResult>, String> {- // Get a summary of the shell integration for display- let integration_summary = shell.integration_summary_with_prefix(cmd);-- // The actual line we write to the config file- let config_content = shell.config_line_with_prefix(cmd);+ // The line we write to the config file (also used for display)+ let config_line = shell.config_line_with_prefix(cmd);// For Fish, we write to a separate conf.d/ fileif matches!(shell, Shell::Fish) {return configure_fish_file(shell,path,- &config_content,+ &config_line,dry_run,explicit_shell,- &integration_summary,+ &config_line,);}@@ -336,12 +333,12 @@ fn configure_shell_file(})?;// Canonical detection: check if the line matches exactly what we write- if line.trim() == config_content {+ if line.trim() == config_line {return Ok(Some(ConfigureResult {shell,path: path.to_path_buf(),action: ConfigAction::AlreadyExists,- config_line: integration_summary.clone(),+ config_line: config_line.clone(),}));}}@@ -352,7 +349,7 @@ fn configure_shell_file(shell,path: path.to_path_buf(),action: ConfigAction::WouldAdd,- config_line: integration_summary.clone(),+ config_line: config_line.clone(),}));}@@ -366,7 +363,7 @@ fn configure_shell_file(})?;// Add blank line before config, then the config line with its own newline- write!(file, "\n{}\n", config_content).map_err(|e| {+ write!(file, "\n{}\n", config_line).map_err(|e| {format!("Failed to write to {}: {}",format_path_for_display(path),@@ -378,7 +375,7 @@ fn configure_shell_file(shell,path: path.to_path_buf(),action: ConfigAction::Added,- config_line: integration_summary.clone(),+ config_line: config_line.clone(),}))} else {// File doesn't exist@@ -389,7 +386,7 @@ fn configure_shell_file(shell,path: path.to_path_buf(),action: ConfigAction::WouldCreate,- config_line: integration_summary.clone(),+ config_line: config_line.clone(),}));}@@ -401,7 +398,7 @@ fn configure_shell_file(}// Write the config content- fs::write(path, format!("{}\n", config_content)).map_err(|e| {+ fs::write(path, format!("{}\n", config_line)).map_err(|e| {format!("Failed to write to {}: {}",format_path_for_display(path),@@ -413,7 +410,7 @@ fn configure_shell_file(shell,path: path.to_path_buf(),action: ConfigAction::Created,- config_line: integration_summary.clone(),+ config_line: config_line.clone(),}))} else {// Don't create config files for shells the user might not use@@ -428,7 +425,7 @@ fn configure_fish_file(content: &str,dry_run: bool,explicit_shell: bool,- integration_summary: &str,+ config_line: &str,) -> Result<Option<ConfigureResult>, String> {// For Fish, we write to conf.d/{cmd}.fish (separate file)@@ -443,7 +440,7 @@ fn configure_fish_file(shell,path: path.to_path_buf(),action: ConfigAction::AlreadyExists,- config_line: integration_summary.to_string(),+ config_line: config_line.to_string(),}));}}@@ -468,7 +465,7 @@ fn configure_fish_file(} else {ConfigAction::WouldCreate},- config_line: integration_summary.to_string(),+ config_line: config_line.to_string(),}));}@@ -491,7 +488,7 @@ fn configure_fish_file(shell,path: path.to_path_buf(),action: ConfigAction::Created,- config_line: integration_summary.to_string(),+ config_line: config_line.to_string(),}))}diff --git a/src/display.rs b/src/display.rsindex 1c0dd0893..20c8a4991 100644--- a/src/display.rs+++ b/src/display.rs@@ -13,10 +13,10 @@ use worktrunk::utils::get_now;/// Format timestamp as abbreviated relative time (e.g., "2h")pub fn format_relative_time_short(timestamp: i64) -> String {// Cast to i64 for signed arithmetic (handles future timestamps)- format_relative_time_impl(timestamp, get_now() as i64, true)+ format_relative_time_impl(timestamp, get_now() as i64)}-fn format_relative_time_impl(timestamp: i64, now: i64, short: bool) -> String {+fn format_relative_time_impl(timestamp: i64, now: i64) -> String {const MINUTE: i64 = 60;const HOUR: i64 = MINUTE * 60;const DAY: i64 = HOUR * 24;@@ -27,35 +27,30 @@ fn format_relative_time_impl(timestamp: i64, now: i64, short: bool) -> String {let seconds_ago = now - timestamp;if seconds_ago < 0 {- return if short { "future" } else { "in the future" }.to_string();+ return "future".to_string();}if seconds_ago < MINUTE {- return if short { "now" } else { "just now" }.to_string();+ return "now".to_string();}- const UNITS: &[(i64, &str, &str)] = &[- (YEAR, "year", "y"),- (MONTH, "month", "mo"),- (WEEK, "week", "w"),- (DAY, "day", "d"),- (HOUR, "hour", "h"),- (MINUTE, "minute", "m"),+ const UNITS: &[(i64, &str)] = &[+ (YEAR, "y"),+ (MONTH, "mo"),+ (WEEK, "w"),+ (DAY, "d"),+ (HOUR, "h"),+ (MINUTE, "m"),];- for &(unit_seconds, label, abbrev) in UNITS {+ for &(unit_seconds, abbrev) in UNITS {let value = seconds_ago / unit_seconds;if value > 0 {- return if short {- format!("{}{}", value, abbrev)- } else {- let plural = if value == 1 { "" } else { "s" };- format!("{} {}{} ago", value, label, plural)- };+ return format!("{}{}", value, abbrev);}}- if short { "now" } else { "just now" }.to_string()+ "now".to_string()}/// Shorten a path relative to the main worktree.@@ -208,60 +203,33 @@ mod tests {let now: i64 = 1700000000; // Fixed timestamp for testing// Just now (< 1 minute)- assert_eq!(format_relative_time_impl(now - 30, now, true), "now");- assert_eq!(format_relative_time_impl(now - 59, now, true), "now");+ assert_eq!(format_relative_time_impl(now - 30, now), "now");+ assert_eq!(format_relative_time_impl(now - 59, now), "now");// Minutes- assert_eq!(format_relative_time_impl(now - 60, now, true), "1m");- assert_eq!(format_relative_time_impl(now - 120, now, true), "2m");- assert_eq!(format_relative_time_impl(now - 3599, now, true), "59m");+ assert_eq!(format_relative_time_impl(now - 60, now), "1m");+ assert_eq!(format_relative_time_impl(now - 120, now), "2m");+ assert_eq!(format_relative_time_impl(now - 3599, now), "59m");// Hours- assert_eq!(format_relative_time_impl(now - 3600, now, true), "1h");- assert_eq!(format_relative_time_impl(now - 7200, now, true), "2h");+ assert_eq!(format_relative_time_impl(now - 3600, now), "1h");+ assert_eq!(format_relative_time_impl(now - 7200, now), "2h");// Days- assert_eq!(format_relative_time_impl(now - 86400, now, true), "1d");- assert_eq!(format_relative_time_impl(now - 172800, now, true), "2d");+ assert_eq!(format_relative_time_impl(now - 86400, now), "1d");+ assert_eq!(format_relative_time_impl(now - 172800, now), "2d");// Weeks- assert_eq!(format_relative_time_impl(now - 604800, now, true), "1w");+ assert_eq!(format_relative_time_impl(now - 604800, now), "1w");// Months- assert_eq!(format_relative_time_impl(now - 2592000, now, true), "1mo");+ assert_eq!(format_relative_time_impl(now - 2592000, now), "1mo");// Years- assert_eq!(format_relative_time_impl(now - 31536000, now, true), "1y");+ assert_eq!(format_relative_time_impl(now - 31536000, now), "1y");// Future timestamp- assert_eq!(format_relative_time_impl(now + 1000, now, true), "future");- }-- #[test]- fn test_format_relative_time_long() {- let now: i64 = 1700000000;-- assert_eq!(format_relative_time_impl(now - 30, now, false), "just now");- assert_eq!(- format_relative_time_impl(now - 60, now, false),- "1 minute ago"- );- assert_eq!(- format_relative_time_impl(now - 120, now, false),- "2 minutes ago"- );- assert_eq!(- format_relative_time_impl(now - 3600, now, false),- "1 hour ago"- );- assert_eq!(- format_relative_time_impl(now - 86400, now, false),- "1 day ago"- );- assert_eq!(- format_relative_time_impl(now + 1000, now, false),- "in the future"- );+ assert_eq!(format_relative_time_impl(now + 1000, now), "future");}#[test]diff --git a/src/git/error.rs b/src/git/error.rsindex 9a03f847e..b4be990bf 100644--- a/src/git/error.rs+++ b/src/git/error.rs@@ -574,12 +574,6 @@ pub fn exit_code(err: &anyhow::Error) -> Option<i32> {})}-/// Check if error is CommandNotApproved (silent error)-pub fn is_command_not_approved(err: &anyhow::Error) -> bool {- err.downcast_ref::<WorktrunkError>()- .is_some_and(|e| matches!(e, WorktrunkError::CommandNotApproved))-}-/// If the error is a HookCommandFailed, wrap it to add a hint about using --no-verify.////// ## When to use@@ -776,32 +770,6 @@ mod tests {assert_eq!(exit_code(&add_hook_skip_hint(inner)), Some(7));}- #[test]- fn test_is_command_not_approved() {- assert!(is_command_not_approved(- &WorktrunkError::CommandNotApproved.into()- ));- assert!(!is_command_not_approved(- &WorktrunkError::ChildProcessExited {- code: 1,- message: "test".into()- }- .into()- ));- assert!(!is_command_not_approved(- &WorktrunkError::HookCommandFailed {- hook_type: HookType::PostCreate,- command_name: None,- error: "failed".into(),- exit_code: None,- }- .into()- ));- assert!(!is_command_not_approved(- &GitError::DetachedHead { action: None }.into()- ));- }-#[test]fn test_add_hook_skip_hint() {// Wraps HookCommandFailed with --no-verify hintdiff --git a/src/git/mod.rs b/src/git/mod.rsindex 5ed71894b..1102a89dc 100644--- a/src/git/mod.rs+++ b/src/git/mod.rs@@ -39,7 +39,6 @@ pub use error::{// Error inspection functionsadd_hook_skip_hint,exit_code,- is_command_not_approved,};pub use repository::{Repository, ResolvedWorktree, set_base_path};pub use url::GitRemoteUrl;diff --git a/src/main.rs b/src/main.rsindex cd1f95a63..ab6205d32 100644--- a/src/main.rs+++ b/src/main.rs@@ -161,8 +161,8 @@ fn maybe_handle_help_with_pager() -> bool {////// Returns the usage/options/subcommands section without the after_long_help content./// If `width` is provided, wraps text at that width (for web docs); otherwise uses default.-/// If `with_colors` is true, preserves ANSI color codes for HTML conversion.-fn get_help_reference(command_path: &[&str], width: Option<usize>, with_colors: bool) -> String {+/// Always preserves ANSI color codes for HTML conversion.+fn get_help_reference(command_path: &[&str], width: Option<usize>) -> String {use clap::ColorChoice;use clap::error::ErrorKind;@@ -172,11 +172,7 @@ fn get_help_reference(command_path: &[&str], width: Option<usize>, with_colors:args.push("--help".to_string());let mut cmd = cli::build_command();- cmd = cmd.color(if with_colors {- ColorChoice::Always- } else {- ColorChoice::Never- });+ cmd = cmd.color(ColorChoice::Always);if let Some(w) = width {cmd = cmd.term_width(w);}@@ -187,12 +183,7 @@ fn get_help_reference(command_path: &[&str], width: Option<usize>, with_colors:ErrorKind::DisplayHelp | ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand) {let rendered = err.render();- // .ansi() returns ANSI-styled output, .to_string() strips colors- let text = if with_colors {- rendered.ansi().to_string()- } else {- rendered.to_string()- };+ let text = rendered.ansi().to_string();text.replace("```text\n", "```\n").replace("```console\n", "```bash\n")} else {@@ -346,7 +337,7 @@ fn handle_help_page(args: &[String]) {};// Get the help reference block (wrap at 80 chars for web docs, with colors for HTML)- let reference_block = get_help_reference(&[subcommand], Some(80), true);+ let reference_block = get_help_reference(&[subcommand], Some(80));// Output the generated content (frontmatter is in skeleton files)// Uses region markers so sync can replace just this content@@ -515,7 +506,7 @@ fn format_subcommand_section(.collect();// Get help reference (wrap at 80 chars for web docs, with colors for HTML)- let reference_block = get_help_reference(&command_path, Some(80), true);+ let reference_block = get_help_reference(&command_path, Some(80));// Format the section: heading, main content, command reference, then nested subdocslet mut section = format!("## {}\n\n", full_command);diff --git a/src/shell.rs b/src/shell.rsindex f14fc16a0..f05f73ab7 100644--- a/src/shell.rs+++ b/src/shell.rs@@ -287,18 +287,6 @@ impl Shell {Ok(None)}-- /// Returns a summary of what the shell integration does for display in confirmation- ///- /// This just returns the same as config_line since we want to show the exact wrapper- pub fn integration_summary(&self) -> String {- self.config_line()- }-- /// Returns a summary with custom prefix for display in confirmation- pub fn integration_summary_with_prefix(&self, cmd: &str) -> String {- self.config_line_with_prefix(cmd)- }}/// Shell integration configuration