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/src/command/base_dependency_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/src/command/base_dependency_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/base_dependency_command.rs | 25 |
1 files changed, 13 insertions, 12 deletions
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<String>; + fn colors(&self) -> std::cell::Ref<'_, Vec<String>>; + fn set_colors(&self, colors: Vec<String>); fn do_execute( - &mut self, + &self, input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, 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<std::cell::RefCell<dyn OutputInterface>>) { - *self.colors_mut() = vec![ + fn init_styles(&self, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>) { + 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('└', "`-") |
