use crate::providers::CodexProvider;
use crate::utils::config::CodexConfig;
use anyhow::Result;
use clap::Parser;
#[derive(Parser, Debug)]
pub struct CodexCommand {
#[clap(index = 1)]
pub prompt: String,
#[clap(long, value_name = "FILE_PATH")]
pub apply_patch: Option<String>,
}
impl CodexCommand {
pub async fn run(&self) -> Result<()> {
let codex_config = CodexConfig::default();
let provider = CodexProvider::new(codex_config).await?;
println!("Sending prompt to Codex: '{}'...", self.prompt);
let response = provider.generate_code(&self.prompt, None).await?;
if let Some(file_path_str) = &self.apply_patch {
let file_path = std::path::PathBuf::from(file_path_str);
println!("\nApplying patch to '{}'...", file_path.display());
provider.apply_patch(&file_path, &response)?;
println!("Patch applied successfully.");
} else {
println!("\nCodex Response:\n{response}");
}
Ok(())
}
}