intelli_shell/service/
mod.rs

1use std::{
2    path::{Path, PathBuf},
3    sync::{Arc, Mutex},
4};
5
6use crate::{
7    config::{AiConfig, SearchTuning},
8    errors::Result,
9    storage::SqliteStorage,
10};
11
12mod ai;
13mod command;
14mod import_export;
15mod tldr;
16mod variable;
17mod version;
18
19pub use ai::AiFixProgress;
20pub use tldr::{RepoStatus, TldrFetchProgress};
21
22/// Service for managing user commands in IntelliShell
23#[derive(Clone)]
24pub struct IntelliShellService {
25    check_updates: bool,
26    storage: SqliteStorage,
27    tuning: SearchTuning,
28    ai: AiConfig,
29    tldr_repo_path: PathBuf,
30    version_check_state: Arc<Mutex<version::VersionCheckState>>,
31}
32
33impl IntelliShellService {
34    /// Creates a new instance of `IntelliShellService`
35    pub fn new(
36        storage: SqliteStorage,
37        tuning: SearchTuning,
38        ai: AiConfig,
39        data_dir: impl AsRef<Path>,
40        check_updates: bool,
41    ) -> Self {
42        Self {
43            check_updates,
44            storage,
45            tuning,
46            ai,
47            tldr_repo_path: data_dir.as_ref().join("tldr"),
48            version_check_state: Arc::new(Mutex::new(version::VersionCheckState::NotStarted)),
49        }
50    }
51
52    #[cfg(debug_assertions)]
53    pub async fn query(&self, sql: String) -> Result<String> {
54        self.storage.query(sql).await
55    }
56}