diff options
Diffstat (limited to 'crates/shirabe/src/command/prohibits_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/prohibits_command.rs | 178 |
1 files changed, 107 insertions, 71 deletions
diff --git a/crates/shirabe/src/command/prohibits_command.rs b/crates/shirabe/src/command/prohibits_command.rs index 0df87fd..02aaf33 100644 --- a/crates/shirabe/src/command/prohibits_command.rs +++ b/crates/shirabe/src/command/prohibits_command.rs @@ -1,12 +1,24 @@ //! ref: composer/src/Composer/Command/ProhibitsCommand.php +use anyhow::Result; +use indexmap::IndexMap; +use shirabe_external_packages::symfony::console::command::command::Command; +use shirabe_external_packages::symfony::console::input::InputInterface; +use shirabe_external_packages::symfony::console::output::OutputInterface; +use shirabe_php_shim::PhpMixed; +use std::cell::RefCell; +use std::rc::Rc; + +use crate::advisory::AuditConfig; use crate::command::BaseDependencyCommand; -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::filter::platform_requirement_filter::PlatformRequirementFilterInterface; use crate::io::IOInterface; -use shirabe_external_packages::symfony::console::input::InputInterface; -use shirabe_external_packages::symfony::console::output::OutputInterface; #[derive(Debug)] pub struct ProhibitsCommand { @@ -16,69 +28,15 @@ pub struct ProhibitsCommand { } impl ProhibitsCommand { - pub fn configure(&mut self) { - // TODO(cli-completion): suggest_available_package() for `package` argument - self.set_name("prohibits") - .set_aliases(&["why-not".to_string()]) - .set_description("Shows which packages prevent the given package from being installed") - .set_definition(&[ - InputArgument::new( - <Self as BaseDependencyCommand>::ARGUMENT_PACKAGE, - Some(InputArgument::REQUIRED), - "Package to inspect", - None, - ) - .unwrap() - .into(), - InputArgument::new( - <Self as BaseDependencyCommand>::ARGUMENT_CONSTRAINT, - Some(InputArgument::REQUIRED), - "Version constraint, which version you expected to be installed", - None, - ) - .unwrap() - .into(), - InputOption::new( - <Self as BaseDependencyCommand>::OPTION_RECURSIVE, - Some(shirabe_php_shim::PhpMixed::String("r".to_string())), - Some(InputOption::VALUE_NONE), - "Recursively resolves up to the root package", - None, - ) - .unwrap() - .into(), - InputOption::new( - <Self as BaseDependencyCommand>::OPTION_TREE, - Some(shirabe_php_shim::PhpMixed::String("t".to_string())), - Some(InputOption::VALUE_NONE), - "Prints the results as a nested tree", - None, - ) - .unwrap() - .into(), - InputOption::new( - "locked", - None, - Some(InputOption::VALUE_NONE), - "Read dependency information from composer.lock", - None, - ) - .unwrap() - .into(), - ]) - .set_help( - "Displays detailed information about why a package cannot be installed.\n\n\ - <info>php composer.phar prohibits composer/composer</info>\n\n\ - Read more at https://getcomposer.org/doc/03-cli.md#prohibits-why-not", - ); - } - - pub fn execute( - &mut self, - input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>, - output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, - ) -> anyhow::Result<i64> { - self.do_execute(input, output, true) + pub fn new() -> Self { + let mut command = ProhibitsCommand { + base_command_data: BaseCommandData::new(None), + colors: Vec::new(), + }; + command + .configure() + .expect("ProhibitsCommand::configure uses static, valid metadata"); + command } } @@ -92,12 +50,90 @@ impl BaseDependencyCommand for ProhibitsCommand { } } -impl HasBaseCommandData for ProhibitsCommand { - fn base_command_data(&self) -> &BaseCommandData { - &self.base_command_data +impl Command for ProhibitsCommand { + fn configure(&mut self) -> anyhow::Result<()> { + // TODO(cli-completion): suggest_available_package() for `package` argument + self.set_name("prohibits")?; + self.set_aliases(vec!["why-not".to_string()])?; + self.set_description("Shows which packages prevent the given package from being installed"); + self.set_definition(&[ + InputArgument::new( + <Self as BaseDependencyCommand>::ARGUMENT_PACKAGE, + Some(InputArgument::REQUIRED), + "Package to inspect", + None, + ) + .unwrap() + .into(), + InputArgument::new( + <Self as BaseDependencyCommand>::ARGUMENT_CONSTRAINT, + Some(InputArgument::REQUIRED), + "Version constraint, which version you expected to be installed", + None, + ) + .unwrap() + .into(), + InputOption::new( + <Self as BaseDependencyCommand>::OPTION_RECURSIVE, + Some(shirabe_php_shim::PhpMixed::String("r".to_string())), + Some(InputOption::VALUE_NONE), + "Recursively resolves up to the root package", + None, + ) + .unwrap() + .into(), + InputOption::new( + <Self as BaseDependencyCommand>::OPTION_TREE, + Some(shirabe_php_shim::PhpMixed::String("t".to_string())), + Some(InputOption::VALUE_NONE), + "Prints the results as a nested tree", + None, + ) + .unwrap() + .into(), + InputOption::new( + "locked", + None, + Some(InputOption::VALUE_NONE), + "Read dependency information from composer.lock", + None, + ) + .unwrap() + .into(), + ]); + self.set_help( + "Displays detailed information about why a package cannot be installed.\n\n\ + <info>php composer.phar prohibits composer/composer</info>\n\n\ + Read more at https://getcomposer.org/doc/03-cli.md#prohibits-why-not", + ); + Ok(()) + } + + fn execute( + &mut self, + input: Rc<RefCell<dyn InputInterface>>, + output: Rc<RefCell<dyn OutputInterface>>, + ) -> anyhow::Result<i64> { + self.do_execute(input, output, true) + } + + fn initialize( + &mut self, + input: Rc<RefCell<dyn InputInterface>>, + output: Rc<RefCell<dyn OutputInterface>>, + ) -> anyhow::Result<()> { + base_command_initialize(self, input, output) } - fn base_command_data_mut(&mut self) -> &mut BaseCommandData { - &mut self.base_command_data + shirabe_external_packages::delegate_command_trait_impls_to_inner!(base_command_data); +} + +impl BaseCommand for ProhibitsCommand { + 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); } |
