smartui/commands/
generate_alias.rs

1use crate::error::Result;
2use crate::gemini::GeminiClientTrait;
3use crate::tts::TTSManager;
4use async_trait::async_trait;
5
6#[async_trait]
7pub trait GenerateContent {
8    async fn generate_content(&self, prompt: &str) -> Result<String>;
9}
10
11pub struct GenerateAliasCommand<T: GeminiClientTrait> {
12    client: T,
13}
14
15impl<T: GeminiClientTrait> GenerateAliasCommand<T> {
16    pub fn new(client: T) -> Self {
17        Self { client }
18    }
19}
20
21#[async_trait]
22impl<T: GeminiClientTrait + Send + Sync> GenerateContent for GenerateAliasCommand<T> {
23    async fn generate_content(&self, prompt: &str) -> Result<String> {
24        let alias_prompt = format!(
25            "Generate a shell alias for the following command:\n\n{}",
26            prompt
27        );
28        
29        self.client.generate_content(alias_prompt).await
30    }
31}
32
33pub async fn execute<T: GeminiClientTrait + Send + Sync>(
34    client: T,
35    command: String,
36    tts_manager: Option<&TTSManager>,
37) -> Result<()> {
38    let generate_command = GenerateAliasCommand::new(client);
39    let alias = generate_command.generate_content(&command).await?;
40    println!("{}", alias);
41
42    if let Some(tts) = tts_manager {
43        tts.speak(&alias).await?;
44    }
45
46    Ok(())
47}
48