diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-17 13:56:15 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-17 13:59:31 +0900 |
| commit | a9bb49c7d685dd82feaf4050f756fdf590315200 (patch) | |
| tree | 0242a737e8280fe9e25c38bb7a6f844d2eff623c /crates/shirabe | |
| parent | 15b1be89eb168a30e96459c6a5307afcb7323bbc (diff) | |
| download | php-shirabe-a9bb49c7d685dd82feaf4050f756fdf590315200.tar.gz php-shirabe-a9bb49c7d685dd82feaf4050f756fdf590315200.tar.zst php-shirabe-a9bb49c7d685dd82feaf4050f756fdf590315200.zip | |
fix(compile): implement abstract class traits across all types
Implement BaseCommand trait and other abstract class traits across
all command, downloader, io, package, and VCS driver types. Also
fix trait method signatures for composer_mut and io_mut to return
mutable references to Option rather than Option of mutable references.
Diffstat (limited to 'crates/shirabe')
66 files changed, 1670 insertions, 96 deletions
diff --git a/crates/shirabe/src/command/about_command.rs b/crates/shirabe/src/command/about_command.rs index 3b16b0e..583482b 100644 --- a/crates/shirabe/src/command/about_command.rs +++ b/crates/shirabe/src/command/about_command.rs @@ -2,11 +2,15 @@ use crate::command::base_command::BaseCommand; use crate::composer::Composer; +use crate::io::io_interface::IOInterface; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; pub struct AboutCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl AboutCommand { @@ -29,3 +33,29 @@ impl AboutCommand { 0 } } + +impl BaseCommand for AboutCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/archive_command.rs b/crates/shirabe/src/command/archive_command.rs index 867b010..1a85df4 100644 --- a/crates/shirabe/src/command/archive_command.rs +++ b/crates/shirabe/src/command/archive_command.rs @@ -4,6 +4,7 @@ use std::any::Any; use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{LogicException, get_debug_type}; @@ -33,7 +34,9 @@ use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct ArchiveCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl CompletionTrait for ArchiveCommand {} @@ -319,3 +322,29 @@ impl ArchiveCommand { Ok(Some(package.into_complete())) } } + +impl BaseCommand for ArchiveCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/audit_command.rs b/crates/shirabe/src/command/audit_command.rs index 7fb6c5f..2331f8d 100644 --- a/crates/shirabe/src/command/audit_command.rs +++ b/crates/shirabe/src/command/audit_command.rs @@ -5,13 +5,16 @@ use crate::advisory::auditor::Auditor; use crate::command::base_command::BaseCommand; use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::package::package_interface::PackageInterface; use crate::repository::installed_repository::InstalledRepository; use crate::repository::repository_set::RepositorySet; use crate::repository::repository_utils::RepositoryUtils; use anyhow::Result; -use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; +use shirabe_external_packages::symfony::{ + component::console::command::command::Command, console::input::input_interface::InputInterface, +}; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, UnexpectedValueException, array_fill_keys, array_merge, implode, in_array, @@ -19,7 +22,9 @@ use shirabe_php_shim::{ #[derive(Debug)] pub struct AuditCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl AuditCommand { @@ -154,3 +159,29 @@ impl AuditCommand { Ok(installed_repo.get_packages()) } } + +impl BaseCommand for AuditCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs index 7f9a860..c9f79b7 100644 --- a/crates/shirabe/src/command/base_command.rs +++ b/crates/shirabe/src/command/base_command.rs @@ -38,9 +38,9 @@ pub trait BaseCommand { fn inner(&self) -> &Command; fn inner_mut(&mut self) -> &mut Command; fn composer(&self) -> Option<&Composer>; - fn composer_mut(&mut self) -> Option<&mut Composer>; + fn composer_mut(&mut self) -> &mut Option<Composer>; fn io(&self) -> Option<&dyn IOInterface>; - fn io_mut(&mut self) -> Option<&mut dyn IOInterface>; + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>>; /// Gets the application instance for this command. fn get_application(&self) -> Result<Application> { diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs index ddb17c2..0382246 100644 --- a/crates/shirabe/src/command/bump_command.rs +++ b/crates/shirabe/src/command/bump_command.rs @@ -2,12 +2,14 @@ use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{PhpMixed, file_get_contents, file_put_contents, is_writable, strtolower}; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::factory::Factory; @@ -23,7 +25,9 @@ use crate::util::silencer::Silencer; #[derive(Debug)] pub struct BumpCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl CompletionTrait for BumpCommand {} @@ -368,3 +372,29 @@ impl BumpCommand { } } } + +impl BaseCommand for BumpCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/check_platform_reqs_command.rs b/crates/shirabe/src/command/check_platform_reqs_command.rs index fcf10aa..62cde82 100644 --- a/crates/shirabe/src/command/check_platform_reqs_command.rs +++ b/crates/shirabe/src/command/check_platform_reqs_command.rs @@ -2,13 +2,16 @@ use anyhow::Result; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{PhpMixed, strip_tags}; use shirabe_semver::constraint::constraint::Constraint; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::package::link::Link; use crate::repository::installed_repository::InstalledRepository; @@ -25,7 +28,9 @@ struct CheckResult { #[derive(Debug)] pub struct CheckPlatformReqsCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl CheckPlatformReqsCommand { @@ -316,3 +321,29 @@ impl CheckPlatformReqsCommand { } } } + +impl BaseCommand for CheckPlatformReqsCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/clear_cache_command.rs b/crates/shirabe/src/command/clear_cache_command.rs index 06026a4..1d49502 100644 --- a/crates/shirabe/src/command/clear_cache_command.rs +++ b/crates/shirabe/src/command/clear_cache_command.rs @@ -2,15 +2,20 @@ use crate::cache::Cache; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; use crate::factory::Factory; +use crate::io::io_interface::IOInterface; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; #[derive(Debug)] pub struct ClearCacheCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl ClearCacheCommand { @@ -116,3 +121,29 @@ impl ClearCacheCommand { Ok(0) } } + +impl BaseCommand for ClearCacheCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs index 5237b62..62e630a 100644 --- a/crates/shirabe/src/command/config_command.rs +++ b/crates/shirabe/src/command/config_command.rs @@ -3,6 +3,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::completion::completion_input::CompletionInput; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::input::input_option::InputOption; @@ -17,7 +18,9 @@ use shirabe_php_shim::{ }; use crate::advisory::auditor::Auditor; +use crate::command::base_command::BaseCommand; use crate::command::base_config_command::BaseConfigCommand; +use crate::composer::Composer; use crate::config::Config; use crate::config::json_config_source::JsonConfigSource; use crate::console::input::input_argument::InputArgument; @@ -32,7 +35,14 @@ use shirabe_semver::version_parser::VersionParser; #[derive(Debug)] pub struct ConfigCommand { - inner: BaseConfigCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, + + config: Option<Config>, + config_file: Option<JsonFile>, + config_source: Option<JsonConfigSource>, + pub(crate) auth_config_file: Option<JsonFile>, pub(crate) auth_config_source: Option<JsonConfigSource>, } @@ -2170,3 +2180,81 @@ fn key_first_key(value: &PhpMixed) -> Option<String> { } None } + +impl BaseCommand for ConfigCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> Option<&mut Composer> { + self.composer.as_mut() + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_ref() + } + + fn io_mut(&mut self) -> Option<&mut dyn IOInterface> { + self.io.as_mut() + } +} + +impl BaseCommand for ConfigCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} + +impl BaseConfigCommand for ConfigCommand { + fn config(&self) -> Option<&Config> { + self.config.as_ref() + } + + fn config_mut(&mut self) -> Option<&mut Config> { + self.config.as_mut() + } + + fn config_file(&self) -> Option<&JsonFile> { + self.config_file.as_ref() + } + + fn config_file_mut(&mut self) -> Option<&mut JsonFile> { + self.config_file.as_mut() + } + + fn config_source(&self) -> Option<&JsonConfigSource> { + self.config_source.as_ref() + } + + fn config_source_mut(&mut self) -> Option<&mut JsonConfigSource> { + self.config_source.as_mut() + } +} diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs index c649848..c0902d4 100644 --- a/crates/shirabe/src/command/create_project_command.rs +++ b/crates/shirabe/src/command/create_project_command.rs @@ -3,6 +3,7 @@ use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::seld::signal::signal_handler::SignalHandler; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::output::output_interface::OutputInterface; use shirabe_external_packages::symfony::component::finder::finder::Finder; @@ -48,7 +49,10 @@ use crate::util::process_executor::ProcessExecutor; /// Install a package as new project into new directory. #[derive(Debug)] pub struct CreateProjectCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, + /// @var SuggestedPackagesReporter pub(crate) suggested_packages_reporter: Option<SuggestedPackagesReporter>, } @@ -895,3 +899,29 @@ impl CreateProjectCommand { self.inner.create_audit_config(config, input) } } + +impl BaseCommand for CreateProjectCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/depends_command.rs b/crates/shirabe/src/command/depends_command.rs index 9ec3dde..f83fe00 100644 --- a/crates/shirabe/src/command/depends_command.rs +++ b/crates/shirabe/src/command/depends_command.rs @@ -8,7 +8,7 @@ use shirabe_external_packages::symfony::console::input::input_interface::InputIn use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; pub struct DependsCommand { - inner: BaseDependencyCommand, + colors: Vec<String>, } impl CompletionTrait for DependsCommand {} @@ -58,3 +58,39 @@ impl DependsCommand { self.inner.do_execute(input, output) } } + +impl BaseCommand for DependsCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} + +impl BaseDependencyCommand for DependsCommand { + fn colors(&self) -> &[String] { + &self.colors + } + + fn colors_mut(&mut self) -> &mut [String] { + &mut self.colors + } +} diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index 07e367f..23c0cd0 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -4,6 +4,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::composer::xdebug_handler::xdebug_handler::XdebugHandler; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::output::output_interface::OutputInterface; use shirabe_external_packages::symfony::component::process::executable_finder::ExecutableFinder; @@ -25,6 +26,7 @@ use crate::config::Config; use crate::downloader::transport_exception::TransportException; use crate::factory::Factory; use crate::io::buffer_io::BufferIO; +use crate::io::io_interface::IOInterface; use crate::io::null_io::NullIO; use crate::json::json_file::JsonFile; use crate::json::json_validation_exception::JsonValidationException; @@ -51,7 +53,10 @@ use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct DiagnoseCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, + pub(crate) http_downloader: Option<HttpDownloader>, pub(crate) process: Option<ProcessExecutor>, pub(crate) exit_code: i64, @@ -1364,3 +1369,29 @@ impl DiagnoseCommand { PhpMixed::Bool(true) } } + +impl BaseCommand for DiagnoseCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/dump_autoload_command.rs b/crates/shirabe/src/command/dump_autoload_command.rs index 295f1c0..471b353 100644 --- a/crates/shirabe/src/command/dump_autoload_command.rs +++ b/crates/shirabe/src/command/dump_autoload_command.rs @@ -1,18 +1,23 @@ //! ref: composer/src/Composer/Command/DumpAutoloadCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{InvalidArgumentException, PhpMixed, file_exists}; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::plugin::command_event::CommandEvent; use crate::plugin::plugin_events::PluginEvents; #[derive(Debug)] pub struct DumpAutoloadCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl DumpAutoloadCommand { @@ -197,3 +202,29 @@ impl DumpAutoloadCommand { Ok(0) } } + +impl BaseCommand for DumpAutoloadCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/exec_command.rs b/crates/shirabe/src/command/exec_command.rs index 5602e85..82c90bc 100644 --- a/crates/shirabe/src/command/exec_command.rs +++ b/crates/shirabe/src/command/exec_command.rs @@ -1,17 +1,22 @@ //! ref: composer/src/Composer/Command/ExecCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{PhpMixed, RuntimeException, basename, chdir, getcwd, glob}; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; #[derive(Debug)] pub struct ExecCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl ExecCommand { @@ -186,3 +191,29 @@ impl ExecCommand { Ok(binaries) } } + +impl BaseCommand for ExecCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/fund_command.rs b/crates/shirabe/src/command/fund_command.rs index 398efd9..0d0c2ec 100644 --- a/crates/shirabe/src/command/fund_command.rs +++ b/crates/shirabe/src/command/fund_command.rs @@ -5,6 +5,7 @@ use std::any::Any; use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::formatter::output_formatter::OutputFormatter; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; @@ -12,7 +13,9 @@ use shirabe_php_shim::PhpMixed; use shirabe_semver::constraint::match_all_constraint::MatchAllConstraint; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::package::alias_package::AliasPackage; use crate::package::base_package::BasePackage; @@ -21,7 +24,9 @@ use crate::repository::composite_repository::CompositeRepository; #[derive(Debug)] pub struct FundCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl FundCommand { @@ -201,3 +206,29 @@ impl FundCommand { Ok(()) } } + +impl BaseCommand for FundCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/global_command.rs b/crates/shirabe/src/command/global_command.rs index 695232c..a5423f5 100644 --- a/crates/shirabe/src/command/global_command.rs +++ b/crates/shirabe/src/command/global_command.rs @@ -4,6 +4,7 @@ use std::path::Path; use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::completion::completion_input::CompletionInput; use shirabe_external_packages::symfony::console::completion::completion_suggestions::CompletionSuggestions; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; @@ -12,14 +13,18 @@ use shirabe_external_packages::symfony::console::output::output_interface::Outpu use shirabe_php_shim::{LogicException, RuntimeException, chdir}; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::factory::Factory; +use crate::io::io_interface::IOInterface; use crate::util::filesystem::Filesystem; use crate::util::platform::Platform; #[derive(Debug)] pub struct GlobalCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl GlobalCommand { @@ -157,3 +162,29 @@ impl GlobalCommand { true } } + +impl BaseCommand for GlobalCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/home_command.rs b/crates/shirabe/src/command/home_command.rs index 142f868..dd8a81c 100644 --- a/crates/shirabe/src/command/home_command.rs +++ b/crates/shirabe/src/command/home_command.rs @@ -1,14 +1,17 @@ //! ref: composer/src/Composer/Command/HomeCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{FILTER_VALIDATE_URL, filter_var}; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::package::complete_package_interface::CompletePackageInterface; use crate::repository::repository_factory::RepositoryFactory; use crate::repository::repository_interface::RepositoryInterface; @@ -18,7 +21,9 @@ use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct HomeCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl CompletionTrait for HomeCommand {} @@ -216,3 +221,29 @@ impl HomeCommand { )) } } + +impl BaseCommand for HomeCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index e61b7a6..d8f0113 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -4,6 +4,7 @@ use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::composer::spdx_licenses::spdx_licenses::SpdxLicenses; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::helper::formatter_helper::FormatterHelper; use shirabe_external_packages::symfony::component::console::input::array_input::ArrayInput; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; @@ -19,6 +20,7 @@ use shirabe_php_shim::{ use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; use crate::command::package_discovery_trait::PackageDiscoveryTrait; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; use crate::factory::Factory; use crate::io::io_interface::IOInterface; @@ -34,7 +36,10 @@ use crate::util::silencer::Silencer; #[derive(Debug)] pub struct InitCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, + /// @var array<string, string> git_config: Option<IndexMap<String, String>>, } @@ -1152,3 +1157,29 @@ impl InitCommand { None } } + +impl BaseCommand for InitCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/install_command.rs b/crates/shirabe/src/command/install_command.rs index 264b58c..04d630b 100644 --- a/crates/shirabe/src/command/install_command.rs +++ b/crates/shirabe/src/command/install_command.rs @@ -1,6 +1,7 @@ //! ref: composer/src/Composer/Command/InstallCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::PhpMixed; @@ -8,16 +9,20 @@ use shirabe_php_shim::PhpMixed; use crate::advisory::auditor::Auditor; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::installer::Installer; +use crate::io::io_interface::IOInterface; use crate::plugin::command_event::CommandEvent; use crate::plugin::plugin_events::PluginEvents; use crate::util::http_downloader::HttpDownloader; #[derive(Debug)] pub struct InstallCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl CompletionTrait for InstallCommand {} @@ -174,3 +179,29 @@ impl InstallCommand { install.run() } } + +impl BaseCommand for InstallCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/licenses_command.rs b/crates/shirabe/src/command/licenses_command.rs index ddb7b32..4cebc07 100644 --- a/crates/shirabe/src/command/licenses_command.rs +++ b/crates/shirabe/src/command/licenses_command.rs @@ -4,6 +4,7 @@ use std::any::Any; use anyhow::Result; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::formatter::output_formatter::OutputFormatter; use shirabe_external_packages::symfony::console::helper::table::Table; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; @@ -12,7 +13,9 @@ use shirabe_external_packages::symfony::console::style::symfony_style::SymfonySt use shirabe_php_shim::{PhpMixed, RuntimeException, UnexpectedValueException}; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::package::complete_package::CompletePackage; use crate::package::complete_package_interface::CompletePackageInterface; @@ -24,7 +27,9 @@ use crate::util::package_sorter::PackageSorter; #[derive(Debug)] pub struct LicensesCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl LicensesCommand { @@ -281,3 +286,29 @@ impl LicensesCommand { Ok(0) } } + +impl BaseCommand for LicensesCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/outdated_command.rs b/crates/shirabe/src/command/outdated_command.rs index ed927b7..1a19931 100644 --- a/crates/shirabe/src/command/outdated_command.rs +++ b/crates/shirabe/src/command/outdated_command.rs @@ -2,10 +2,13 @@ use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use anyhow::Result; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::array_input::ArrayInput; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; @@ -13,7 +16,9 @@ use shirabe_php_shim::PhpMixed; #[derive(Debug)] pub struct OutdatedCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl CompletionTrait for OutdatedCommand {} @@ -133,3 +138,29 @@ impl OutdatedCommand { true } } + +impl BaseCommand for OutdatedCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/prohibits_command.rs b/crates/shirabe/src/command/prohibits_command.rs index accfcf0..c8aa89d 100644 --- a/crates/shirabe/src/command/prohibits_command.rs +++ b/crates/shirabe/src/command/prohibits_command.rs @@ -8,7 +8,7 @@ use shirabe_external_packages::symfony::console::input::input_interface::InputIn use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; pub struct ProhibitsCommand { - inner: BaseDependencyCommand, + colors: Vec<String>, } impl CompletionTrait for ProhibitsCommand {} @@ -65,3 +65,39 @@ impl ProhibitsCommand { self.inner.do_execute(input, output, true) } } + +impl BaseCommand for ProhibitsCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} + +impl BaseDependencyCommand for ProhibitsCommand { + fn colors(&self) -> &[String] { + &self.colors + } + + fn colors_mut(&mut self) -> &mut [String] { + &mut self.colors + } +} diff --git a/crates/shirabe/src/command/reinstall_command.rs b/crates/shirabe/src/command/reinstall_command.rs index 3fb26a2..e0a8843 100644 --- a/crates/shirabe/src/command/reinstall_command.rs +++ b/crates/shirabe/src/command/reinstall_command.rs @@ -4,17 +4,20 @@ use std::any::Any; use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::InvalidArgumentException; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::dependency_resolver::operation::install_operation::InstallOperation; use crate::dependency_resolver::operation::uninstall_operation::UninstallOperation; use crate::dependency_resolver::transaction::Transaction; +use crate::io::io_interface::IOInterface; use crate::package::alias_package::AliasPackage; use crate::package::base_package::BasePackage; use crate::plugin::command_event::CommandEvent; @@ -24,7 +27,9 @@ use crate::util::platform::Platform; #[derive(Debug)] pub struct ReinstallCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl CompletionTrait for ReinstallCommand {} @@ -264,3 +269,29 @@ impl ReinstallCommand { Ok(0) } } + +impl BaseCommand for ReinstallCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/remove_command.rs b/crates/shirabe/src/command/remove_command.rs index b7f8378..da1da09 100644 --- a/crates/shirabe/src/command/remove_command.rs +++ b/crates/shirabe/src/command/remove_command.rs @@ -2,6 +2,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::exception::invalid_argument_exception::InvalidArgumentException; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::output::output_interface::OutputInterface; @@ -10,18 +11,22 @@ use shirabe_php_shim::{PhpMixed, UnexpectedValueException, array_map, strtolower use crate::advisory::auditor::Auditor; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::config::json_config_source::JsonConfigSource; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::dependency_resolver::request::Request; use crate::factory::Factory; use crate::installer::Installer; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::package::base_package::BasePackage; #[derive(Debug)] pub struct RemoveCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl RemoveCommand { @@ -672,3 +677,29 @@ impl RemoveCommand { Ok(status) } } + +impl BaseCommand for RemoveCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/repository_command.rs b/crates/shirabe/src/command/repository_command.rs index cfe9065..86afe80 100644 --- a/crates/shirabe/src/command/repository_command.rs +++ b/crates/shirabe/src/command/repository_command.rs @@ -2,6 +2,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::completion::completion_input::CompletionInput; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; @@ -9,15 +10,26 @@ use shirabe_php_shim::{ InvalidArgumentException, PHP_URL_HOST, PhpMixed, RuntimeException, parse_url, strtolower, }; +use crate::command::base_command::BaseCommand; use crate::command::base_config_command::BaseConfigCommand; +use crate::composer::Composer; +use crate::config::Config; +use crate::config::json_config_source::JsonConfigSource; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::factory::Factory; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; #[derive(Debug)] pub struct RepositoryCommand { - inner: BaseConfigCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, + + config: Option<Config>, + config_file: Option<JsonFile>, + config_source: Option<JsonConfigSource>, } impl RepositoryCommand { @@ -436,3 +448,81 @@ impl RepositoryCommand { }) } } + +impl BaseCommand for RepositoryCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> Option<&mut Composer> { + self.composer.as_mut() + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_ref() + } + + fn io_mut(&mut self) -> Option<&mut dyn IOInterface> { + self.io.as_mut() + } +} + +impl BaseCommand for RepositoryCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} + +impl BaseConfigCommand for RepositoryCommand { + fn config(&self) -> Option<&Config> { + self.config.as_ref() + } + + fn config_mut(&mut self) -> Option<&mut Config> { + self.config.as_mut() + } + + fn config_file(&self) -> Option<&JsonFile> { + self.config_file.as_ref() + } + + fn config_file_mut(&mut self) -> Option<&mut JsonFile> { + self.config_file.as_mut() + } + + fn config_source(&self) -> Option<&JsonConfigSource> { + self.config_source.as_ref() + } + + fn config_source_mut(&mut self) -> Option<&mut JsonConfigSource> { + self.config_source.as_mut() + } +} diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs index 738790d..24dda7e 100644 --- a/crates/shirabe/src/command/require_command.rs +++ b/crates/shirabe/src/command/require_command.rs @@ -4,6 +4,7 @@ use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::seld::signal::signal_handler::SignalHandler; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::output::output_interface::OutputInterface; use shirabe_php_shim::{ @@ -17,6 +18,7 @@ use crate::advisory::auditor::Auditor; use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; use crate::command::package_discovery_trait::PackageDiscoveryTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::dependency_resolver::request::Request; @@ -45,7 +47,10 @@ use crate::util::silencer::Silencer; #[derive(Debug)] pub struct RequireCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, + newly_created: bool, first_require: bool, json: Option<JsonFile>, @@ -1132,3 +1137,29 @@ impl RequireCommand { } } } + +impl BaseCommand for RequireCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/run_script_command.rs b/crates/shirabe/src/command/run_script_command.rs index 09624af..fac896a 100644 --- a/crates/shirabe/src/command/run_script_command.rs +++ b/crates/shirabe/src/command/run_script_command.rs @@ -1,13 +1,16 @@ //! ref: composer/src/Composer/Command/RunScriptCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{InvalidArgumentException, PhpMixed, RuntimeException}; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::script::event::Event as ScriptEvent; use crate::script::script_events::ScriptEvents; use crate::util::platform::Platform; @@ -15,7 +18,10 @@ use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct RunScriptCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, + script_events: Vec<&'static str>, } @@ -249,3 +255,29 @@ impl RunScriptCommand { Ok(result) } } + +impl BaseCommand for RunScriptCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/script_alias_command.rs b/crates/shirabe/src/command/script_alias_command.rs index c5bacc4..a02d646 100644 --- a/crates/shirabe/src/command/script_alias_command.rs +++ b/crates/shirabe/src/command/script_alias_command.rs @@ -1,17 +1,22 @@ //! ref: composer/src/Composer/Command/ScriptAliasCommand.php -use crate::command::base_command::BaseCommand; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::util::platform::Platform; +use crate::{command::base_command::BaseCommand, composer::Composer}; use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use shirabe_php_shim::{InvalidArgumentException, LogicException, PhpMixed, is_string}; pub struct ScriptAliasCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, + script: String, description: String, aliases: Vec<String>, @@ -125,3 +130,29 @@ impl ScriptAliasCommand { )?) } } + +impl BaseCommand for ScriptAliasCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs index 2e9de04..28f4fd1 100644 --- a/crates/shirabe/src/command/search_command.rs +++ b/crates/shirabe/src/command/search_command.rs @@ -1,16 +1,18 @@ //! ref: composer/src/Composer/Command/SearchCommand.php -use crate::command::base_command::BaseCommand; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::plugin::command_event::CommandEvent; use crate::plugin::plugin_events::PluginEvents; use crate::repository::composite_repository::CompositeRepository; use crate::repository::platform_repository::PlatformRepository; use crate::repository::repository_interface::RepositoryInterface; +use crate::{command::base_command::BaseCommand, composer::Composer}; use anyhow::Result; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::formatter::output_formatter::OutputFormatter; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; @@ -18,7 +20,9 @@ use shirabe_php_shim::{InvalidArgumentException, PhpMixed, implode, in_array, pr #[derive(Debug)] pub struct SearchCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl SearchCommand { @@ -177,3 +181,29 @@ impl SearchCommand { Ok(0) } } + +impl BaseCommand for SearchCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/self_update_command.rs b/crates/shirabe/src/command/self_update_command.rs index f69476d..b1b0c06 100644 --- a/crates/shirabe/src/command/self_update_command.rs +++ b/crates/shirabe/src/command/self_update_command.rs @@ -2,6 +2,7 @@ use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::component::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::component::console::output::output_interface::OutputInterface; use shirabe_external_packages::symfony::component::finder::finder::Finder; @@ -32,7 +33,9 @@ use crate::util::platform::Platform; #[derive(Debug)] pub struct SelfUpdateCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl SelfUpdateCommand { @@ -1178,3 +1181,29 @@ RGv89BPD+2DLnJysngsvVaUCAwEAAQ==\n\ result } } + +impl BaseCommand for SelfUpdateCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index 8b5e967..52d2bd7 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -4,6 +4,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::composer::semver::semver::Semver; use shirabe_external_packages::composer::spdx_licenses::spdx_licenses::SpdxLicenses; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::completion::completion_input::CompletionInput; use shirabe_external_packages::symfony::console::formatter::output_formatter::OutputFormatter; use shirabe_external_packages::symfony::console::formatter::output_formatter_style::OutputFormatterStyle; @@ -50,7 +51,10 @@ const _INPUT_OPTION_REF: i64 = InputOption::VALUE_NONE; #[derive(Debug)] pub struct ShowCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, + pub(crate) version_parser: VersionParser, pub(crate) colors: Vec<String>, repository_set: Option<RepositorySet>, @@ -2640,6 +2644,32 @@ impl ShowCommand { impl CompletionTrait for ShowCommand {} +impl BaseCommand for ShowCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} + #[derive(Debug)] pub enum PackageOrName { Pkg(Box<dyn PackageInterface>), diff --git a/crates/shirabe/src/command/status_command.rs b/crates/shirabe/src/command/status_command.rs index ff6675d..e4f25cd 100644 --- a/crates/shirabe/src/command/status_command.rs +++ b/crates/shirabe/src/command/status_command.rs @@ -2,11 +2,14 @@ use anyhow::Result; use indexmap::IndexMap; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_option::InputOption; +use crate::io::io_interface::IOInterface; use crate::package::dumper::array_dumper::ArrayDumper; use crate::package::version::version_guesser::VersionGuesser; use crate::package::version::version_parser::VersionParser; @@ -17,7 +20,9 @@ use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct StatusCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl StatusCommand { @@ -301,3 +306,29 @@ impl StatusCommand { Ok(exit_code) } } + +impl BaseCommand for StatusCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/suggests_command.rs b/crates/shirabe/src/command/suggests_command.rs index efa0ce2..317b9c4 100644 --- a/crates/shirabe/src/command/suggests_command.rs +++ b/crates/shirabe/src/command/suggests_command.rs @@ -2,20 +2,27 @@ use crate::command::base_command::BaseCommand; use crate::command::completion_trait::CompletionTrait; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::installer::suggested_packages_reporter::SuggestedPackagesReporter; +use crate::io::io_interface::IOInterface; use crate::repository::installed_repository::InstalledRepository; use crate::repository::platform_repository::PlatformRepository; use crate::repository::root_package_repository::RootPackageRepository; use anyhow::Result; -use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; +use shirabe_external_packages::symfony::{ + component::console::command::command::Command, console::input::input_interface::InputInterface, +}; use shirabe_php_shim::{PhpMixed, empty, in_array}; #[derive(Debug)] pub struct SuggestsCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, + completion_trait: CompletionTrait, } @@ -112,3 +119,29 @@ impl SuggestsCommand { Ok(0) } } + +impl BaseCommand for SuggestsCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs index 0311cec..aeeb7ba 100644 --- a/crates/shirabe/src/command/update_command.rs +++ b/crates/shirabe/src/command/update_command.rs @@ -37,7 +37,9 @@ use crate::util::http_downloader::HttpDownloader; #[derive(Debug)] pub struct UpdateCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl CompletionTrait for UpdateCommand {} @@ -623,3 +625,29 @@ impl UpdateCommand { VersionSelector::new(repository_set) } } + +impl BaseCommand for UpdateCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/command/validate_command.rs b/crates/shirabe/src/command/validate_command.rs index e95e5ca..5906aaa 100644 --- a/crates/shirabe/src/command/validate_command.rs +++ b/crates/shirabe/src/command/validate_command.rs @@ -1,10 +1,12 @@ //! ref: composer/src/Composer/Command/ValidateCommand.php use anyhow::Result; +use shirabe_external_packages::symfony::component::console::command::command::Command; use shirabe_external_packages::symfony::console::input::input_interface::InputInterface; use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface; use crate::command::base_command::BaseCommand; +use crate::composer::Composer; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::factory::Factory; @@ -17,7 +19,9 @@ use crate::util::filesystem::Filesystem; #[derive(Debug)] pub struct ValidateCommand { - inner: BaseCommand, + inner: Command, + composer: Option<Composer>, + io: Option<Box<dyn IOInterface>>, } impl ValidateCommand { @@ -330,3 +334,29 @@ impl ValidateCommand { } } } + +impl BaseCommand for ValidateCommand { + fn inner(&self) -> &Command { + &self.inner + } + + fn inner_mut(&mut self) -> &mut Command { + &mut self.inner + } + + fn composer(&self) -> Option<&Composer> { + self.composer.as_ref() + } + + fn composer_mut(&mut self) -> &mut Option<Composer> { + &mut self.composer + } + + fn io(&self) -> Option<&dyn IOInterface> { + self.io.as_deref() + } + + fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { + &mut self.io + } +} diff --git a/crates/shirabe/src/dependency_resolver/generic_rule.rs b/crates/shirabe/src/dependency_resolver/generic_rule.rs index f30d612..23d1e3c 100644 --- a/crates/shirabe/src/dependency_resolver/generic_rule.rs +++ b/crates/shirabe/src/dependency_resolver/generic_rule.rs @@ -2,19 +2,16 @@ use crate::dependency_resolver::rule::Rule; use anyhow::Result; -use shirabe_php_shim::{PHP_VERSION_ID, RuntimeException, hash_raw, implode, unpack}; +use shirabe_php_shim::{PHP_VERSION_ID, PhpMixed, RuntimeException, hash_raw, implode, unpack}; + +use super::{request::Request, rule::ReasonData}; pub struct GenericRule { - inner: Rule, pub(crate) literals: Vec<i64>, } impl GenericRule { - pub fn new( - mut literals: Vec<i64>, - reason: shirabe_php_shim::PhpMixed, - reason_data: shirabe_php_shim::PhpMixed, - ) -> Self { + pub fn new(mut literals: Vec<i64>, reason: PhpMixed, reason_data: PhpMixed) -> Self { let inner = Rule::new(reason, reason_data); literals.sort(); Self { inner, literals } @@ -96,3 +93,49 @@ impl RuleLiterals for GenericRule { &self.literals } } + +impl Rule for GenericRule { + fn bitfield(&self) -> i64 { + todo!() + } + + fn bitfield_mut(&mut self) -> &mut i64 { + todo!() + } + + fn request(&self) -> Option<&Request> { + todo!() + } + + fn request_mut(&mut self) -> Option<&mut Request> { + todo!() + } + + fn reason_data(&self) -> Option<&ReasonData> { + todo!() + } + + fn reason_data_mut(&mut self) -> Option<&mut ReasonData> { + todo!() + } + + fn get_literals(&self) -> Vec<i64> { + todo!() + } + + fn get_hash(&self) -> PhpMixed { + todo!() + } + + fn to_string(&self) -> String { + todo!() + } + + fn equals(&self, rule: &dyn Rule) -> bool { + todo!() + } + + fn is_assertion(&self) -> bool { + todo!() + } +} diff --git a/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs b/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs index b15434e..981a522 100644 --- a/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs +++ b/crates/shirabe/src/dependency_resolver/multi_conflict_rule.rs @@ -7,7 +7,6 @@ use shirabe_php_shim::{PHP_VERSION_ID, RuntimeException, hash_raw}; #[derive(Debug)] pub struct MultiConflictRule { - inner: Rule, pub(crate) literals: Vec<i64>, } @@ -118,3 +117,49 @@ impl RuleLiterals for MultiConflictRule { true } } + +impl Rule for MultiConflictRule { + fn bitfield(&self) -> i64 { + todo!() + } + + fn bitfield_mut(&mut self) -> &mut i64 { + todo!() + } + + fn request(&self) -> Option<&Request> { + todo!() + } + + fn request_mut(&mut self) -> Option<&mut Request> { + todo!() + } + + fn reason_data(&self) -> Option<&ReasonData> { + todo!() + } + + fn reason_data_mut(&mut self) -> Option<&mut ReasonData> { + todo!() + } + + fn get_literals(&self) -> Vec<i64> { + todo!() + } + + fn get_hash(&self) -> PhpMixed { + todo!() + } + + fn to_string(&self) -> String { + todo!() + } + + fn equals(&self, rule: &dyn Rule) -> bool { + todo!() + } + + fn is_assertion(&self) -> bool { + todo!() + } +} diff --git a/crates/shirabe/src/dependency_resolver/rule2_literals.rs b/crates/shirabe/src/dependency_resolver/rule2_literals.rs index e86c93d..50ae77b 100644 --- a/crates/shirabe/src/dependency_resolver/rule2_literals.rs +++ b/crates/shirabe/src/dependency_resolver/rule2_literals.rs @@ -5,7 +5,6 @@ use crate::dependency_resolver::rule::Rule; #[derive(Debug)] pub struct Rule2Literals { - inner: Rule, pub(crate) literal1: i64, pub(crate) literal2: i64, literals: Vec<i64>, @@ -71,3 +70,49 @@ impl RuleLiterals for Rule2Literals { &self.literals } } + +impl Rule for Rule2Literals { + fn bitfield(&self) -> i64 { + todo!() + } + + fn bitfield_mut(&mut self) -> &mut i64 { + todo!() + } + + fn request(&self) -> Option<&Request> { + todo!() + } + + fn request_mut(&mut self) -> Option<&mut Request> { + todo!() + } + + fn reason_data(&self) -> Option<&ReasonData> { + todo!() + } + + fn reason_data_mut(&mut self) -> Option<&mut ReasonData> { + todo!() + } + + fn get_literals(&self) -> Vec<i64> { + todo!() + } + + fn get_hash(&self) -> PhpMixed { + todo!() + } + + fn to_string(&self) -> String { + todo!() + } + + fn equals(&self, rule: &dyn Rule) -> bool { + todo!() + } + + fn is_assertion(&self) -> bool { + todo!() + } +} diff --git a/crates/shirabe/src/downloader/fossil_downloader.rs b/crates/shirabe/src/downloader/fossil_downloader.rs index a686177..5314e10 100644 --- a/crates/shirabe/src/downloader/fossil_downloader.rs +++ b/crates/shirabe/src/downloader/fossil_downloader.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Downloader/FossilDownloader.php -use crate::downloader::vcs_downloader::VcsDownloader; +use crate::downloader::vcs_downloader::VcsDownloaderBase; use crate::package::package_interface::PackageInterface; use anyhow::Result; use shirabe_external_packages::composer::pcre::preg::Preg; @@ -9,7 +9,7 @@ use shirabe_php_shim::RuntimeException; #[derive(Debug)] pub struct FossilDownloader { - inner: VcsDownloader, + inner: VcsDownloaderBase, } impl FossilDownloader { diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs index 97d0ee9..1bc0ff1 100644 --- a/crates/shirabe/src/downloader/git_downloader.rs +++ b/crates/shirabe/src/downloader/git_downloader.rs @@ -13,7 +13,7 @@ use shirabe_php_shim::{ use crate::cache::Cache; use crate::config::Config; use crate::downloader::dvcs_downloader_interface::DvcsDownloaderInterface; -use crate::downloader::vcs_downloader::VcsDownloader; +use crate::downloader::vcs_downloader::VcsDownloaderBase; use crate::io::io_interface::IOInterface; use crate::package::package_interface::PackageInterface; use crate::util::filesystem::Filesystem; @@ -24,7 +24,7 @@ use crate::util::url::Url; #[derive(Debug)] pub struct GitDownloader { - inner: VcsDownloader, + inner: VcsDownloaderBase, /// @var array<string, bool> has_stashed_changes: IndexMap<String, bool>, /// @var array<string, bool> @@ -41,7 +41,7 @@ impl GitDownloader { process: Option<ProcessExecutor>, fs: Option<Filesystem>, ) -> Self { - let inner = VcsDownloader::new(io, config, process, fs); + let inner = VcsDownloaderBase::new(io, config, process, fs); let git_util = GitUtil::new(&*inner.io, &inner.config, &inner.process, &inner.filesystem); Self { inner, diff --git a/crates/shirabe/src/downloader/gzip_downloader.rs b/crates/shirabe/src/downloader/gzip_downloader.rs index 81fdbed..ca50827 100644 --- a/crates/shirabe/src/downloader/gzip_downloader.rs +++ b/crates/shirabe/src/downloader/gzip_downloader.rs @@ -1,9 +1,11 @@ //! ref: composer/src/Composer/Downloader/GzipDownloader.php use crate::downloader::archive_downloader::ArchiveDownloader; +use crate::downloader::file_downloader::FileDownloader; use crate::package::package_interface::PackageInterface; use crate::util::platform::Platform; use anyhow::Result; +use indexmap::IndexMap; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; use shirabe_php_shim::{ DIRECTORY_SEPARATOR, PATHINFO_FILENAME, PHP_URL_PATH, RuntimeException, extension_loaded, @@ -11,7 +13,8 @@ use shirabe_php_shim::{ }; pub struct GzipDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap<String, bool>, } impl GzipDownloader { diff --git a/crates/shirabe/src/downloader/hg_downloader.rs b/crates/shirabe/src/downloader/hg_downloader.rs index ff06806..1b4204f 100644 --- a/crates/shirabe/src/downloader/hg_downloader.rs +++ b/crates/shirabe/src/downloader/hg_downloader.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Downloader/HgDownloader.php -use crate::downloader::vcs_downloader::VcsDownloader; +use crate::downloader::vcs_downloader::VcsDownloaderBase; use crate::package::package_interface::PackageInterface; use crate::util::hg::Hg as HgUtils; use anyhow::Result; @@ -9,7 +9,7 @@ use shirabe_php_shim::RuntimeException; #[derive(Debug)] pub struct HgDownloader { - inner: VcsDownloader, + inner: VcsDownloaderBase, } impl HgDownloader { diff --git a/crates/shirabe/src/downloader/perforce_downloader.rs b/crates/shirabe/src/downloader/perforce_downloader.rs index 8674b3d..b10e27f 100644 --- a/crates/shirabe/src/downloader/perforce_downloader.rs +++ b/crates/shirabe/src/downloader/perforce_downloader.rs @@ -1,6 +1,6 @@ //! ref: composer/src/Composer/Downloader/PerforceDownloader.php -use crate::downloader::vcs_downloader::VcsDownloader; +use crate::downloader::vcs_downloader::VcsDownloaderBase; use crate::package::package_interface::PackageInterface; use crate::repository::vcs_repository::VcsRepository; use crate::util::perforce::Perforce; @@ -12,7 +12,7 @@ use std::any::Any; #[derive(Debug)] pub struct PerforceDownloader { - inner: VcsDownloader, + inner: VcsDownloaderBase, pub(crate) perforce: Option<Perforce>, } diff --git a/crates/shirabe/src/downloader/phar_downloader.rs b/crates/shirabe/src/downloader/phar_downloader.rs index 8fea679..5316fc1 100644 --- a/crates/shirabe/src/downloader/phar_downloader.rs +++ b/crates/shirabe/src/downloader/phar_downloader.rs @@ -1,14 +1,17 @@ //! ref: composer/src/Composer/Downloader/PharDownloader.php use crate::downloader::archive_downloader::ArchiveDownloader; +use crate::downloader::file_downloader::FileDownloader; use crate::package::package_interface::PackageInterface; use anyhow::Result; +use indexmap::IndexMap; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; use shirabe_php_shim::Phar; #[derive(Debug)] pub struct PharDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap<String, bool>, } impl PharDownloader { diff --git a/crates/shirabe/src/downloader/rar_downloader.rs b/crates/shirabe/src/downloader/rar_downloader.rs index 1b4767f..308b6fa 100644 --- a/crates/shirabe/src/downloader/rar_downloader.rs +++ b/crates/shirabe/src/downloader/rar_downloader.rs @@ -1,17 +1,20 @@ //! ref: composer/src/Composer/Downloader/RarDownloader.php use crate::downloader::archive_downloader::ArchiveDownloader; +use crate::downloader::file_downloader::FileDownloader; use crate::package::package_interface::PackageInterface; use crate::util::ini_helper::IniHelper; use crate::util::platform::Platform; use anyhow::Result; +use indexmap::IndexMap; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; use shirabe_php_shim::{ RarArchive, RuntimeException, UnexpectedValueException, class_exists, implode, }; pub struct RarDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap<String, bool>, } impl RarDownloader { diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs index 30a64f2..ef006f3 100644 --- a/crates/shirabe/src/downloader/svn_downloader.rs +++ b/crates/shirabe/src/downloader/svn_downloader.rs @@ -5,7 +5,7 @@ use shirabe_external_packages::react::promise; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; use shirabe_php_shim::{PhpMixed, RuntimeException, is_dir, version_compare}; -use crate::downloader::vcs_downloader::VcsDownloader; +use crate::downloader::vcs_downloader::VcsDownloaderBase; use crate::io::io_interface::IOInterface; use crate::package::package_interface::PackageInterface; use crate::repository::vcs_repository::VcsRepository; @@ -13,7 +13,7 @@ use crate::util::svn::Svn as SvnUtil; #[derive(Debug)] pub struct SvnDownloader { - inner: VcsDownloader, + inner: VcsDownloaderBase, pub(crate) cache_credentials: bool, } diff --git a/crates/shirabe/src/downloader/tar_downloader.rs b/crates/shirabe/src/downloader/tar_downloader.rs index c327ca0..d8531e0 100644 --- a/crates/shirabe/src/downloader/tar_downloader.rs +++ b/crates/shirabe/src/downloader/tar_downloader.rs @@ -1,14 +1,17 @@ //! ref: composer/src/Composer/Downloader/TarDownloader.php use crate::downloader::archive_downloader::ArchiveDownloader; +use crate::downloader::file_downloader::FileDownloader; use crate::package::package_interface::PackageInterface; use anyhow::Result; +use indexmap::IndexMap; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; use shirabe_php_shim::PharData; #[derive(Debug)] pub struct TarDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap<String, bool>, } impl TarDownloader { diff --git a/crates/shirabe/src/downloader/vcs_downloader.rs b/crates/shirabe/src/downloader/vcs_downloader.rs index b76c242..9ec86ff 100644 --- a/crates/shirabe/src/downloader/vcs_downloader.rs +++ b/crates/shirabe/src/downloader/vcs_downloader.rs @@ -23,6 +23,34 @@ use crate::package::version::version_parser::VersionParser; use crate::util::filesystem::Filesystem; use crate::util::process_executor::ProcessExecutor; +#[derive(Debug)] +pub struct VcsDownloaderBase { + pub io: Box<dyn IOInterface>, + pub config: Config, + pub process: ProcessExecutor, + pub filesystem: Filesystem, + pub has_cleaned_changes: IndexMap<String, bool>, +} + +impl VcsDownloaderBase { + pub fn new( + io: Box<dyn IOInterface>, + config: Config, + process: Option<ProcessExecutor>, + fs: Option<Filesystem>, + ) -> Self { + let process = process.unwrap_or_else(|| ProcessExecutor::new(None, None)); + let filesystem = fs.unwrap_or_else(|| Filesystem::new(None)); + Self { + io, + config, + process, + filesystem, + has_cleaned_changes: IndexMap::new(), + } + } +} + pub trait VcsDownloader: DownloaderInterface + ChangeReportInterface + VcsCapableDownloaderInterface { diff --git a/crates/shirabe/src/downloader/xz_downloader.rs b/crates/shirabe/src/downloader/xz_downloader.rs index 0c5d876..1ad0bb1 100644 --- a/crates/shirabe/src/downloader/xz_downloader.rs +++ b/crates/shirabe/src/downloader/xz_downloader.rs @@ -1,13 +1,16 @@ //! ref: composer/src/Composer/Downloader/XzDownloader.php use crate::downloader::archive_downloader::ArchiveDownloader; +use crate::downloader::file_downloader::FileDownloader; use crate::package::package_interface::PackageInterface; use anyhow::{Result, bail}; +use indexmap::IndexMap; use shirabe_external_packages::react::promise::promise_interface::PromiseInterface; #[derive(Debug)] pub struct XzDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap<String, bool>, } impl XzDownloader { diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs index ecb7821..90e5639 100644 --- a/crates/shirabe/src/downloader/zip_downloader.rs +++ b/crates/shirabe/src/downloader/zip_downloader.rs @@ -24,7 +24,8 @@ static IS_WINDOWS: Mutex<Option<bool>> = Mutex::new(None); #[derive(Debug)] pub struct ZipDownloader { - inner: ArchiveDownloader, + inner: FileDownloader, + cleanup_executed: IndexMap<String, bool>, // @phpstan-ignore property.onlyRead (helper property that is set via reflection for testing purposes) zip_archive_object: Option<ZipArchive>, } diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs index 0794ca5..f2c09ac 100644 --- a/crates/shirabe/src/io/console_io.rs +++ b/crates/shirabe/src/io/console_io.rs @@ -24,7 +24,8 @@ use crate::util::silencer::Silencer; /// The Input/Output helper. #[derive(Debug)] pub struct ConsoleIO { - pub(crate) inner: BaseIO, + authentications: index::IndexMap<String, indexmap::IndexMap<String, Option<String>>>, + pub(crate) input: Box<dyn InputInterface>, pub(crate) output: Box<dyn OutputInterface>, pub(crate) helper_set: HelperSet, @@ -567,3 +568,17 @@ impl ConsoleIO { } } } + +impl BaseIO for ConsoleIO { + fn authentications( + &self, + ) -> &indexmap::IndexMap<String, indexmap::IndexMap<String, Option<String>>> { + &self.authentications + } + + fn authentications_mut( + &mut self, + ) -> &mut indexmap::IndexMap<String, indexmap::IndexMap<String, Option<String>>> { + &mut self.authentications + } +} diff --git a/crates/shirabe/src/io/null_io.rs b/crates/shirabe/src/io/null_io.rs index 4218398..af0296d 100644 --- a/crates/shirabe/src/io/null_io.rs +++ b/crates/shirabe/src/io/null_io.rs @@ -6,7 +6,7 @@ use shirabe_php_shim::PhpMixed; #[derive(Debug)] pub struct NullIO { - inner: BaseIO, + authentications: index::IndexMap<String, indexmap::IndexMap<String, Option<String>>>, } impl IOInterface for NullIO { @@ -79,3 +79,17 @@ impl IOInterface for NullIO { default } } + +impl BaseIO for NullIO { + fn authentications( + &self, + ) -> &indexmap::IndexMap<String, indexmap::IndexMap<String, Option<String>>> { + &self.authentications + } + + fn authentications_mut( + &mut self, + ) -> &mut indexmap::IndexMap<String, indexmap::IndexMap<String, Option<String>>> { + &mut self.authentications + } +} diff --git a/crates/shirabe/src/package/alias_package.rs b/crates/shirabe/src/package/alias_package.rs index a101a1f..a427913 100644 --- a/crates/shirabe/src/package/alias_package.rs +++ b/crates/shirabe/src/package/alias_package.rs @@ -13,7 +13,11 @@ use crate::repository::repository_interface::RepositoryInterface; #[derive(Debug)] pub struct AliasPackage { - pub(crate) inner: BasePackage, + id: i64, + name: String, + pretty_name: String, + repository: Option<Box<dyn RepositoryInterface>>, + /// @var string pub(crate) version: String, /// @var string @@ -427,3 +431,49 @@ impl PackageInterface for AliasPackage { self.inner.get_repository() } } + +impl BasePackage for AliasPackage { + fn id(&self) -> i64 { + self.id + } + + fn id_mut(&mut self) -> &mut i64 { + &mut self.id + } + + fn name(&self) -> &str { + &self.name + } + + fn name_mut(&mut self) -> &mut String { + &mut self.name + } + + fn pretty_name(&self) -> &str { + &self.pretty_name + } + + fn pretty_name_mut(&mut self) -> &mut String { + &mut self.pretty_name + } + + fn repository_opt(&self) -> Option<&dyn RepositoryInterface> { + self.repository.as_ref() + } + + fn set_repository_box(&mut self, repository: Box<dyn RepositoryInterface>) { + todo!() + } + + fn take_repository(&mut self) -> Option<Box<dyn RepositoryInterface>> { + todo!() + } + + fn as_any(&self) -> &dyn std::any::Any { + todo!() + } + + fn clone_box(&self) -> Box<dyn BasePackage> { + todo!() + } +} diff --git a/crates/shirabe/src/package/archiver/base_exclude_filter.rs b/crates/shirabe/src/package/archiver/base_exclude_filter.rs index 6522d79..c7d2557 100644 --- a/crates/shirabe/src/package/archiver/base_exclude_filter.rs +++ b/crates/shirabe/src/package/archiver/base_exclude_filter.rs @@ -3,6 +3,73 @@ use shirabe_external_packages::composer::pcre::preg::Preg; use shirabe_external_packages::symfony::component::finder::glob::Glob; +#[derive(Debug)] +pub struct BaseExcludeFilterBase { + pub source_path: String, + pub exclude_patterns: Vec<(String, bool, bool)>, +} + +impl BaseExcludeFilterBase { + pub fn new(source_path: String) -> Self { + Self { + source_path, + exclude_patterns: Vec::new(), + } + } + + pub fn parse_lines<F>(&self, lines: Vec<String>, line_parser: F) -> Vec<(String, bool, bool)> + where + F: Fn(&str) -> Option<(String, bool, bool)>, + { + lines + .into_iter() + .filter_map(|line| { + let line = line.trim().to_string(); + if line.is_empty() || line.starts_with('#') { + return None; + } + line_parser(&line) + }) + .collect() + } + + pub fn generate_patterns(&self, rules: Vec<String>) -> Vec<(String, bool, bool)> { + rules + .into_iter() + .map(|rule| Self::generate_pattern(&rule)) + .collect() + } + + pub fn generate_pattern(rule: &str) -> (String, bool, bool) { + let mut negate = false; + let mut pattern = String::new(); + + let mut rule = rule.to_string(); + if !rule.is_empty() && rule.starts_with('!') { + negate = true; + rule = rule.trim_start_matches('!').to_string(); + } + + let first_slash_position = rule.find('/'); + if first_slash_position == Some(0) { + pattern = "^/".to_string(); + } else if first_slash_position.is_none() || first_slash_position == Some(rule.len() - 1) { + pattern = "/".to_string(); + } + + let rule = rule.trim_matches('/'); + + let glob_regex = Glob::to_regex(rule); + let rule_regex = &glob_regex[2..glob_regex.len() - 2]; + + ( + format!("{{{}{}(?=$|/)}}", pattern, rule_regex), + negate, + false, + ) + } +} + pub trait BaseExcludeFilter { fn source_path(&self) -> &str; fn exclude_patterns(&self) -> &[(String, bool, bool)]; diff --git a/crates/shirabe/src/package/archiver/composer_exclude_filter.rs b/crates/shirabe/src/package/archiver/composer_exclude_filter.rs index b9a32f4..979e67e 100644 --- a/crates/shirabe/src/package/archiver/composer_exclude_filter.rs +++ b/crates/shirabe/src/package/archiver/composer_exclude_filter.rs @@ -1,15 +1,15 @@ //! ref: composer/src/Composer/Package/Archiver/ComposerExcludeFilter.php -use super::base_exclude_filter::BaseExcludeFilter; +use super::base_exclude_filter::BaseExcludeFilterBase; #[derive(Debug)] pub struct ComposerExcludeFilter { - inner: BaseExcludeFilter, + inner: BaseExcludeFilterBase, } impl ComposerExcludeFilter { pub fn new(source_path: String, exclude_rules: Vec<String>) -> Self { - let mut inner = BaseExcludeFilter::new(source_path); + let mut inner = BaseExcludeFilterBase::new(source_path); inner.exclude_patterns = inner.generate_patterns(exclude_rules); Self { inner } } diff --git a/crates/shirabe/src/package/archiver/git_exclude_filter.rs b/crates/shirabe/src/package/archiver/git_exclude_filter.rs index 8028c15..dddad12 100644 --- a/crates/shirabe/src/package/archiver/git_exclude_filter.rs +++ b/crates/shirabe/src/package/archiver/git_exclude_filter.rs @@ -1,16 +1,16 @@ //! ref: composer/src/Composer/Package/Archiver/GitExcludeFilter.php -use crate::package::archiver::base_exclude_filter::BaseExcludeFilter; +use crate::package::archiver::base_exclude_filter::BaseExcludeFilterBase; use shirabe_external_packages::composer::pcre::preg::Preg; use std::path::Path; pub struct GitExcludeFilter { - inner: BaseExcludeFilter, + inner: BaseExcludeFilterBase, } impl GitExcludeFilter { pub fn new(source_path: String) -> Self { - let inner = BaseExcludeFilter::new(source_path.clone()); + let inner = BaseExcludeFilterBase::new(source_path.clone()); let mut filter = Self { inner }; let gitattributes_path = format!("{}/.gitattributes", source_path); @@ -37,11 +37,11 @@ impl GitExcludeFilter { let parts = Preg::split(r"\s+", line); if parts.len() == 2 && parts[1] == "export-ignore" { - return BaseExcludeFilter::generate_pattern(&parts[0]); + return Some(BaseExcludeFilterBase::generate_pattern(&parts[0])); } if parts.len() == 2 && parts[1] == "-export-ignore" { - return BaseExcludeFilter::generate_pattern(&format!("!{}", parts[0])); + return BaseExcludeFilterBase::generate_pattern(&format!("!{}", parts[0])); } None diff --git a/crates/shirabe/src/package/package.rs b/crates/shirabe/src/package/package.rs index 81d6131..ae94a20 100644 --- a/crates/shirabe/src/package/package.rs +++ b/crates/shirabe/src/package/package.rs @@ -9,6 +9,7 @@ use shirabe_php_shim::{E_USER_DEPRECATED, PhpMixed, strpos, trigger_error}; use crate::package::base_package::BasePackage; use crate::package::link::Link; use crate::package::version::version_parser::VersionParser; +use crate::repository::repository_interface::RepositoryInterface; /// Mirror entry, e.g. `['url' => 'https://...', 'preferred' => true]`. #[derive(Debug, Clone)] @@ -20,7 +21,11 @@ pub struct Mirror { /// Core package definitions that are needed to resolve dependencies and install packages #[derive(Debug)] pub struct Package { - pub(crate) inner: BasePackage, + id: i64, + name: String, + pretty_name: String, + repository: Option<Box<dyn RepositoryInterface>>, + pub(crate) r#type: Option<String>, pub(crate) target_dir: Option<String>, /// `'source'` | `'dist'` | `null` @@ -523,3 +528,49 @@ impl Package { new_links } } + +impl BasePackage for Package { + fn id(&self) -> i64 { + self.id + } + + fn id_mut(&mut self) -> &mut i64 { + &mut self.id + } + + fn name(&self) -> &str { + &self.name + } + + fn name_mut(&mut self) -> &mut String { + &mut self.name + } + + fn pretty_name(&self) -> &str { + &self.pretty_name + } + + fn pretty_name_mut(&mut self) -> &mut String { + &mut self.pretty_name + } + + fn repository_opt(&self) -> Option<&dyn RepositoryInterface> { + self.repository.as_ref() + } + + fn set_repository_box(&mut self, repository: Box<dyn RepositoryInterface>) { + todo!() + } + + fn take_repository(&mut self) -> Option<Box<dyn RepositoryInterface>> { + todo!() + } + + fn as_any(&self) -> &dyn std::any::Any { + todo!() + } + + fn clone_box(&self) -> Box<dyn BasePackage> { + todo!() + } +} diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs index 74f1e11..c03f217 100644 --- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs +++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs @@ -13,7 +13,7 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::forgejo::Forgejo; use crate::util::forgejo_repository_data::ForgejoRepositoryData; use crate::util::forgejo_url::ForgejoUrl; @@ -21,7 +21,7 @@ use crate::util::http::response::Response; #[derive(Debug)] pub struct ForgejoDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) forgejo_url: Option<ForgejoUrl>, pub(crate) repository_data: Option<ForgejoRepositoryData>, pub(crate) git_driver: Option<GitDriver>, @@ -500,7 +500,7 @@ impl ForgejoDriver { fn setup_git_driver(&mut self, url: &str) -> Result<()> { let mut git_driver = GitDriver { - inner: VcsDriver::new( + inner: VcsDriverBase::new( { let mut m = IndexMap::new(); m.insert("url".to_string(), PhpMixed::String(url.to_string())); diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs index 6e99f5f..f1e6a89 100644 --- a/crates/shirabe/src/repository/vcs/fossil_driver.rs +++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs @@ -8,13 +8,13 @@ use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_file, is_ use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct FossilDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) tags: Option<IndexMap<String, String>>, pub(crate) branches: Option<IndexMap<String, String>>, pub(crate) root_identifier: Option<String>, diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index dc3b5f3..0e16ced 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -16,14 +16,14 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::repository::vcs::vcs_driver_interface::VcsDriverInterface; use crate::util::bitbucket::Bitbucket; use crate::util::http::response::Response; #[derive(Debug)] pub struct GitBitbucketDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, /// @var string pub(crate) owner: String, /// @var string diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs index 0f8f841..48aa4c1 100644 --- a/crates/shirabe/src/repository/vcs/git_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_driver.rs @@ -12,7 +12,7 @@ use shirabe_php_shim::{ use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::git::Git as GitUtil; use crate::util::process_executor::ProcessExecutor; @@ -20,7 +20,7 @@ use crate::util::url::Url; #[derive(Debug)] pub struct GitDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) tags: Option<IndexMap<String, String>>, pub(crate) branches: Option<IndexMap<String, String>>, pub(crate) root_identifier: Option<String>, diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index bd2e2ad..233e3ea 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -16,13 +16,13 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::github::GitHub; use crate::util::http::response::Response; #[derive(Debug)] pub struct GitHubDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) owner: String, pub(crate) repository: String, /// @var array<int|string, string> Map of tag name to identifier diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index cb0d0a2..583f221 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -16,7 +16,7 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::gitlab::GitLab; use crate::util::http::response::Response; use crate::util::http_downloader::HttpDownloader; @@ -24,7 +24,7 @@ use crate::util::http_downloader::HttpDownloader; /// Driver for GitLab API, use the Git driver for local checkouts. #[derive(Debug)] pub struct GitLabDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, /// @phpstan-var 'https'|'http' scheme: String, namespace: String, diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs index 6b32a0a..a8fc70a 100644 --- a/crates/shirabe/src/repository/vcs/hg_driver.rs +++ b/crates/shirabe/src/repository/vcs/hg_driver.rs @@ -3,7 +3,7 @@ use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::hg::Hg as HgUtils; use crate::util::url::Url; @@ -14,7 +14,7 @@ use shirabe_php_shim::{RuntimeException, dirname, is_dir, is_writable}; #[derive(Debug)] pub struct HgDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) tags: Option<IndexMap<String, String>>, pub(crate) branches: Option<IndexMap<String, String>>, pub(crate) root_identifier: Option<String>, diff --git a/crates/shirabe/src/repository/vcs/perforce_driver.rs b/crates/shirabe/src/repository/vcs/perforce_driver.rs index cd3b32b..ee09dee 100644 --- a/crates/shirabe/src/repository/vcs/perforce_driver.rs +++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs @@ -7,14 +7,14 @@ use shirabe_php_shim::{BadMethodCallException, PhpMixed, RuntimeException}; use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::http::response::Response; use crate::util::perforce::Perforce; use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct PerforceDriver { - inner: VcsDriver, + inner: VcsDriverBase, pub(crate) depot: String, pub(crate) branch: String, pub(crate) perforce: Option<Perforce>, diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index 7c32e4a..0a05d84 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -14,7 +14,7 @@ use crate::config::Config; use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::process_executor::ProcessExecutor; use crate::util::svn::Svn as SvnUtil; @@ -22,7 +22,7 @@ use crate::util::url::Url; #[derive(Debug)] pub struct SvnDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, /// @var string pub(crate) base_url: String, /// @var array<int|string, string> Map of tag name to identifier diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs index 3195822..162792e 100644 --- a/crates/shirabe/src/repository/vcs/vcs_driver.rs +++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs @@ -17,6 +17,67 @@ use crate::util::http::response::Response; use crate::util::http_downloader::HttpDownloader; use crate::util::process_executor::ProcessExecutor; +#[derive(Debug)] +pub struct VcsDriverBase { + pub url: String, + pub origin_url: String, + pub repo_config: IndexMap<String, PhpMixed>, + pub io: Box<dyn IOInterface>, + pub config: Config, + pub process: ProcessExecutor, + pub http_downloader: HttpDownloader, + pub info_cache: IndexMap<String, Option<IndexMap<String, PhpMixed>>>, + pub cache: Option<Cache>, +} + +impl VcsDriverBase { + pub fn new( + repo_config: IndexMap<String, PhpMixed>, + io: Box<dyn IOInterface>, + config: Config, + http_downloader: HttpDownloader, + process: ProcessExecutor, + ) -> Self { + let url = repo_config + .get("url") + .and_then(|v| v.as_string()) + .unwrap_or("") + .to_string(); + let origin_url = url.clone(); + Self { + url, + origin_url, + repo_config, + io, + config, + process, + http_downloader, + info_cache: IndexMap::new(), + cache: None, + } + } + + pub fn should_cache(&self, identifier: &str) -> bool { + self.cache.is_some() && Preg::is_match("{^[a-f0-9]{40}$}iD", identifier).unwrap_or(false) + } + + pub fn get_scheme(&self) -> &str { + if extension_loaded("openssl") { + return "https"; + } + "http" + } + + pub fn get_contents(&self, url: &str) -> anyhow::Result<Response, TransportException> { + let options = self + .repo_config + .get("options") + .cloned() + .unwrap_or(PhpMixed::Array(IndexMap::new())); + self.http_downloader.get(url, &options) + } +} + // TODO(phase-b): the constructor is `final` in PHP; concrete implementations must replicate the // initialization logic (local-path normalization etc.) from the original new() body. pub trait VcsDriver: VcsDriverInterface { |
