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/create_project_command.rs | 35 ++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'crates/shirabe/src/command/create_project_command.rs') diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs index 8432040..9969cf5 100644 --- a/crates/shirabe/src/command/create_project_command.rs +++ b/crates/shirabe/src/command/create_project_command.rs @@ -59,7 +59,7 @@ pub struct CreateProjectCommand { /// @var SuggestedPackagesReporter pub(crate) suggested_packages_reporter: - Option>>, + std::cell::RefCell>>>, } impl Default for CreateProjectCommand { @@ -70,9 +70,9 @@ impl Default for CreateProjectCommand { impl CreateProjectCommand { pub fn new() -> Self { - let mut command = CreateProjectCommand { + let command = CreateProjectCommand { base_command_data: BaseCommandData::new(None), - suggested_packages_reporter: None, + suggested_packages_reporter: std::cell::RefCell::new(None), }; command .configure() @@ -82,7 +82,7 @@ impl CreateProjectCommand { } impl Command for CreateProjectCommand { - fn configure(&mut self) -> anyhow::Result<()> { + fn configure(&self) -> anyhow::Result<()> { // TODO(cli-completion): suggest_prefer_install / suggest_available_package self.set_name("create-project")?; self.set_description("Creates new project from a package into given directory"); @@ -134,7 +134,7 @@ impl Command for CreateProjectCommand { } fn execute( - &mut self, + &self, input: std::rc::Rc>, _output: std::rc::Rc>, ) -> anyhow::Result { @@ -260,7 +260,7 @@ impl Command for CreateProjectCommand { } fn initialize( - &mut self, + &self, input: Rc>, output: Rc>, ) -> anyhow::Result<()> { @@ -271,10 +271,10 @@ impl Command for CreateProjectCommand { } impl BaseCommand for CreateProjectCommand { - fn command_data_mut( - &mut self, - ) -> &mut shirabe_external_packages::symfony::console::command::command::CommandData { - self.base_command_data.command_data_mut() + fn command_data( + &self, + ) -> &shirabe_external_packages::symfony::console::command::command::CommandData { + self.base_command_data.command_data() } crate::delegate_base_command_trait_impls_to_inner!(base_command_data); @@ -286,7 +286,7 @@ impl CreateProjectCommand { /// @throws \Exception #[allow(clippy::too_many_arguments)] pub fn install_project( - &mut self, + &self, io: std::rc::Rc>, config: std::rc::Rc>, input: std::rc::Rc>, @@ -330,9 +330,9 @@ impl CreateProjectCommand { io.borrow_mut() .load_configuration(&mut config.borrow_mut())?; - self.suggested_packages_reporter = Some(std::rc::Rc::new(std::cell::RefCell::new( - SuggestedPackagesReporter::new(io.clone()), - ))); + *self.suggested_packages_reporter.borrow_mut() = Some(std::rc::Rc::new( + std::cell::RefCell::new(SuggestedPackagesReporter::new(io.clone())), + )); let installed_from_vcs = if let Some(package_name) = package_name.as_ref() { self.install_root_package( @@ -469,7 +469,11 @@ impl CreateProjectCommand { .set_dev_mode(install_dev_packages) .set_platform_requirement_filter(platform_requirement_filter.clone()) .set_suggested_packages_reporter( - self.suggested_packages_reporter.as_ref().unwrap().clone(), + self.suggested_packages_reporter + .borrow() + .as_ref() + .unwrap() + .clone(), ) .set_optimize_autoloader( config @@ -1014,6 +1018,7 @@ impl CreateProjectCommand { // collect suggestions self.suggested_packages_reporter + .borrow() .as_ref() .unwrap() .borrow_mut() -- cgit v1.3.1