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 proxy;
30pub mod server;
31pub mod setup;
32pub mod ui;
33
34pub use commands::{Command, CommandHandler, CommandRegistry};
36pub use core::config::Config;
37pub use core::error::{AppError, Result};
38pub use ui::screen::ScreenManager;
39
40use std::sync::OnceLock;
42static DEFAULT_REGISTRY: OnceLock<CommandRegistry> = OnceLock::new();
43
44pub fn create_default_registry() -> CommandRegistry {
45 build_registry()
46}
47
48fn build_registry() -> CommandRegistry {
50 use commands::{
51 cleanup::CleanupCommand, clear::ClearCommand, create::CreateCommand, exit::ExitCommand,
52 history::HistoryCommand, lang::LanguageCommand, list::ListCommand,
53 log_level::LogLevelCommand, restart::RestartCommand, start::StartCommand,
54 stop::StopCommand, theme::ThemeCommand, version::VersionCommand,
55 };
56
57 let mut registry = CommandRegistry::new();
58
59 registry
61 .register(VersionCommand)
63 .register(ClearCommand)
64 .register(ExitCommand)
65 .register(RestartCommand)
66 .register(LogLevelCommand)
68 .register(LanguageCommand::new())
69 .register(ThemeCommand::new())
70 .register(HistoryCommand)
72 .register(CleanupCommand::new())
74 .register(CreateCommand::new())
75 .register(ListCommand::new())
76 .register(StartCommand::new())
77 .register(StopCommand::new());
78
79 registry
80}
81
82pub async fn run() -> Result<()> {
84 let config = Config::load().await?;
85 run_with_config(config).await
86}
87
88pub async fn run_with_config(config: Config) -> Result<()> {
90 let mut screen = ScreenManager::new(&config).await?;
91 screen.run().await
92}
93
94pub fn create_handler() -> CommandHandler {
96 CommandHandler::new()
97}
98
99pub async fn load_config() -> Result<Config> {
100 Config::load().await
101}
102
103#[cfg(test)]
105pub fn create_test_registry() -> CommandRegistry {
106 build_registry()
108}
109
110pub fn get_command_count() -> usize {
112 DEFAULT_REGISTRY.get().map(|r| r.len()).unwrap_or(0)
113}