From d5b313f388d424e60ae33ae58c1a65a65b24b8f1 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 6 Jun 2026 18:04:45 +0900 Subject: refactor(command): share Input/OutputInterface via Rc Convert InputInterface and OutputInterface parameters from &dyn/&mut dyn references to Rc> shared ownership across the command, console, and IO layers, matching the Phase C shared-ownership approach already used for IOInterface. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/command/run_script_command.rs | 34 +++++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'crates/shirabe/src/command/run_script_command.rs') diff --git a/crates/shirabe/src/command/run_script_command.rs b/crates/shirabe/src/command/run_script_command.rs index 9118463..cf8b8f1 100644 --- a/crates/shirabe/src/command/run_script_command.rs +++ b/crates/shirabe/src/command/run_script_command.rs @@ -115,16 +115,16 @@ impl RunScriptCommand { pub fn interact( &mut self, - input: &mut dyn InputInterface, - _output: &dyn OutputInterface, + input: std::rc::Rc>, + _output: std::rc::Rc>, ) -> Result<()> { let scripts = self.get_scripts()?; if scripts.is_empty() { return Ok(()); } - if input.get_argument("script").as_string().is_some() - || input.get_option("list").as_bool().unwrap_or(false) + if input.borrow().get_argument("script").as_string().is_some() + || input.borrow().get_option("list").as_bool().unwrap_or(false) { return Ok(()); } @@ -145,7 +145,7 @@ impl RunScriptCommand { ); if let Some(selected) = script.as_string() { - // TODO(phase-b): input is &dyn InputInterface but set_argument needs &mut. + // TODO(phase-b): input is std::rc::Rc> but set_argument needs &mut. let _ = selected; } @@ -154,14 +154,14 @@ impl RunScriptCommand { pub fn execute( &mut self, - input: &dyn InputInterface, - output: &dyn OutputInterface, + input: std::rc::Rc>, + output: std::rc::Rc>, ) -> Result { - if input.get_option("list").as_bool().unwrap_or(false) { + if input.borrow().get_option("list").as_bool().unwrap_or(false) { return self.list_scripts(output); } - let script = match input.get_argument("script").as_string() { + let script = match input.borrow().get_argument("script").as_string() { None => { return Err(RuntimeException { message: "Missing required argument \"script\"".to_string(), @@ -187,8 +187,12 @@ impl RunScriptCommand { let dispatcher = crate::command::composer_full(&composer) .get_event_dispatcher() .clone(); - let dev_mode = input.get_option("dev").as_bool().unwrap_or(false) - || !input.get_option("no-dev").as_bool().unwrap_or(false); + let dev_mode = input.borrow().get_option("dev").as_bool().unwrap_or(false) + || !input + .borrow() + .get_option("no-dev") + .as_bool() + .unwrap_or(false); // TODO(phase-b): ScriptEvent::new takes Composer/IOInterface by value; placeholder construction. let _ = (script.clone(), &composer, dev_mode); let has_listeners = false; @@ -201,6 +205,7 @@ impl RunScriptCommand { } let args: Vec = input + .borrow() .get_argument("args") .as_list() .map(|l| { @@ -210,7 +215,7 @@ impl RunScriptCommand { }) .unwrap_or_default(); - if let Some(timeout_val) = input.get_option("timeout").as_string() { + if let Some(timeout_val) = input.borrow().get_option("timeout").as_string() { let timeout_str = timeout_val.to_string(); if !timeout_str.chars().all(|c| c.is_ascii_digit()) { return Err(RuntimeException { @@ -232,7 +237,10 @@ impl RunScriptCommand { .dispatch_script(&script, dev_mode, args, IndexMap::new())?) } - fn list_scripts(&mut self, output: &dyn OutputInterface) -> Result { + fn list_scripts( + &mut self, + output: std::rc::Rc>, + ) -> Result { let scripts = self.get_scripts()?; if scripts.is_empty() { return Ok(0); -- cgit v1.3.1