1#[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
23pub mod commands;
25pub mod core;
26pub mod i18n;
27pub mod input;
28pub mod output;
29pub mod server;
30pub mod setup;
31pub mod ui;
32
33pub use commands::{Command, CommandHandler, CommandRegistry};
35pub use core::config::Config;
36pub use core::error::{AppError, Result};
37pub use ui::screen::ScreenManager;
38
39use std::sync::OnceLock;
41static DEFAULT_REGISTRY: OnceLock<CommandRegistry> = OnceLock::new();
42
43pub fn create_default_registry() -> CommandRegistry {
44 build_registry()
45}
46
47fn 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 registry
60 .register(VersionCommand)
62 .register(ClearCommand)
63 .register(ExitCommand)
64 .register(RestartCommand)
65 .register(LogLevelCommand)
67 .register(LanguageCommand::new())
68 .register(ThemeCommand::new())
69 .register(HistoryCommand)
71 .register(CleanupCommand::new())
73 .register(CreateCommand::new())
74 .register(ListCommand::new())
75 .register(StartCommand::new())
76 .register(StopCommand::new());
77
78 registry
79}
80
81pub async fn run() -> Result<()> {
83 let config = Config::load().await?;
84 run_with_config(config).await
85}
86
87pub async fn run_with_config(config: Config) -> Result<()> {
89 let mut screen = ScreenManager::new(&config).await?;
90 screen.run().await
91}
92
93pub fn create_handler() -> CommandHandler {
95 CommandHandler::new()
96}
97
98pub async fn load_config() -> Result<Config> {
99 Config::load().await
100}
101
102#[cfg(test)]
104pub fn create_test_registry() -> CommandRegistry {
105 build_registry()
107}
108
109pub fn get_command_count() -> usize {
111 DEFAULT_REGISTRY.get().map(|r| r.len()).unwrap_or(0)
112}