Skip to main content

rush_sync_server/
lib.rs

1#[macro_export]
2macro_rules! impl_default {
3    ($type:ty, $body:expr) => {
4        impl Default for $type {
5            fn default() -> Self {
6                $body
7            }
8        }
9    };
10}
11
12#[macro_export]
13macro_rules! matches_exact {
14    ($cmd:expr, $($pattern:literal)|+) => {
15        matches!($cmd.trim().to_lowercase().as_str(), $($pattern)|+)
16    };
17}
18
19// Module definitions
20pub mod commands;
21pub mod core;
22#[cfg(feature = "memory")]
23pub mod embedded;
24pub mod i18n;
25pub mod input;
26#[cfg(feature = "memory")]
27pub mod memory;
28pub mod output;
29pub mod proxy;
30pub mod server;
31pub mod setup;
32pub mod sync;
33pub mod ui;
34
35// Essential re-exports
36pub use commands::{Command, CommandHandler, CommandRegistry};
37pub use core::config::Config;
38pub use core::error::{AppError, Result};
39pub use ui::screen::ScreenManager;
40
41pub fn create_default_registry() -> CommandRegistry {
42    build_registry()
43}
44
45fn build_registry() -> CommandRegistry {
46    use commands::{
47        cleanup::CleanupCommand, clear::ClearCommand, create::CreateCommand, exit::ExitCommand,
48        help::HelpCommand, history::HistoryCommand, lang::LanguageCommand, list::ListCommand,
49        log_level::LogLevelCommand, recovery::RecoveryCommand, remote::RemoteCommand,
50        restart::RestartCommand, start::StartCommand, stop::StopCommand, sync::SyncCommand,
51        theme::ThemeCommand, version::VersionCommand,
52    };
53
54    let mut registry = CommandRegistry::new();
55
56    registry
57        .register(HelpCommand::new())
58        .register(VersionCommand)
59        .register(ClearCommand)
60        .register(ExitCommand)
61        .register(RestartCommand)
62        .register(LogLevelCommand)
63        .register(LanguageCommand::new())
64        .register(ThemeCommand::new())
65        .register(HistoryCommand)
66        .register(RecoveryCommand::new())
67        .register(RemoteCommand::new())
68        .register(SyncCommand::new())
69        .register(CleanupCommand::new())
70        .register(CreateCommand::new())
71        .register(ListCommand::new())
72        .register(StartCommand::new())
73        .register(StopCommand::new());
74
75    #[cfg(feature = "memory")]
76    registry.register(commands::memory::command::MemoryCommand::new());
77
78    registry
79}
80
81pub async fn run() -> Result<()> {
82    let config = Config::load().await?;
83    run_with_config(config).await
84}
85
86pub async fn run_with_config(config: Config) -> Result<()> {
87    let mut screen = ScreenManager::new(&config).await?;
88    screen.run().await
89}
90
91pub fn create_handler() -> CommandHandler {
92    CommandHandler::new()
93}
94
95pub async fn load_config() -> Result<Config> {
96    Config::load().await
97}
98
99#[cfg(test)]
100pub fn create_test_registry() -> CommandRegistry {
101    build_registry()
102}