From fd733a87364b877d5e66b4973bd61b5379ec4d61 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 16 Jun 2026 21:59:35 +0900 Subject: feat(command): implement Symfony Command --- crates/shirabe/src/command/update_command.rs | 115 +++++++++++++++++---------- 1 file changed, 73 insertions(+), 42 deletions(-) (limited to 'crates/shirabe/src/command/update_command.rs') diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs index 26b05f5..873b244 100644 --- a/crates/shirabe/src/command/update_command.rs +++ b/crates/shirabe/src/command/update_command.rs @@ -5,6 +5,7 @@ use crate::package::base_package; use anyhow::Result; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; +use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::helper::Table; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; @@ -14,14 +15,20 @@ use shirabe_php_shim::{ }; use shirabe_semver::constraint::MultiConstraint; use shirabe_semver::intervals::Intervals; +use std::cell::RefCell; +use std::rc::Rc; +use crate::advisory::AuditConfig; use crate::advisory::Auditor; use crate::command::BumpCommand; -use crate::command::{BaseCommand, BaseCommandData, HasBaseCommandData}; +use crate::command::base_command::base_command_initialize; +use crate::command::{BaseCommand, BaseCommandData}; use crate::composer::PartialComposerHandle; +use crate::config::Config; use crate::console::input::InputArgument; use crate::console::input::InputOption; use crate::dependency_resolver::request::{self, Request, UpdateAllowTransitiveDeps}; +use crate::filter::platform_requirement_filter::PlatformRequirementFilterInterface; use crate::installer::Installer; use crate::io::IOInterface; use crate::io::IOInterfaceImmutable; @@ -43,40 +50,52 @@ pub struct UpdateCommand { } impl UpdateCommand { - pub fn configure(&mut self) { + pub fn new() -> Self { + let mut command = UpdateCommand { + base_command_data: BaseCommandData::new(None), + }; + command + .configure() + .expect("UpdateCommand::configure uses static, valid metadata"); + command + } +} + +impl Command for UpdateCommand { + fn configure(&mut self) -> anyhow::Result<()> { // TODO(cli-completion): suggest_installed_package(false, true) / suggest_prefer_install - self - .set_name("update") - .set_aliases(&["u".to_string(), "upgrade".to_string()]) - .set_description("Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file") - // TODO(phase-c): populate with InputArgument/InputOption entries (see PHP UpdateCommand); - // blocked on the symfony InputDefinition entry modeling. - .set_definition(&[]) - .set_help( - "The update command reads the composer.json file from the\n\ - current directory, processes it, and updates, removes or installs all the\n\ - dependencies.\n\n\ - php composer.phar update\n\n\ - To limit the update operation to a few packages, you can list the package(s)\n\ - you want to update as such:\n\n\ - php composer.phar update vendor/package1 foo/mypackage [...]\n\n\ - You may also use an asterisk (*) pattern to limit the update operation to package(s)\n\ - from a specific vendor:\n\n\ - php composer.phar update vendor/package1 foo/* [...]\n\n\ - To run an update with more restrictive constraints you can use:\n\n\ - php composer.phar update --with vendor/package:1.0.*\n\n\ - To run a partial update with more restrictive constraints you can use the shorthand:\n\n\ - php composer.phar update vendor/package:1.0.*\n\n\ - To select packages names interactively with auto-completion use -i.\n\n\ - Read more at https://getcomposer.org/doc/03-cli.md#update-u-upgrade\n", - ); + self.set_name("update")?; + self.set_aliases(vec!["u".to_string(), "upgrade".to_string()])?; + self.set_description("Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file"); + // TODO(phase-c): populate with InputArgument/InputOption entries (see PHP UpdateCommand); + // blocked on the symfony InputDefinition entry modeling. + self.set_definition(&[]); + self.set_help( + "The update command reads the composer.json file from the\n\ + current directory, processes it, and updates, removes or installs all the\n\ + dependencies.\n\n\ + php composer.phar update\n\n\ + To limit the update operation to a few packages, you can list the package(s)\n\ + you want to update as such:\n\n\ + php composer.phar update vendor/package1 foo/mypackage [...]\n\n\ + You may also use an asterisk (*) pattern to limit the update operation to package(s)\n\ + from a specific vendor:\n\n\ + php composer.phar update vendor/package1 foo/* [...]\n\n\ + To run an update with more restrictive constraints you can use:\n\n\ + php composer.phar update --with vendor/package:1.0.*\n\n\ + To run a partial update with more restrictive constraints you can use the shorthand:\n\n\ + php composer.phar update vendor/package:1.0.*\n\n\ + To select packages names interactively with auto-completion use -i.\n\n\ + Read more at https://getcomposer.org/doc/03-cli.md#update-u-upgrade\n", + ); + Ok(()) } - pub fn execute( + fn execute( &mut self, - input: std::rc::Rc>, - output: std::rc::Rc>, - ) -> Result { + input: Rc>, + output: Rc>, + ) -> anyhow::Result { let io = self.get_io().clone(); if input.borrow().get_option("dev")?.as_bool().unwrap_or(false) { io.write_error3( @@ -491,7 +510,7 @@ impl UpdateCommand { true, io_interface::NORMAL, ); - let mut bump_command = BumpCommand::new(None); + let mut bump_command = BumpCommand::new(); bump_command.set_composer(composer_handle.clone()); result = bump_command.do_bump( io.clone(), @@ -520,6 +539,28 @@ impl UpdateCommand { Ok(result) } + fn initialize( + &mut self, + input: Rc>, + output: Rc>, + ) -> anyhow::Result<()> { + base_command_initialize(self, input, output) + } + + shirabe_external_packages::delegate_command_trait_impls_to_inner!(base_command_data); +} + +impl BaseCommand for UpdateCommand { + fn command_data_mut( + &mut self, + ) -> &mut shirabe_external_packages::symfony::console::command::command::CommandData { + self.base_command_data.command_data_mut() + } + + crate::delegate_base_command_trait_impls_to_inner!(base_command_data); +} + +impl UpdateCommand { /// @param array $packages /// @return array fn get_packages_interactively( @@ -717,13 +758,3 @@ impl UpdateCommand { ) } } - -impl HasBaseCommandData for UpdateCommand { - fn base_command_data(&self) -> &BaseCommandData { - &self.base_command_data - } - - fn base_command_data_mut(&mut self) -> &mut BaseCommandData { - &mut self.base_command_data - } -} -- cgit v1.3.1