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) --- .../src/symfony/console/command/help_command.rs | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony/console/command/help_command.rs') diff --git a/crates/shirabe-external-packages/src/symfony/console/command/help_command.rs b/crates/shirabe-external-packages/src/symfony/console/command/help_command.rs index 2346258..8ef488f 100644 --- a/crates/shirabe-external-packages/src/symfony/console/command/help_command.rs +++ b/crates/shirabe-external-packages/src/symfony/console/command/help_command.rs @@ -22,7 +22,7 @@ use std::rc::Rc; #[derive(Debug)] pub struct HelpCommand { inner: CommandData, - command: Option>>, + command: RefCell>>>, } impl Deref for HelpCommand { @@ -47,9 +47,9 @@ impl Default for HelpCommand { impl HelpCommand { pub fn new() -> Self { - let mut command = HelpCommand { + let command = HelpCommand { inner: CommandData::new(None), - command: None, + command: RefCell::new(None), }; command .configure() @@ -57,8 +57,8 @@ impl HelpCommand { command } - pub fn set_command(&mut self, command: Rc>) { - self.command = Some(command); + pub fn set_command(&self, command: Rc>) { + *self.command.borrow_mut() = Some(command); } pub fn complete_impl(&self, input: &CompletionInput, suggestions: &mut CompletionSuggestions) { @@ -91,7 +91,7 @@ impl HelpCommand { } impl Command for HelpCommand { - fn configure(&mut self) -> anyhow::Result<()> { + fn configure(&self) -> anyhow::Result<()> { self.inner.ignore_validation_errors(); self.inner.set_name("help")?; @@ -134,24 +134,25 @@ impl Command for HelpCommand { } fn execute( - &mut self, + &self, input: Rc>, output: Rc>, ) -> anyhow::Result { - if self.command.is_none() { + if self.command.borrow().is_none() { let application = self.get_application().unwrap(); let command_name = input.borrow().get_argument("command_name")?.to_string(); - self.command = Some(application.borrow_mut().find(&command_name)?); + let found = application.borrow_mut().find(&command_name)?; + *self.command.borrow_mut() = Some(found); } let mut helper = DescriptorHelper::new(); - let object = DescribableObject::Command(self.command.clone().unwrap()); + let object = DescribableObject::Command(self.command.borrow().clone().unwrap()); let mut options = indexmap::IndexMap::new(); options.insert("format".to_string(), input.borrow().get_option("format")?); options.insert("raw_text".to_string(), input.borrow().get_option("raw")?); helper.describe2(output.clone(), object, options)?; - self.command = None; + *self.command.borrow_mut() = None; Ok(0) } -- cgit v1.3.1