diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-19 23:54:12 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-20 00:01:37 +0900 |
| commit | e5fcde172b38d9a71292d0b4dd7f5d347da2e748 (patch) | |
| tree | c1091a1d94efb1c3ac1cda7c59a18ce53d74313b /crates/shirabe-external-packages/src/symfony/console/descriptor | |
| parent | adfa7c6b295521a6f8fdf4084993a80a8030e49b (diff) | |
| download | php-shirabe-e5fcde172b38d9a71292d0b4dd7f5d347da2e748.tar.gz php-shirabe-e5fcde172b38d9a71292d0b4dd7f5d347da2e748.tar.zst php-shirabe-e5fcde172b38d9a71292d0b4dd7f5d347da2e748.zip | |
feat(command): implement --help output
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/descriptor')
6 files changed, 45 insertions, 45 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/descriptor.rs index 43b1094..38824a6 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/descriptor.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/descriptor.rs @@ -2,8 +2,9 @@ use crate::symfony::console::application::Application; use crate::symfony::console::command::command::Command; -use crate::symfony::console::descriptor::descriptor_interface::DescriptorInterface; -use crate::symfony::console::exception::invalid_argument_exception::InvalidArgumentException; +use crate::symfony::console::descriptor::descriptor_interface::{ + DescribableObject, DescriptorInterface, +}; use crate::symfony::console::input::input_argument::InputArgument; use crate::symfony::console::input::input_definition::InputDefinition; use crate::symfony::console::input::input_option::InputOption; @@ -20,52 +21,29 @@ pub trait Descriptor: DescriptorInterface { fn describe( &mut self, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, - object: PhpMixed, + object: DescribableObject, options: IndexMap<String, PhpMixed>, ) -> anyhow::Result<()> { self.set_output(output); - // PHP dispatches via `$object instanceof ...`. The concrete runtime type of - // `object` must be recovered to route to the correct describe* method. - match true { - // case $object instanceof InputArgument: - _ if todo!("$object instanceof InputArgument") => { - let argument: InputArgument = todo!("downcast object to InputArgument"); + // PHP dispatches via `$object instanceof ...`; the explicit `DescribableObject` enum makes + // that dispatch a `match`. + match object { + DescribableObject::InputArgument(argument) => { self.describe_input_argument(&argument, options)?; } - // case $object instanceof InputOption: - _ if todo!("$object instanceof InputOption") => { - let option: InputOption = todo!("downcast object to InputOption"); + DescribableObject::InputOption(option) => { self.describe_input_option(&option, options)?; } - // case $object instanceof InputDefinition: - _ if todo!("$object instanceof InputDefinition") => { - let definition: InputDefinition = todo!("downcast object to InputDefinition"); + DescribableObject::InputDefinition(definition) => { self.describe_input_definition(&definition, options)?; } - // case $object instanceof Command: - _ if todo!("$object instanceof Command") => { - let mut command: Box<dyn Command> = todo!("downcast object to Command"); - self.describe_command(command.as_mut(), options)?; + DescribableObject::Command(command) => { + self.describe_command(&mut *command.borrow_mut(), options)?; } - // case $object instanceof Application: - _ if todo!("$object instanceof Application") => { - let application: std::rc::Rc<std::cell::RefCell<dyn Application>> = - todo!("downcast object to Application"); + DescribableObject::Application(application) => { self.describe_application(application, options)?; } - _ => { - return Err( - InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: format!( - "Object of type \"{}\" is not describable.", - shirabe_php_shim::get_debug_type(&object) - ), - code: 0, - }) - .into(), - ); - } } Ok(()) diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/descriptor_interface.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/descriptor_interface.rs index be39ec3..be0e9ff 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/descriptor_interface.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/descriptor_interface.rs @@ -1,15 +1,29 @@ //! ref: composer/vendor/symfony/console/Descriptor/DescriptorInterface.php +use crate::symfony::console::application::Application; +use crate::symfony::console::command::command::Command; +use crate::symfony::console::input::input_argument::InputArgument; +use crate::symfony::console::input::input_definition::InputDefinition; +use crate::symfony::console::input::input_option::InputOption; use crate::symfony::console::output::output_interface::OutputInterface; use indexmap::IndexMap; use shirabe_php_shim::PhpMixed; +/// The set of objects the descriptors know how to describe. +pub enum DescribableObject { + InputArgument(InputArgument), + InputOption(InputOption), + InputDefinition(InputDefinition), + Command(std::rc::Rc<std::cell::RefCell<dyn Command>>), + Application(std::rc::Rc<std::cell::RefCell<dyn Application>>), +} + /// Descriptor interface. pub trait DescriptorInterface { fn describe( &mut self, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, - object: PhpMixed, + object: DescribableObject, options: IndexMap<String, PhpMixed>, ) -> anyhow::Result<()>; } diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs index 4793370..9068a0a 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs @@ -5,7 +5,9 @@ use crate::symfony::console::application::Application; use crate::symfony::console::command::command::Command; use crate::symfony::console::descriptor::application_description::ApplicationDescription; use crate::symfony::console::descriptor::descriptor::Descriptor; -use crate::symfony::console::descriptor::descriptor_interface::DescriptorInterface; +use crate::symfony::console::descriptor::descriptor_interface::{ + DescribableObject, DescriptorInterface, +}; use crate::symfony::console::input::input_argument::InputArgument; use crate::symfony::console::input::input_definition::InputDefinition; use crate::symfony::console::input::input_option::InputOption; @@ -370,7 +372,7 @@ impl DescriptorInterface for JsonDescriptor { fn describe( &mut self, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, - object: PhpMixed, + object: DescribableObject, options: IndexMap<String, PhpMixed>, ) -> anyhow::Result<()> { Descriptor::describe(self, output, object, options) diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs index 698cc51..49d958f 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs @@ -5,7 +5,9 @@ use crate::symfony::console::application::Application; use crate::symfony::console::command::command::Command; use crate::symfony::console::descriptor::application_description::ApplicationDescription; use crate::symfony::console::descriptor::descriptor::Descriptor; -use crate::symfony::console::descriptor::descriptor_interface::DescriptorInterface; +use crate::symfony::console::descriptor::descriptor_interface::{ + DescribableObject, DescriptorInterface, +}; use crate::symfony::console::helper::helper::Helper; use crate::symfony::console::input::input_argument::InputArgument; use crate::symfony::console::input::input_definition::InputDefinition; @@ -26,7 +28,7 @@ impl MarkdownDescriptor { pub fn describe( &mut self, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, - object: PhpMixed, + object: DescribableObject, options: IndexMap<String, PhpMixed>, ) -> anyhow::Result<()> { let decorated = output.borrow().is_decorated(); @@ -312,7 +314,7 @@ impl DescriptorInterface for MarkdownDescriptor { fn describe( &mut self, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, - object: PhpMixed, + object: DescribableObject, options: IndexMap<String, PhpMixed>, ) -> anyhow::Result<()> { MarkdownDescriptor::describe(self, output, object, options) diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs index 915e19e..6590384 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs @@ -5,7 +5,9 @@ use crate::symfony::console::application::Application; use crate::symfony::console::command::command::Command; use crate::symfony::console::descriptor::application_description::ApplicationDescription; use crate::symfony::console::descriptor::descriptor::Descriptor; -use crate::symfony::console::descriptor::descriptor_interface::DescriptorInterface; +use crate::symfony::console::descriptor::descriptor_interface::{ + DescribableObject, DescriptorInterface, +}; use crate::symfony::console::formatter::output_formatter::OutputFormatter; use crate::symfony::console::helper::helper::Helper; use crate::symfony::console::input::input_argument::InputArgument; @@ -549,7 +551,7 @@ impl DescriptorInterface for TextDescriptor { fn describe( &mut self, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, - object: PhpMixed, + object: DescribableObject, options: IndexMap<String, PhpMixed>, ) -> anyhow::Result<()> { Descriptor::describe(self, output, object, options) diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/xml_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/xml_descriptor.rs index 4c65893..063f279 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/xml_descriptor.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/xml_descriptor.rs @@ -4,7 +4,9 @@ use crate::symfony::console::application::Application; use crate::symfony::console::command::command::Command; use crate::symfony::console::descriptor::application_description::ApplicationDescription; use crate::symfony::console::descriptor::descriptor::Descriptor; -use crate::symfony::console::descriptor::descriptor_interface::DescriptorInterface; +use crate::symfony::console::descriptor::descriptor_interface::{ + DescribableObject, DescriptorInterface, +}; use crate::symfony::console::input::input_argument::InputArgument; use crate::symfony::console::input::input_definition::InputDefinition; use crate::symfony::console::input::input_option::InputOption; @@ -372,7 +374,7 @@ impl DescriptorInterface for XmlDescriptor { fn describe( &mut self, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, - object: PhpMixed, + object: DescribableObject, options: IndexMap<String, PhpMixed>, ) -> anyhow::Result<()> { Descriptor::describe(self, output, object, options) |
