Common/Command/
CommandExecutor.rs

1//! # CommandExecutor Trait
2//!
3//! Defines the abstract service trait for command management and execution
4//! capabilities.
5
6use async_trait::async_trait;
7use serde_json::Value;
8
9use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
10
11/// An abstract service contract for an environment component that can execute
12/// and manage commands within the application.
13///
14/// This trait is implemented by the concrete `MountainEnvironment` and provides
15/// the core logic for the command palette and programmatic command execution.
16/// It is designed to handle both native commands implemented in Rust and
17/// proxied commands implemented in external sidecars.
18#[async_trait]
19pub trait CommandExecutor: Environment + Send + Sync {
20	/// Executes a command with the given identifier and arguments.
21	///
22	/// # Parameters
23	///
24	/// * `CommandIdentifier`: The unique ID of the command to execute.
25	/// * `Argument`: A `serde_json::Value` containing the arguments for the
26	///   command.
27	///
28	/// # Returns
29	///
30	/// A `Result` containing the command's return value as a
31	/// `serde_json::Value` on success, or a `CommonError` on failure.
32	async fn ExecuteCommand(&self, CommandIdentifier:String, Argument:Value) -> Result<Value, CommonError>;
33
34	/// Registers a command that is implemented in an external sidecar process.
35	///
36	/// # Parameters
37	///
38	/// * `SideCarIdentifier`: The unique ID of the sidecar where the command
39	///   logic resides.
40	/// * `CommandIdentifier`: The unique ID of the command being registered.
41	async fn RegisterCommand(&self, SideCarIdentifier:String, CommandIdentifier:String) -> Result<(), CommonError>;
42
43	/// Unregisters a previously registered command.
44	async fn UnregisterCommand(&self, SideCarIdentifier:String, CommandIdentifier:String) -> Result<(), CommonError>;
45
46	/// Retrieves a list of all currently registered command identifiers.
47	async fn GetAllCommands(&self) -> Result<Vec<String>, CommonError>;
48}