use crate::config::{Config, LLMProvider};
use clap::Parser;
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(name = "Litho (deepwiki-rs)")]
#[command(
about = "AI-based high-performance generation engine for documentation, It can intelligently analyze project structures, identify core modules, and generate professional architecture documentation."
)]
#[command(author = "Sopaco")]
#[command(version)]
pub struct Args {
#[arg(short, long, default_value = ".")]
pub project_path: PathBuf,
#[arg(short, long, default_value = "./litho.docs")]
pub output_path: PathBuf,
#[arg(short, long)]
pub config: Option<PathBuf>,
#[arg(short, long)]
pub name: Option<String>,
#[arg(long)]
pub skip_preprocessing: bool,
#[arg(long)]
pub skip_research: bool,
#[arg(long)]
pub skip_documentation: bool,
#[arg(short, long)]
pub verbose: bool,
#[arg(long)]
pub model_efficient: Option<String>,
#[arg(long)]
pub model_powerful: Option<String>,
#[arg(long)]
pub llm_api_base_url: Option<String>,
#[arg(long)]
pub llm_api_key: Option<String>,
#[arg(long)]
pub max_tokens: Option<u32>,
#[arg(long)]
pub temperature: Option<f32>,
#[arg(long)]
pub max_parallels: Option<usize>,
#[arg(long)]
pub llm_provider: Option<String>,
#[arg(long, default_value = "false", action = clap::ArgAction::SetTrue)]
pub enable_preset_tools: bool,
#[arg(long)]
pub no_cache: bool,
#[arg(long)]
pub force_regenerate: bool,
}
impl Args {
pub fn to_config(self) -> Config {
let mut config = if let Some(config_path) = &self.config {
Config::from_file(config_path).unwrap_or_else(|_| {
eprintln!("⚠️ 警告: 无法读取配置文件 {:?},使用默认配置", config_path);
Config::default()
})
} else {
Config::default()
};
config.project_path = self.project_path.clone();
config.output_path = self.output_path;
config.internal_path = self.project_path.join(".litho");
if let Some(name) = self.name {
config.project_name = Some(name);
}
if let Some(provider_str) = self.llm_provider {
if let Ok(provider) = provider_str.parse::<LLMProvider>() {
config.llm.provider = provider;
} else {
eprintln!(
"⚠️ 警告: 未知的provider: {},使用默认provider",
provider_str
);
}
}
if let Some(llm_api_base_url) = self.llm_api_base_url {
config.llm.api_base_url = llm_api_base_url;
}
if let Some(llm_api_key) = self.llm_api_key {
config.llm.api_key = llm_api_key;
}
if let Some(model_efficient) = self.model_efficient {
config.llm.model_efficient = model_efficient;
}
if let Some(model_powerful) = self.model_powerful {
config.llm.model_powerful = model_powerful;
} else {
config.llm.model_powerful = config.llm.model_efficient.to_string();
}
if let Some(max_tokens) = self.max_tokens {
config.llm.max_tokens = max_tokens;
}
if let Some(temperature) = self.temperature {
config.llm.temperature = temperature;
}
if let Some(max_parallels) = self.max_parallels {
config.llm.max_parallels = max_parallels;
}
config.llm.enable_preset_tools = self.enable_preset_tools;
if self.no_cache {
config.cache.enabled = false;
}
config
}
}