Skip to main content

agent_migrate_adapters/
context.rs

1use std::path::{Path, PathBuf};
2
3use agent_migrate_core::{ManifestIdentity, Scope};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct ScanContext {
7    home: PathBuf,
8    scope: Scope,
9    workspace: Option<PathBuf>,
10}
11
12impl ScanContext {
13    #[must_use]
14    pub fn new(home: PathBuf, scope: Scope, workspace: Option<PathBuf>) -> Self {
15        Self {
16            home,
17            scope,
18            workspace,
19        }
20    }
21
22    #[must_use]
23    pub fn global(home: &Path) -> Self {
24        Self::new(home.to_path_buf(), Scope::Global, None)
25    }
26
27    #[must_use]
28    pub fn project(home: &Path, workspace: &Path) -> Self {
29        Self::new(
30            home.to_path_buf(),
31            Scope::Project,
32            Some(workspace.to_path_buf()),
33        )
34    }
35
36    #[must_use]
37    pub fn home(&self) -> &Path {
38        &self.home
39    }
40
41    #[must_use]
42    pub const fn scope(&self) -> Scope {
43        self.scope
44    }
45
46    #[must_use]
47    pub fn workspace(&self) -> Option<&Path> {
48        self.workspace.as_deref()
49    }
50}
51
52#[derive(Debug, Clone, PartialEq, Eq)]
53pub struct ExportContext {
54    scan: ScanContext,
55    agent_version: String,
56    identity: ManifestIdentity,
57}
58
59impl ExportContext {
60    #[must_use]
61    pub fn new(
62        scan: ScanContext,
63        agent_version: impl Into<String>,
64        identity: ManifestIdentity,
65    ) -> Self {
66        Self {
67            scan,
68            agent_version: agent_version.into(),
69            identity,
70        }
71    }
72
73    #[must_use]
74    pub const fn scan(&self) -> &ScanContext {
75        &self.scan
76    }
77
78    #[must_use]
79    pub fn agent_version(&self) -> &str {
80        &self.agent_version
81    }
82
83    #[must_use]
84    pub const fn identity(&self) -> ManifestIdentity {
85        self.identity
86    }
87}