doum_cli/cli/
commands.rs

1use crate::system::error::Result;
2use crate::system::{load_config, save_config, get_config_path, load_default_config, get_system_info};
3use crate::llm::create_client;
4use crate::core::{handle_ask, handle_suggest, select_and_execute};
5use super::args::ConfigAction;
6
7/// config 커맨드 처리
8pub fn handle_config_command(action: Option<ConfigAction>) -> Result<()> {
9    // action이 None이면 interactive 모드로
10    let action = action.unwrap_or(ConfigAction::Interactive);
11    
12    match action {
13        ConfigAction::Interactive => {
14            crate::cli::config::run_config_interactive()
15        }
16        ConfigAction::Show => show_config(),
17        ConfigAction::Reset => reset_config(),
18    }
19}
20
21/// 전체 설정 표시
22fn show_config() -> Result<()> {
23    let config = load_config()?;
24    let config_path = get_config_path()?;
25    
26    println!("Config file location: {}\n", config_path.display());
27    
28    let toml_str = toml::to_string_pretty(&config)?;
29    
30    println!("{}", toml_str);
31    
32    Ok(())
33}
34
35/// 설정을 기본값으로 리셋
36fn reset_config() -> Result<()> {
37    let default_config = load_default_config()?;
38    save_config(&default_config)?;
39    
40    println!("✅ Configuration reset to default");
41    
42    Ok(())
43}
44
45/// ask 커맨드 처리
46pub async fn handle_ask_command(question: &str) -> Result<()> {
47    let config = load_config()?;
48    let client = create_client(&config.llm)?;
49    let system_info = get_system_info();
50    handle_ask(question, client.as_ref(), &system_info, &config).await
51}
52
53/// suggest 커맨드 처리
54pub async fn handle_suggest_command(request: &str) -> Result<()> {
55    let config = load_config()?;
56    let client = create_client(&config.llm)?;
57    let system_info = get_system_info();
58    handle_suggest(request, client.as_ref(), &system_info, &config).await?;
59    Ok(())
60}
61
62/// auto 커맨드 처리 (모드 자동 선택)
63pub async fn handle_auto_command(input: &str) -> Result<()> {
64    let config = load_config()?;
65    let client = create_client(&config.llm)?;
66    let system_info = get_system_info();
67    select_and_execute(input, client.as_ref(), &system_info, &config).await
68}