moon_pdk_api/
common.rs

1use warpgate_api::{api_enum, api_struct, ExecCommandInput, VirtualPath};
2
3api_struct!(
4    /// Information about the current moon workspace.
5    pub struct MoonContext {
6        /// Virtual path to the current working directory.
7        pub working_dir: VirtualPath,
8
9        /// Virtual path to the workspace root.
10        pub workspace_root: VirtualPath,
11    }
12);
13
14impl MoonContext {
15    /// Return the provided file path as an absolute path (using virtual paths).
16    /// If the path is already absolute (either real or virtual), return it.
17    /// Otherwise prefix the path with the current working directory.
18    pub fn get_absolute_path<T: AsRef<std::path::Path>>(&self, path: T) -> VirtualPath {
19        let path = path.as_ref();
20
21        if path.is_absolute() {
22            return VirtualPath::OnlyReal(path.to_owned());
23        }
24
25        self.working_dir.join(path)
26    }
27}
28
29api_enum!(
30    /// An operation to perform within moon (the host) itself.
31    #[serde(tag = "type", rename_all = "kebab-case")]
32    pub enum Operation {
33        ProcessExecution(ExecCommandInput),
34    }
35);