rush_sync_server/
lib.rs

1// =====================================================
2// FILE: src/lib.rs - OPTIMIERTE VERSION
3// =====================================================
4
5#[macro_export]
6macro_rules! impl_default {
7    ($type:ty, $body:expr) => {
8        impl Default for $type {
9            fn default() -> Self {
10                $body
11            }
12        }
13    };
14}
15
16#[macro_export]
17macro_rules! matches_exact {
18    ($cmd:expr, $($pattern:literal)|+) => {
19        matches!($cmd.trim().to_lowercase().as_str(), $($pattern)|+)
20    };
21}
22
23// Module definitions
24pub mod commands;
25pub mod core;
26pub mod i18n;
27pub mod input;
28pub mod output;
29pub mod server;
30pub mod setup;
31pub mod ui;
32
33// Essential re-exports
34pub use commands::{Command, CommandHandler, CommandRegistry};
35pub use core::config::Config;
36pub use core::error::{AppError, Result};
37pub use ui::screen::ScreenManager;
38
39// ✅ OPTIMIERT: Lazy static für Registry - nur einmal erstellen
40use std::sync::OnceLock;
41static DEFAULT_REGISTRY: OnceLock<CommandRegistry> = OnceLock::new();
42
43pub fn create_default_registry() -> CommandRegistry {
44    build_registry()
45}
46
47// ✅ EXTRACTED: Registry-Building separiert für bessere Testbarkeit
48fn build_registry() -> CommandRegistry {
49    use commands::{
50        cleanup::CleanupCommand, clear::ClearCommand, create::CreateCommand, exit::ExitCommand,
51        history::HistoryCommand, lang::LanguageCommand, list::ListCommand,
52        log_level::LogLevelCommand, restart::RestartCommand, start::StartCommand,
53        stop::StopCommand, theme::ThemeCommand, version::VersionCommand,
54    };
55
56    let mut registry = CommandRegistry::new();
57
58    // ✅ OPTIMIERT: Functional-Style Chain für kompakteren Code
59    registry
60        // Core Commands
61        .register(VersionCommand)
62        .register(ClearCommand)
63        .register(ExitCommand)
64        .register(RestartCommand)
65        // Configuration Commands
66        .register(LogLevelCommand)
67        .register(LanguageCommand::new())
68        .register(ThemeCommand::new())
69        // Utility Commands
70        .register(HistoryCommand)
71        // Server Commands
72        .register(CleanupCommand::new())
73        .register(CreateCommand::new())
74        .register(ListCommand::new())
75        .register(StartCommand::new())
76        .register(StopCommand::new());
77
78    registry
79}
80
81// ✅ VEREINFACHT: Main entry point
82pub async fn run() -> Result<()> {
83    let config = Config::load().await?;
84    run_with_config(config).await
85}
86
87// ✅ OPTIMIERT: Direkte Implementierung ohne Duplikation
88pub async fn run_with_config(config: Config) -> Result<()> {
89    let mut screen = ScreenManager::new(&config).await?;
90    screen.run().await
91}
92
93// ✅ VEREINFACHT: Convenience functions
94pub fn create_handler() -> CommandHandler {
95    CommandHandler::new()
96}
97
98pub async fn load_config() -> Result<Config> {
99    Config::load().await
100}
101
102// ✅ NEU: Registry-Testing Helper (für Unit Tests)
103#[cfg(test)]
104pub fn create_test_registry() -> CommandRegistry {
105    // Für Tests immer fresh Registry ohne static caching
106    build_registry()
107}
108
109// ✅ NEU: Command-Count für Debugging
110pub fn get_command_count() -> usize {
111    DEFAULT_REGISTRY.get().map(|r| r.len()).unwrap_or(0)
112}