From a1c7e6908a26e10f6e1f23a51721664b5e2d838d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 17 May 2026 02:53:53 +0900 Subject: chore(style): cargo fmt --- crates/shirabe/src/command/run_script_command.rs | 104 ++++++++++++++++++----- 1 file changed, 84 insertions(+), 20 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 155a2f1..cbf85c0 100644 --- a/crates/shirabe/src/command/run_script_command.rs +++ b/crates/shirabe/src/command/run_script_command.rs @@ -47,27 +47,73 @@ impl RunScriptCommand { .set_description("Runs the scripts defined in composer.json") .set_definition(vec![ // completion callback (runtime script names) is deferred to Phase B - InputArgument::new("script", Some(InputArgument::OPTIONAL), "Script name to run.", None, vec![]), - InputArgument::new("args", Some(InputArgument::IS_ARRAY | InputArgument::OPTIONAL), "", None, vec![]), - InputOption::new("timeout", None, Some(InputOption::VALUE_REQUIRED), "Sets script timeout in seconds, or 0 for never.", None, vec![]), - InputOption::new("dev", None, Some(InputOption::VALUE_NONE), "Sets the dev mode.", None, vec![]), - InputOption::new("no-dev", None, Some(InputOption::VALUE_NONE), "Disables the dev mode.", None, vec![]), - InputOption::new("list", Some(PhpMixed::String("l".to_string())), Some(InputOption::VALUE_NONE), "List scripts.", None, vec![]), + InputArgument::new( + "script", + Some(InputArgument::OPTIONAL), + "Script name to run.", + None, + vec![], + ), + InputArgument::new( + "args", + Some(InputArgument::IS_ARRAY | InputArgument::OPTIONAL), + "", + None, + vec![], + ), + InputOption::new( + "timeout", + None, + Some(InputOption::VALUE_REQUIRED), + "Sets script timeout in seconds, or 0 for never.", + None, + vec![], + ), + InputOption::new( + "dev", + None, + Some(InputOption::VALUE_NONE), + "Sets the dev mode.", + None, + vec![], + ), + InputOption::new( + "no-dev", + None, + Some(InputOption::VALUE_NONE), + "Disables the dev mode.", + None, + vec![], + ), + InputOption::new( + "list", + Some(PhpMixed::String("l".to_string())), + Some(InputOption::VALUE_NONE), + "List scripts.", + None, + vec![], + ), ]) .set_help( "The run-script command runs scripts defined in composer.json:\n\n\ php composer.phar run-script post-update-cmd\n\n\ - Read more at https://getcomposer.org/doc/03-cli.md#run-script-run" + Read more at https://getcomposer.org/doc/03-cli.md#run-script-run", ); } - pub fn interact(&self, input: &mut dyn InputInterface, _output: &dyn OutputInterface) -> Result<()> { + pub fn interact( + &self, + input: &mut dyn InputInterface, + _output: &dyn OutputInterface, + ) -> Result<()> { let scripts = self.get_scripts()?; if scripts.is_empty() { return Ok(()); } - if input.get_argument("script").as_string_opt().is_some() || input.get_option("list").as_bool().unwrap_or(false) { + if input.get_argument("script").as_string_opt().is_some() + || input.get_option("list").as_bool().unwrap_or(false) + { return Ok(()); } @@ -103,7 +149,8 @@ impl RunScriptCommand { return Err(RuntimeException { message: "Missing required argument \"script\"".to_string(), code: 0, - }.into()); + } + .into()); } Some(s) => s.to_string(), }; @@ -114,33 +161,44 @@ impl RunScriptCommand { return Err(InvalidArgumentException { message: format!("Script \"{}\" cannot be run with this command", script), code: 0, - }.into()); + } + .into()); } } let composer = self.inner.require_composer()?; - 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.get_option("dev").as_bool().unwrap_or(false) + || !input.get_option("no-dev").as_bool().unwrap_or(false); let event = ScriptEvent::new(script.clone(), &composer, self.inner.get_io(), dev_mode); let has_listeners = composer.get_event_dispatcher().has_event_listeners(&event); if !has_listeners { return Err(InvalidArgumentException { message: format!("Script \"{}\" is not defined in this package", script), code: 0, - }.into()); + } + .into()); } - let args: Vec = input.get_argument("args") + let args: Vec = input + .get_argument("args") .as_list() - .map(|l| l.iter().filter_map(|v| v.as_string().map(|s| s.to_string())).collect()) + .map(|l| { + l.iter() + .filter_map(|v| v.as_string().map(|s| s.to_string())) + .collect() + }) .unwrap_or_default(); if let Some(timeout_val) = input.get_option("timeout").as_string_opt() { let timeout_str = timeout_val.to_string(); if !timeout_str.chars().all(|c| c.is_ascii_digit()) { return Err(RuntimeException { - message: "Timeout value must be numeric and positive if defined, or 0 for forever".to_string(), + message: + "Timeout value must be numeric and positive if defined, or 0 for forever" + .to_string(), code: 0, - }.into()); + } + .into()); } let timeout: i64 = timeout_str.parse().unwrap_or(0); ProcessExecutor::set_timeout(timeout); @@ -148,7 +206,9 @@ impl RunScriptCommand { Platform::put_env("COMPOSER_DEV_MODE", if dev_mode { "1" } else { "0" }); - Ok(composer.get_event_dispatcher().dispatch_script(&script, dev_mode, args)?) + Ok(composer + .get_event_dispatcher() + .dispatch_script(&script, dev_mode, args)?) } fn list_scripts(&self, output: &dyn OutputInterface) -> Result { @@ -159,7 +219,8 @@ impl RunScriptCommand { let io = self.inner.get_io(); io.write_error("scripts:"); - let table: Vec> = scripts.iter() + let table: Vec> = scripts + .iter() .map(|(name, desc)| vec![format!(" {}", name), desc.clone()]) .collect(); @@ -176,7 +237,10 @@ impl RunScriptCommand { let mut result: Vec<(String, String)> = vec![]; for (name, _script) in scripts { - let description = self.inner.get_application().find(&name) + let description = self + .inner + .get_application() + .find(&name) .map(|cmd| cmd.get_description().unwrap_or("").to_string()) .unwrap_or_default(); result.push((name, description)); -- cgit v1.3.1