intelli_shell/service/
mod.rs

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