forester_rs/runtime/builder/
file_builder.rs1use crate::runtime::{RtResult, RuntimeError};
2use crate::tree::project::{FileName, Project, TreeName};
3use std::path::PathBuf;
4
5pub struct FileForesterBuilder {
7 main_file: Option<FileName>,
8 main: Option<TreeName>,
9 pub(super) root: Option<PathBuf>,
10}
11
12impl FileForesterBuilder {
13 pub fn new() -> Self {
14 Self {
15 main_file: None,
16 main: None,
17 root: None,
18 }
19 }
20
21 pub fn root(&mut self, root: PathBuf) {
23 self.root = Some(root);
24 }
25 pub fn main_file(&mut self, main_file: FileName) {
27 self.main_file = Some(main_file);
28 }
29 pub fn main_tree(&mut self, main_tree: TreeName) {
31 self.main = Some(main_tree);
32 }
33
34 pub fn build(self) -> RtResult<Project> {
36 match (self.main, self.root.clone(), self.main_file) {
37 (None, Some(root), Some(mf)) => Ok(Project::build(mf, root)?),
38 (Some(mt), Some(root), Some(mf)) => Ok(Project::build_with_root(mf, mt, root)?),
39 _ => Err(RuntimeError::UnImplementedAction(
40 "not enough arguments to initialize the project".to_string(),
41 )),
42 }
43 }
44}