rush_sync_server/commands/log_level/
command.rs

1use super::manager::LogLevelManager;
2use crate::commands::command::Command;
3use crate::core::prelude::*;
4
5#[derive(Debug)]
6pub struct LogLevelCommand;
7
8impl Command for LogLevelCommand {
9    fn name(&self) -> &'static str {
10        "log-level"
11    }
12
13    fn description(&self) -> &'static str {
14        "Change application log level"
15    }
16
17    fn matches(&self, command: &str) -> bool {
18        let cmd = command.trim().to_lowercase();
19        cmd.starts_with("log-level")
20            || cmd.starts_with("loglevel")
21            || (cmd.starts_with("config") && cmd.contains("--log-level"))
22    }
23
24    // ✅ FIXED EXECUTE_SYNC - Proper error handling
25    fn execute_sync(&self, args: &[&str]) -> Result<String> {
26        match args.first() {
27            None => Ok(LogLevelManager::show_status()),
28            Some(&"--help" | &"-h" | &"help") => Ok(LogLevelManager::show_help_i18n()),
29            Some(&level) => match LogLevelManager::set_level_persistent(level) {
30                Ok(success_msg) => Ok(success_msg),
31                Err(error_msg) => Ok(error_msg), // Convert String error to String success
32            },
33        }
34    }
35
36    fn priority(&self) -> u8 {
37        75
38    }
39}