Skip to main content

rush_sync_server/commands/
command.rs

1use crate::core::prelude::*;
2
3#[async_trait::async_trait]
4pub trait Command: Send + Sync + std::fmt::Debug + 'static {
5    fn name(&self) -> &'static str;
6    fn description(&self) -> &'static str;
7    fn matches(&self, command: &str) -> bool;
8
9    // Async execution - default calls sync version
10    async fn execute(&self, args: &[&str]) -> Result<String> {
11        self.execute_sync(args)
12    }
13
14    // Sync execution - MUST be implemented by commands that don't override execute()
15    fn execute_sync(&self, _args: &[&str]) -> Result<String> {
16        Err(crate::core::error::AppError::Validation(
17            "Command must implement either execute() or execute_sync()".to_string(),
18        ))
19    }
20
21    fn priority(&self) -> u8 {
22        50
23    }
24    fn is_available(&self) -> bool {
25        true
26    }
27}