assemble_std/specs/
dupe_spec.rs

1//! Define the DupeSpec
2
3use assemble_core::file_collection::FileSet;
4use assemble_core::project::VisitProject;
5use assemble_core::utilities::{Spec, Work};
6use assemble_core::Project;
7use std::path::{Path, PathBuf};
8
9/// A dupe spec is used for copying files around. All values (besides children) are inherited
10/// by children specs unless specified otherwise. Include and Excludes are always inherited
11pub struct DupeSpec {
12    /// The files to copy from. If not set, uses the parent spec
13    from: Option<FileSet>,
14    /// The target directory to copy files in. If not set, uses the parent spec
15    into: Option<PathBuf>,
16    /// Filters which files to include
17    include: Box<dyn Spec<Path>>,
18    /// Filters which files should be excluded.
19    ///
20    /// Only files which pass the included filter are tested to be excluded.
21    exclude: Box<dyn Spec<Path>>,
22    parent: Option<Box<DupeSpec>>,
23}
24
25impl DupeSpec {
26    fn get_from(&self) -> Option<&FileSet> {
27        self.from
28            .as_ref()
29            .or_else(|| self.parent.as_ref().and_then(|p| p.get_from()))
30    }
31
32    fn get_into(&self) -> Option<&Path> {
33        self.into
34            .as_deref()
35            .or_else(|| self.parent.as_ref().and_then(|p| p.get_into()))
36    }
37
38    fn is_included(&self, path: &Path) -> bool {
39        if let Some(parent) = &self.parent {
40            if !parent.is_included(path) {
41                return false;
42            }
43        }
44        self.include.accept(path) && !self.exclude.accept(path)
45    }
46
47    // fn copy(&self, from: ) -> Work {
48    //     todo!()
49    // }
50}
51
52impl VisitProject<Work> for DupeSpec {
53    fn visit(&mut self, _project: &Project) -> Work {
54        todo!()
55    }
56}