1mod anchor;
7mod cargo;
8mod go;
9mod node;
10mod python;
11
12pub use anchor::AnchorParser;
13pub use cargo::CargoParser;
14pub use go::GoParser;
15pub use node::NodeParser;
16pub use python::PythonParser;
17
18use kdo_core::{Dependency, KdoError, Project};
19use std::path::Path;
20
21pub trait ManifestParser {
23 fn manifest_name(&self) -> &str;
25
26 fn can_parse(&self, manifest_path: &Path) -> bool;
28
29 fn parse(
33 &self,
34 manifest_path: &Path,
35 workspace_root: &Path,
36 ) -> Result<(Project, Vec<Dependency>), KdoError>;
37}
38
39pub fn parse_manifest(
43 manifest_path: &Path,
44 workspace_root: &Path,
45) -> Result<(Project, Vec<Dependency>), KdoError> {
46 let parsers: Vec<Box<dyn ManifestParser>> = vec![
47 Box::new(AnchorParser),
48 Box::new(CargoParser),
49 Box::new(NodeParser),
50 Box::new(PythonParser),
51 Box::new(GoParser),
52 ];
53
54 for parser in &parsers {
55 if parser.can_parse(manifest_path) {
56 return parser.parse(manifest_path, workspace_root);
57 }
58 }
59
60 Err(KdoError::ManifestNotFound(manifest_path.to_path_buf()))
61}
62
63pub fn manifest_filenames() -> &'static [&'static str] {
65 &[
66 "Anchor.toml",
67 "Cargo.toml",
68 "package.json",
69 "pyproject.toml",
70 "go.mod",
71 ]
72}