diff options
Diffstat (limited to 'crates/shirabe/src/plugin/capability')
| -rw-r--r-- | crates/shirabe/src/plugin/capability/capability.rs | 14 | ||||
| -rw-r--r-- | crates/shirabe/src/plugin/capability/command_provider.rs | 8 |
2 files changed, 18 insertions, 4 deletions
diff --git a/crates/shirabe/src/plugin/capability/capability.rs b/crates/shirabe/src/plugin/capability/capability.rs index 1788d9a0..aa70ffa0 100644 --- a/crates/shirabe/src/plugin/capability/capability.rs +++ b/crates/shirabe/src/plugin/capability/capability.rs @@ -1,4 +1,14 @@ //! ref: composer/src/Composer/Plugin/Capability/Capability.php -// TODO(plugin): Marker interface for Plugin capabilities. Every new Capability which is added to the Plugin API must implement this interface. -pub trait Capability {} +use crate::plugin::capability::CommandProvider; + +/// Marker interface for Plugin capabilities. Every new Capability which is added to the +/// Plugin API must implement this interface. +/// +/// The accessor replaces PHP's `instanceof` downcast on a capability instance of unknown +/// concrete type (the way `PluginInterface::as_capable` does for plugins). +pub trait Capability { + fn as_command_provider(&self) -> Option<&dyn CommandProvider> { + None + } +} diff --git a/crates/shirabe/src/plugin/capability/command_provider.rs b/crates/shirabe/src/plugin/capability/command_provider.rs index 6d6f6cf1..2453860a 100644 --- a/crates/shirabe/src/plugin/capability/command_provider.rs +++ b/crates/shirabe/src/plugin/capability/command_provider.rs @@ -1,9 +1,13 @@ //! ref: composer/src/Composer/Plugin/Capability/CommandProvider.php -// TODO(plugin): Commands Provider Interface. Plugins implementing this capability provide a list of commands. use crate::command::BaseCommand; use crate::plugin::capability::Capability; +/// Commands Provider Interface. Plugins implementing this capability provide a list of +/// commands. +/// +/// The sole implementor is the PHP capability proxy (Composer itself never implements a +/// capability), so the method is fallible: the answer crosses the RPC boundary. pub trait CommandProvider: Capability { - fn get_commands(&self) -> Vec<Box<dyn BaseCommand>>; + fn get_commands(&self) -> anyhow::Result<Vec<Box<dyn BaseCommand>>>; } |
