Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor(hook): share command-label rendering with approvals surfaces (#3397)
Maximilian Roos745f6a90df0b
diff --git a/src/commands/hook_commands.rs b/src/commands/hook_commands.rsindex 40a1942b0..6a54de4d7 100644--- a/src/commands/hook_commands.rs+++ b/src/commands/hook_commands.rs@@ -27,6 +27,7 @@ use super::command_executor::{};use super::context::CommandEnv;use super::hooks::{HookAnnouncer, prepare_and_check, run_hooks_foreground};+use super::project_config::command_label;use super::template_vars::TemplateVars;fn run_post_hook(@@ -614,11 +615,7 @@ fn render_hook_commands(}for cmd in commands {- // Build label: "hook-type name:" or "hook-type:"- let label = match &cmd.name {- Some(name) => cformat!("{hook_type} <bold>{name}</>:"),- None => format!("{hook_type}:"),- };+ let label = command_label(hook_type, cmd.name.as_deref());// Check approval status for project hookslet needs_approval = if let Some((approvals, Some(project_id))) = approval_context {diff --git a/src/commands/project_config.rs b/src/commands/project_config.rsindex 0a611b064..c43caa0e5 100644--- a/src/commands/project_config.rs+++ b/src/commands/project_config.rs@@ -48,11 +48,7 @@ impl ApprovableCommand {/// `phase name:` label shown before the command body, in the approval/// prompt and the approvals listing.pub fn label(&self) -> String {- let phase = &self.phase;- match &self.command.name {- Some(name) => cformat!("{phase} <bold>{name}</>:"),- None => format!("{phase}:"),- }+ command_label(&self.phase, self.command.name.as_deref())}/// Gutter-formatted template. Shell commands get bash syntax@@ -66,6 +62,16 @@ impl ApprovableCommand {}}+/// `phase name:` label shown before a command body. Free-standing rather+/// than a method on [`ApprovableCommand`] so `wt hook show` can label user+/// hooks, which are never approvable.+pub fn command_label(phase: impl fmt::Display, name: Option<&str>) -> String {+ match name {+ Some(name) => cformat!("{phase} <bold>{name}</>:"),+ None => format!("{phase}:"),+ }+}+/// Collect commands for the given hook types, preserving order of the provided hooks.pub fn collect_commands_for_hooks(project_config: &ProjectConfig,