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/clear_cache_command.rs | 69 +++++++++++++++++------ 1 file changed, 52 insertions(+), 17 deletions(-) (limited to 'crates/shirabe/src/command/clear_cache_command.rs') diff --git a/crates/shirabe/src/command/clear_cache_command.rs b/crates/shirabe/src/command/clear_cache_command.rs index 5dbfaa5..31ba953 100644 --- a/crates/shirabe/src/command/clear_cache_command.rs +++ b/crates/shirabe/src/command/clear_cache_command.rs @@ -1,13 +1,25 @@ //! ref: composer/src/Composer/Command/ClearCacheCommand.php -use crate::command::{BaseCommand, BaseCommandData, HasBaseCommandData}; -use crate::composer; -use crate::composer::ComposerHandle; -use crate::console::input::InputOption; -use crate::factory::Factory; +use anyhow::Result; use indexmap::IndexMap; +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::PhpMixed; +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; +use crate::composer::PartialComposerHandle; +use crate::config::Config; +use crate::console::input::InputOption; +use crate::factory::Factory; +use crate::filter::platform_requirement_filter::PlatformRequirementFilterInterface; +use crate::io::IOInterface; #[derive(Debug)] pub struct ClearCacheCommand { @@ -15,9 +27,21 @@ pub struct ClearCacheCommand { } impl ClearCacheCommand { - pub fn configure(&mut self) { - self.set_name("clear-cache"); - self.set_aliases(&["clearcache".to_string(), "cc".to_string()]); + pub fn new() -> Self { + let mut command = ClearCacheCommand { + base_command_data: BaseCommandData::new(None), + }; + command + .configure() + .expect("ClearCacheCommand::configure uses static, valid metadata"); + command + } +} + +impl Command for ClearCacheCommand { + fn configure(&mut self) -> anyhow::Result<()> { + self.set_name("clear-cache")?; + self.set_aliases(vec!["clearcache".to_string(), "cc".to_string()])?; self.set_description("Clears composer's internal package cache"); self.set_definition(&[InputOption::new( "gc", @@ -33,12 +57,13 @@ impl ClearCacheCommand { cache directory.\n\n\ Read more at https://getcomposer.org/doc/03-cli.md#clear-cache-clearcache-cc", ); + Ok(()) } - pub fn execute( + fn execute( &mut self, - _input: std::rc::Rc>, - _output: std::rc::Rc>, + _input: Rc>, + _output: Rc>, ) -> anyhow::Result { // PHP: $config = $this->tryComposer()?->getConfig() ?? Factory::createConfig(); then // iterate the cache-* paths and clear/gc each via Cache. @@ -52,14 +77,24 @@ impl ClearCacheCommand { let _ = Factory::create_config(None, None); todo!("ClearCacheCommand::execute pending try_composer + Config sharing model") } -} -impl HasBaseCommandData for ClearCacheCommand { - 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 ClearCacheCommand { + 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