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