From f1af14b1cc503ac20f56a79a96c7780d02bdfe75 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 24 Jun 2026 03:56:26 +0900 Subject: fix(console): make Command/BaseCommand methods take &self The Command trait and Composer's BaseCommand took &mut self, so dispatch held a borrow_mut on the command's RefCell for the whole call. A command re-entering itself (e.g. the help command describing itself) then panicked with "RefCell already borrowed". All Command/BaseCommand methods now take &self and the command state is interior-mutable (Cell/RefCell). Shared borrows coexist, so re-entrant describe paths no longer conflict. Getters that returned references now return Ref guards; the descriptor describe_* methods take &dyn Command; mixin accessors return Ref/RefMut. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../shirabe/src/command/base_dependency_command.rs | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'crates/shirabe/src/command/base_dependency_command.rs') diff --git a/crates/shirabe/src/command/base_dependency_command.rs b/crates/shirabe/src/command/base_dependency_command.rs index 6a892e8..7bedf7d 100644 --- a/crates/shirabe/src/command/base_dependency_command.rs +++ b/crates/shirabe/src/command/base_dependency_command.rs @@ -37,11 +37,11 @@ pub trait BaseDependencyCommand: BaseCommand { const OPTION_RECURSIVE: &'static str = OPTION_RECURSIVE; const OPTION_TREE: &'static str = OPTION_TREE; - fn colors(&self) -> &[String]; - fn colors_mut(&mut self) -> &mut Vec; + fn colors(&self) -> std::cell::Ref<'_, Vec>; + fn set_colors(&self, colors: Vec); fn do_execute( - &mut self, + &self, input: std::rc::Rc>, output: std::rc::Rc>, inverted: bool, @@ -383,15 +383,15 @@ pub trait BaseDependencyCommand: BaseCommand { self.render_table(table_as_mixed, output); } - fn init_styles(&mut self, output: std::rc::Rc>) { - *self.colors_mut() = vec![ + fn init_styles(&self, output: std::rc::Rc>) { + self.set_colors(vec![ "green".to_string(), "yellow".to_string(), "cyan".to_string(), "magenta".to_string(), "blue".to_string(), - ]; - for color in self.colors() { + ]); + for color in self.colors().iter() { let style = OutputFormatterStyle::new(Some(color), None, vec![]); output .borrow() @@ -401,14 +401,15 @@ pub trait BaseDependencyCommand: BaseCommand { } } - fn print_tree(&mut self, results: &[DependentsEntry], prefix: &str, level: i64) { + fn print_tree(&self, results: &[DependentsEntry], prefix: &str, level: i64) { let count = results.len() as i64; let mut idx: i64 = 0; - let colors_len = self.colors().len() as i64; + let colors = self.colors(); + let colors_len = colors.len() as i64; for result in results { let DependentsEntry(package, link, children) = result; - let color = &self.colors()[(level % colors_len) as usize]; - let prev_color = &self.colors()[((level - 1) % colors_len) as usize]; + let color = &colors[(level % colors_len) as usize]; + let prev_color = &colors[((level - 1) % colors_len) as usize]; idx += 1; let is_last = idx == count; let version_text = @@ -464,7 +465,7 @@ pub trait BaseDependencyCommand: BaseCommand { } } - fn write_tree_line(&mut self, line: &str) { + fn write_tree_line(&self, line: &str) { let io = self.get_io(); let line = if !io.is_decorated() { line.replace('└', "`-") -- cgit v1.3.1