1use super::args::ConfigAction;
2use crate::cli::config::{get_config, reset_config, set_config, show_config, unset_config};
3use crate::core::{handle_ask, handle_suggest, select_mode};
4use crate::llm::create_client;
5use crate::system::error::DoumResult;
6use crate::system::{get_system_info, load_config};
7
8pub fn handle_config_command(action: Option<ConfigAction>) -> DoumResult<()> {
9 let action = action.unwrap_or(ConfigAction::Show);
11
12 match action {
13 ConfigAction::Show => show_config(),
14 ConfigAction::Reset => reset_config(),
15 ConfigAction::Set { key, value } => set_config(&key, &value),
16 ConfigAction::Get { key } => get_config(&key),
17 ConfigAction::Unset { key } => unset_config(&key),
18 }
19}
20
21pub async fn handle_ask_command(question: &str) -> DoumResult<()> {
22 let config = load_config()?;
23 let client = create_client(&config.llm)?;
24 let system_info = get_system_info();
25 handle_ask(question, client.as_ref(), &system_info, &config).await
26}
27
28pub async fn handle_suggest_command(request: &str) -> DoumResult<()> {
29 let config = load_config()?;
30 let client = create_client(&config.llm)?;
31 let system_info = get_system_info();
32 handle_suggest(request, client.as_ref(), &system_info, &config).await?;
33 Ok(())
34}
35
36pub async fn handle_auto_command(input: &str) -> DoumResult<()> {
37 let config = load_config()?;
38 let client = create_client(&config.llm)?;
39 let system_info = get_system_info();
40 select_mode(input, client.as_ref(), &system_info, &config).await
41}