rush_sync_server/commands/
mod.rs

1// =====================================================
2// FILE: commands/mod.rs - MODULE CLEANUP
3// =====================================================
4
5pub mod clear;
6pub mod command;
7pub mod exit;
8pub mod handler;
9pub mod history;
10pub mod lang;
11pub mod plugins; // ✅ Plugins hinzugefügt
12pub mod registry;
13pub mod restart;
14pub mod version;
15
16// ✅ CLEAN EXPORTS (macros entfernt da sie in lib.rs sind)
17pub use command::Command;
18pub use handler::CommandHandler;
19pub use plugins::{CommandPlugin, PluginManager}; // ✅ Plugin exports
20pub use registry::CommandRegistry;
21
22// =====================================================
23// ERWEITERTE PLUGIN EXAMPLE - WIE ES GENUTZT WIRD
24// =====================================================
25
26/*
27// ✅ BEISPIEL: Neues Network Plugin
28
29// FILE: commands/network/mod.rs
30pub mod ping;
31pub mod wget;
32
33pub use ping::PingCommand;
34pub use wget::WgetCommand;
35
36// Network Plugin Implementation
37use crate::commands::{Command, CommandPlugin};
38
39pub struct NetworkPlugin;
40
41impl CommandPlugin for NetworkPlugin {
42    fn name(&self) -> &'static str {
43        "network"
44    }
45
46    fn load_commands(&self) -> Vec<Box<dyn Command>> {
47        vec![
48            Box::new(PingCommand),
49            Box::new(WgetCommand),
50        ]
51    }
52}
53
54// ✅ NUTZUNG in main.rs oder wo auch immer:
55
56use crate::commands::{CommandHandler, PluginManager};
57use crate::commands::network::NetworkPlugin;
58
59let mut handler = CommandHandler::new();
60
61// Option 1: Plugin zur Laufzeit hinzufügen
62let mut plugin_manager = PluginManager::new();
63plugin_manager.load_plugin(NetworkPlugin);
64plugin_manager.apply_to_registry(&mut handler.registry);
65
66// Option 2: Mit erweiterten Macros (optional)
67let handler = CommandHandler::with_registry(
68    create_full_registry_with_plugins!(NetworkPlugin)
69);
70
71*/
72
73// =====================================================
74// PERFORMANCE TIPP - COMMAND CACHING
75// =====================================================
76
77/*
78// ✅ OPTIONAL: Command Caching für bessere Performance
79
80use std::collections::HashMap;
81
82impl CommandRegistry {
83    cache: HashMap<String, usize>, // Cache command name -> index
84
85    pub fn find_command_cached(&self, input: &str) -> Option<&dyn Command> {
86        // Cache lookup first, dann normale find_command logic
87        if let Some(&index) = self.cache.get(input) {
88            return self.commands.get(index).map(|cmd| cmd.as_ref());
89        }
90
91        // Normal lookup + cache update
92        if let Some(cmd) = self.find_command(input) {
93            // Update cache
94            self.cache.insert(input.to_string(), /* index */);
95            Some(cmd)
96        } else {
97            None
98        }
99    }
100}
101*/
102
103// =====================================================
104// DEBUG COMMAND EXAMPLE - NUR IN DEBUG BUILDS
105// =====================================================
106
107/*
108// ✅ BEISPIEL: Debug Command nur in Development
109
110#[derive(Debug)]
111pub struct DebugCommand;
112
113impl Command for DebugCommand {
114    fn name(&self) -> &'static str { "debug" }
115    fn description(&self) -> &'static str { "Debug utilities" }
116
117    fn matches(&self, command: &str) -> bool {
118        command == "debug"
119    }
120
121    fn execute_sync(&self, args: &[&str]) -> Result<String> {
122        match args.first() {
123            Some(&"registry") => {
124                // Registry debug info von handler
125                Ok("Registry debug info...".to_string())
126            }
127            Some(&"commands") => {
128                // Liste alle verfügbaren commands
129                Ok("Available commands: ...".to_string())
130            }
131            _ => Ok("Debug commands: registry, commands".to_string())
132        }
133    }
134
135    fn is_available(&self) -> bool {
136        cfg!(debug_assertions) // ✅ Nur in Debug builds
137    }
138
139    fn priority(&self) -> u8 { 10 } // Niedrigste Priorität
140}
141
142// Dann in create_full_registry! hinzufügen:
143#[cfg(debug_assertions)]
144register_commands!(registry, DebugCommand);
145*/