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