diff options
Diffstat (limited to 'crates/shirabe/src/command/install_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/install_command.rs | 118 |
1 files changed, 40 insertions, 78 deletions
diff --git a/crates/shirabe/src/command/install_command.rs b/crates/shirabe/src/command/install_command.rs index eac04c3..2b9a87d 100644 --- a/crates/shirabe/src/command/install_command.rs +++ b/crates/shirabe/src/command/install_command.rs @@ -1,16 +1,12 @@ //! 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::component::console::command::command::CommandBase; 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; use crate::advisory::auditor::Auditor; -use crate::command::base_command::BaseCommand; -use crate::command::completion_trait::CompletionTrait; -use crate::composer::Composer; +use crate::command::base_command::{BaseCommand, BaseCommandData, HasBaseCommandData}; use crate::console::input::input_argument::InputArgument; use crate::console::input::input_option::InputOption; use crate::installer::Installer; @@ -21,51 +17,39 @@ use crate::util::http_downloader::HttpDownloader; #[derive(Debug)] pub struct InstallCommand { - inner: CommandBase, - composer: Option<Composer>, - io: Option<Box<dyn IOInterface>>, -} - -impl CompletionTrait for InstallCommand { - fn require_composer( - &self, - disable_plugins: Option<bool>, - disable_scripts: Option<bool>, - ) -> Composer { - todo!() - } + base_command_data: BaseCommandData, } impl InstallCommand { pub fn configure(&mut self) { - let suggest_prefer_install = self.suggest_prefer_install(); - self.inner + // TODO(cli-completion): suggest_prefer_install() for `prefer-install` option + self .set_name("install") - .set_aliases(vec!["i".to_string()]) + .set_aliases(&["i".to_string()]) .set_description("Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json") .set_definition(vec![ - InputOption::new("prefer-source", None, Some(InputOption::VALUE_NONE), "Forces installation from package sources when possible, including VCS information.", None, vec![]), - InputOption::new("prefer-dist", None, Some(InputOption::VALUE_NONE), "Forces installation from package dist (default behavior).", None, vec![]), - InputOption::new("prefer-install", None, Some(InputOption::VALUE_REQUIRED), "Forces installation from package dist|source|auto (auto chooses source for dev versions, dist for the rest).", None, suggest_prefer_install), - InputOption::new("dry-run", None, Some(InputOption::VALUE_NONE), "Outputs the operations but will not execute anything (implicitly enables --verbose).", None, vec![]), - InputOption::new("download-only", None, Some(InputOption::VALUE_NONE), "Download only, do not install packages.", None, vec![]), - InputOption::new("dev", None, Some(InputOption::VALUE_NONE), "DEPRECATED: Enables installation of require-dev packages (enabled by default, only present for BC).", None, vec![]), - InputOption::new("no-suggest", None, Some(InputOption::VALUE_NONE), "DEPRECATED: This flag does not exist anymore.", None, vec![]), - InputOption::new("no-dev", None, Some(InputOption::VALUE_NONE), "Disables installation of require-dev packages.", None, vec![]), - InputOption::new("no-security-blocking", None, Some(InputOption::VALUE_NONE), "Allows installing packages with security advisories or that are abandoned (can also be set via the COMPOSER_NO_SECURITY_BLOCKING=1 env var). Only applies when no lock file is present.", None, vec![]), - InputOption::new("no-autoloader", None, Some(InputOption::VALUE_NONE), "Skips autoloader generation", None, vec![]), - InputOption::new("no-progress", None, Some(InputOption::VALUE_NONE), "Do not output download progress.", None, vec![]), - InputOption::new("no-install", None, Some(InputOption::VALUE_NONE), "Do not use, only defined here to catch misuse of the install command.", None, vec![]), - InputOption::new("audit", None, Some(InputOption::VALUE_NONE), "Run an audit after installation is complete.", None, vec![]), - InputOption::new("audit-format", None, Some(InputOption::VALUE_REQUIRED), "Audit output format. Must be \"table\", \"plain\", \"json\", or \"summary\".", Some(PhpMixed::String(Auditor::FORMAT_SUMMARY.to_string())), Auditor::FORMATS.iter().map(|s| s.to_string()).collect()), - InputOption::new("verbose", Some(PhpMixed::String("v|vv|vvv".to_string())), Some(InputOption::VALUE_NONE), "Shows more details including new commits pulled in when updating packages.", None, vec![]), - InputOption::new("optimize-autoloader", Some(PhpMixed::String("o".to_string())), Some(InputOption::VALUE_NONE), "Optimize autoloader during autoloader dump", None, vec![]), - InputOption::new("classmap-authoritative", Some(PhpMixed::String("a".to_string())), Some(InputOption::VALUE_NONE), "Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.", None, vec![]), - InputOption::new("apcu-autoloader", None, Some(InputOption::VALUE_NONE), "Use APCu to cache found/not-found classes.", None, vec![]), - InputOption::new("apcu-autoloader-prefix", None, Some(InputOption::VALUE_REQUIRED), "Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader", None, vec![]), - InputOption::new("ignore-platform-req", None, Some(InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY), "Ignore a specific platform requirement (php & ext- packages).", None, vec![]), - InputOption::new("ignore-platform-reqs", None, Some(InputOption::VALUE_NONE), "Ignore all platform requirements (php & ext- packages).", None, vec![]), - InputArgument::new("packages", Some(InputArgument::IS_ARRAY | InputArgument::OPTIONAL), "Should not be provided, use composer require instead to add a given package to composer.json.", None, vec![]), + InputOption::new("prefer-source", None, Some(InputOption::VALUE_NONE), "Forces installation from package sources when possible, including VCS information.", None), + InputOption::new("prefer-dist", None, Some(InputOption::VALUE_NONE), "Forces installation from package dist (default behavior).", None), + InputOption::new("prefer-install", None, Some(InputOption::VALUE_REQUIRED), "Forces installation from package dist|source|auto (auto chooses source for dev versions, dist for the rest).", None), + InputOption::new("dry-run", None, Some(InputOption::VALUE_NONE), "Outputs the operations but will not execute anything (implicitly enables --verbose).", None), + InputOption::new("download-only", None, Some(InputOption::VALUE_NONE), "Download only, do not install packages.", None), + InputOption::new("dev", None, Some(InputOption::VALUE_NONE), "DEPRECATED: Enables installation of require-dev packages (enabled by default, only present for BC).", None), + InputOption::new("no-suggest", None, Some(InputOption::VALUE_NONE), "DEPRECATED: This flag does not exist anymore.", None), + InputOption::new("no-dev", None, Some(InputOption::VALUE_NONE), "Disables installation of require-dev packages.", None), + InputOption::new("no-security-blocking", None, Some(InputOption::VALUE_NONE), "Allows installing packages with security advisories or that are abandoned (can also be set via the COMPOSER_NO_SECURITY_BLOCKING=1 env var). Only applies when no lock file is present.", None), + InputOption::new("no-autoloader", None, Some(InputOption::VALUE_NONE), "Skips autoloader generation", None), + InputOption::new("no-progress", None, Some(InputOption::VALUE_NONE), "Do not output download progress.", None), + InputOption::new("no-install", None, Some(InputOption::VALUE_NONE), "Do not use, only defined here to catch misuse of the install command.", None), + InputOption::new("audit", None, Some(InputOption::VALUE_NONE), "Run an audit after installation is complete.", None), + InputOption::new("audit-format", None, Some(InputOption::VALUE_REQUIRED), "Audit output format. Must be \"table\", \"plain\", \"json\", or \"summary\".", Some(PhpMixed::String(Auditor::FORMAT_SUMMARY.to_string()))), + InputOption::new("verbose", Some(PhpMixed::String("v|vv|vvv".to_string())), Some(InputOption::VALUE_NONE), "Shows more details including new commits pulled in when updating packages.", None), + InputOption::new("optimize-autoloader", Some(PhpMixed::String("o".to_string())), Some(InputOption::VALUE_NONE), "Optimize autoloader during autoloader dump", None), + InputOption::new("classmap-authoritative", Some(PhpMixed::String("a".to_string())), Some(InputOption::VALUE_NONE), "Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.", None), + InputOption::new("apcu-autoloader", None, Some(InputOption::VALUE_NONE), "Use APCu to cache found/not-found classes.", None), + InputOption::new("apcu-autoloader-prefix", None, Some(InputOption::VALUE_REQUIRED), "Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader", None), + InputOption::new("ignore-platform-req", None, Some(InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY), "Ignore a specific platform requirement (php & ext- packages).", None), + InputOption::new("ignore-platform-reqs", None, Some(InputOption::VALUE_NONE), "Ignore all platform requirements (php & ext- packages).", None), + InputArgument::new("packages", Some(InputArgument::IS_ARRAY | InputArgument::OPTIONAL), "Should not be provided, use composer require instead to add a given package to composer.json.", None), ]) .set_help( "The <info>install</info> command reads the composer.lock file from\n\ @@ -78,7 +62,7 @@ impl InstallCommand { } pub fn execute(&self, input: &dyn InputInterface, output: &dyn OutputInterface) -> Result<i64> { - let io = self.inner.get_io(); + let io = self.get_io(); if input.get_option("dev").as_bool().unwrap_or(false) { io.write_error("<warning>You are using the deprecated option \"--dev\". It has no effect and will break in Composer 3.</warning>"); @@ -110,7 +94,7 @@ impl InstallCommand { return Ok(1); } - let composer = self.inner.require_composer()?; + let composer = self.require_composer(None, None)?; if !composer.get_locker().is_locked() && !HttpDownloader::is_curl_enabled() { io.write_error("<warning>Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.</warning>"); @@ -120,20 +104,19 @@ impl InstallCommand { let command_event = CommandEvent::new( PluginEvents::COMMAND.to_string(), "install".to_string(), - Box::new(input), - Box::new(output), + input, + output, vec![], vec![], ); composer .get_event_dispatcher() - .dispatch(command_event.get_name(), &command_event); + .dispatch(Some(command_event.get_name()), None); let install = Installer::create(io, &composer); let config = composer.get_config(); - let (prefer_source, prefer_dist) = - self.inner.get_preferred_install_options(config, input)?; + let (prefer_source, prefer_dist) = self.get_preferred_install_options(config, input)?; let optimize = input .get_option("optimize-autoloader") @@ -174,11 +157,8 @@ impl InstallCommand { .set_optimize_autoloader(optimize) .set_class_map_authoritative(authoritative) .set_apcu_autoloader(apcu, apcu_prefix.as_deref()) - .set_platform_requirement_filter(self.inner.get_platform_requirement_filter(input)?) - .set_audit_config( - self.inner - .create_audit_config(composer.get_config(), input)?, - ) + .set_platform_requirement_filter(self.get_platform_requirement_filter(input)?) + .set_audit_config(self.create_audit_config(composer.get_config(), input)?) .set_error_on_audit(input.get_option("audit").as_bool().unwrap_or(false)); if input.get_option("no-plugins").as_bool().unwrap_or(false) { @@ -189,30 +169,12 @@ impl InstallCommand { } } -impl BaseCommand for InstallCommand { - fn inner(&self) -> &CommandBase { - &self.inner - } - - fn inner_mut(&mut self) -> &mut CommandBase { - &mut self.inner - } - - fn composer(&self) -> Option<&Composer> { - self.composer.as_ref() - } - - fn composer_mut(&mut self) -> &mut Option<Composer> { - &mut self.composer +impl HasBaseCommandData for InstallCommand { + fn base_command_data(&self) -> &BaseCommandData { + &self.base_command_data } - fn io(&self) -> Option<&dyn IOInterface> { - self.io.as_deref() - } - - fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> { - &mut self.io + fn base_command_data_mut(&mut self) -> &mut BaseCommandData { + &mut self.base_command_data } } - -impl Command for InstallCommand {} |
