From fd733a87364b877d5e66b4973bd61b5379ec4d61 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 16 Jun 2026 21:59:35 +0900 Subject: feat(command): implement Symfony Command --- crates/shirabe/src/command/script_alias_command.rs | 144 ++++++++++++--------- 1 file changed, 84 insertions(+), 60 deletions(-) (limited to 'crates/shirabe/src/command/script_alias_command.rs') diff --git a/crates/shirabe/src/command/script_alias_command.rs b/crates/shirabe/src/command/script_alias_command.rs index 95c80fb..e740c4b 100644 --- a/crates/shirabe/src/command/script_alias_command.rs +++ b/crates/shirabe/src/command/script_alias_command.rs @@ -1,15 +1,26 @@ //! ref: composer/src/Composer/Command/ScriptAliasCommand.php -use crate::command::{BaseCommand, BaseCommandData, HasBaseCommandData}; -use crate::console::input::InputArgument; -use crate::console::input::InputOption; -use crate::io::IOInterface; -use crate::util::Platform; use anyhow::Result; +use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; +use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::{InvalidArgumentException, LogicException, PhpMixed, is_string}; +use std::cell::RefCell; +use std::rc::Rc; + +use crate::advisory::AuditConfig; +use crate::command::BaseCommand; +use crate::command::BaseCommandData; +use crate::command::base_command::base_command_initialize; +use crate::composer::PartialComposerHandle; +use crate::config::Config; +use crate::console::input::InputArgument; +use crate::console::input::InputOption; +use crate::filter::platform_requirement_filter::PlatformRequirementFilterInterface; +use crate::io::IOInterface; +use crate::util::Platform; #[derive(Debug)] pub struct ScriptAliasCommand { @@ -43,64 +54,67 @@ impl ScriptAliasCommand { // the command's name/definition/application state and ignoreValidationErrors() flips a flag // on it. Composer's BaseCommand carries no such Symfony Command state yet (the Symfony // Command base is an intentional todo!() stub), so there is nothing to initialize here. - Ok(Self { - base_command_data: BaseCommandData { - composer: None, - io: None, - }, + let mut command = Self { + base_command_data: BaseCommandData::new(None), script, description, aliases, - }) + }; + command + .configure() + .expect("ScriptAliasCommand::configure uses constructor-provided metadata"); + Ok(command) } +} - pub fn configure(&mut self) { - let script = self.script.clone(); +impl Command for ScriptAliasCommand { + fn configure(&mut self) -> anyhow::Result<()> { + let name = self.script.clone(); + self.set_name(&name)?; let description = self.description.clone(); - let aliases = self.aliases.clone(); - self.set_name(&script) - .set_description(&description) - .set_aliases(&aliases) - .set_definition(&[ - InputOption::new( - "dev", - None, - Some(InputOption::VALUE_NONE), - "Sets the dev mode.", - None, - ) - .unwrap() - .into(), - InputOption::new( - "no-dev", - None, - Some(InputOption::VALUE_NONE), - "Disables the dev mode.", - None, - ) - .unwrap() - .into(), - InputArgument::new( - "args", - Some(InputArgument::IS_ARRAY | InputArgument::OPTIONAL), - "", - None, - ) - .unwrap() - .into(), - ]) - .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", - ); + self.set_description(&description); + self.set_aliases(self.aliases.clone())?; + self.set_definition(&[ + InputOption::new( + "dev", + None, + Some(InputOption::VALUE_NONE), + "Sets the dev mode.", + None, + ) + .unwrap() + .into(), + InputOption::new( + "no-dev", + None, + Some(InputOption::VALUE_NONE), + "Disables the dev mode.", + None, + ) + .unwrap() + .into(), + InputArgument::new( + "args", + Some(InputArgument::IS_ARRAY | InputArgument::OPTIONAL), + "", + None, + ) + .unwrap() + .into(), + ]); + self.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", + ); + Ok(()) } - pub fn execute( + fn execute( &mut self, - input: std::rc::Rc>, - _output: std::rc::Rc>, - ) -> Result { + input: Rc>, + _output: Rc>, + ) -> anyhow::Result { let composer = self.require_composer(None, None)?; let dispatcher = crate::command::composer_full(&composer) .get_event_dispatcher() @@ -151,14 +165,24 @@ impl ScriptAliasCommand { .borrow_mut() .dispatch_script(&self.script, dev_mode, args_value, flags)?) } -} -impl HasBaseCommandData for ScriptAliasCommand { - fn base_command_data(&self) -> &BaseCommandData { - &self.base_command_data + fn initialize( + &mut self, + input: Rc>, + output: Rc>, + ) -> anyhow::Result<()> { + base_command_initialize(self, input, output) } - fn base_command_data_mut(&mut self) -> &mut BaseCommandData { - &mut self.base_command_data + shirabe_external_packages::delegate_command_trait_impls_to_inner!(base_command_data); +} + +impl BaseCommand for ScriptAliasCommand { + fn command_data_mut( + &mut self, + ) -> &mut shirabe_external_packages::symfony::console::command::command::CommandData { + self.base_command_data.command_data_mut() } + + crate::delegate_base_command_trait_impls_to_inner!(base_command_data); } -- cgit v1.3.1