mod anchor;
mod cargo;
mod go;
mod node;
mod python;
pub use anchor::AnchorParser;
pub use cargo::CargoParser;
pub use go::GoParser;
pub use node::NodeParser;
pub use python::PythonParser;
use kdo_core::{Dependency, KdoError, Project};
use std::path::Path;
pub trait ManifestParser {
fn manifest_name(&self) -> &str;
fn can_parse(&self, manifest_path: &Path) -> bool;
fn parse(
&self,
manifest_path: &Path,
workspace_root: &Path,
) -> Result<(Project, Vec<Dependency>), KdoError>;
}
pub fn parse_manifest(
manifest_path: &Path,
workspace_root: &Path,
) -> Result<(Project, Vec<Dependency>), KdoError> {
let parsers: Vec<Box<dyn ManifestParser>> = vec![
Box::new(AnchorParser),
Box::new(CargoParser),
Box::new(NodeParser),
Box::new(PythonParser),
Box::new(GoParser),
];
for parser in &parsers {
if parser.can_parse(manifest_path) {
return parser.parse(manifest_path, workspace_root);
}
}
Err(KdoError::ManifestNotFound(manifest_path.to_path_buf()))
}
pub fn manifest_filenames() -> &'static [&'static str] {
&[
"Anchor.toml",
"Cargo.toml",
"package.json",
"pyproject.toml",
"go.mod",
]
}