Skip to main content

stynx_code_commands/domain/
command_definition.rs

1use std::future::Future;
2use std::pin::Pin;
3use std::sync::Arc;
4
5use stynx_code_errors::AppResult;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum CommandType {
9
10    Prompt,
11
12    Local,
13
14    Interactive,
15}
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum CommandSource {
19    Builtin,
20    Skill,
21    Plugin,
22    Mcp,
23    Bundled,
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq)]
27pub enum CommandAvailability {
28    ClaudeAi,
29    Console,
30    Universal,
31}
32
33#[derive(Debug)]
34pub enum CommandOutput {
35
36    Text(String),
37
38    Prompt(String),
39
40    Quit,
41
42    None,
43}
44
45pub type CommandHandler = Arc<
46    dyn Fn(&str) -> Pin<Box<dyn Future<Output = AppResult<CommandOutput>> + Send>>
47        + Send
48        + Sync,
49>;
50
51pub struct CommandDefinition {
52    pub name: String,
53    pub aliases: Vec<String>,
54    pub description: String,
55    pub command_type: CommandType,
56    pub argument_hint: Option<String>,
57    pub is_hidden: bool,
58    pub availability: Vec<CommandAvailability>,
59    pub source: CommandSource,
60    pub handler: CommandHandler,
61}
62
63impl CommandDefinition {
64    pub fn matches(&self, name: &str) -> bool {
65        self.name == name || self.aliases.iter().any(|a| a == name)
66    }
67}
68
69impl std::fmt::Debug for CommandDefinition {
70    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71        f.debug_struct("CommandDefinition")
72            .field("name", &self.name)
73            .field("aliases", &self.aliases)
74            .field("description", &self.description)
75            .field("command_type", &self.command_type)
76            .finish()
77    }
78}