diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-24 03:56:26 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-24 03:57:46 +0900 |
| commit | f1af14b1cc503ac20f56a79a96c7780d02bdfe75 (patch) | |
| tree | 3f8661e1dc4d2092ac16b45c574c90ec2d8bec2a /crates/shirabe-external-packages/src/symfony/console/command/help_command.rs | |
| parent | c5fc34a106a706ac12925c4df273a926811d260b (diff) | |
| download | php-shirabe-f1af14b1cc503ac20f56a79a96c7780d02bdfe75.tar.gz php-shirabe-f1af14b1cc503ac20f56a79a96c7780d02bdfe75.tar.zst php-shirabe-f1af14b1cc503ac20f56a79a96c7780d02bdfe75.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/command/help_command.rs')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/console/command/help_command.rs | 23 |
1 files changed, 12 insertions, 11 deletions
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<Rc<RefCell<dyn Command>>>, + command: RefCell<Option<Rc<RefCell<dyn Command>>>>, } 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<RefCell<dyn Command>>) { - self.command = Some(command); + pub fn set_command(&self, command: Rc<RefCell<dyn Command>>) { + *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<RefCell<dyn InputInterface>>, output: Rc<RefCell<dyn OutputInterface>>, ) -> anyhow::Result<i64> { - 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) } |
