Rest/Fn/Binary/Command/Entry.rs
1/// Generates a list of file paths from the specified root directory, excluding
2/// paths that match any of the specified exclude patterns.
3///
4/// # Argument
5///
6/// * `Option` - A reference to an `Option` struct containing the following
7/// fields:
8/// - `Exclude`: A vector of strings representing patterns to exclude.
9/// - `Root`: The root directory to start the walk from.
10/// - `Separator`: The separator used for splitting file paths.
11///
12/// # Returns
13///
14/// Returns a vector of vectors, where each inner vector contains the components
15/// of a file path split by the specified separator.
16///
17/// # Panics
18///
19/// This function will panic if it encounters an error while reading a directory
20/// entry.
21///
22/// # Example
23///
24/// ```
25/// let options = Option {
26/// Exclude:vec!["node_modules".to_string(), "target".to_string()],
27/// Root:".".to_string(),
28/// Separator:'/',
29/// };
30/// let paths = Fn(&options);
31/// for path in paths {
32/// println!("{:?}", path);
33/// }
34/// ```
35pub fn Fn(Option { Exclude, Root, Pattern, Separator, .. }:&Option) -> Return {
36 WalkDir::new(Root)
37 .follow_links(true)
38 .into_iter()
39 .filter_map(|Entry| {
40 let Path = Entry.expect("Cannot Entry.").path().display().to_string();
41
42 // DEPENDENCY: Separate this into Entry/Exclude.rs
43 if !Exclude
44 .clone()
45 .into_iter()
46 .filter(|Exclude| *Pattern != *Exclude)
47 .any(|Exclude| Path.contains(&Exclude))
48 {
49 Some(Path.split(*Separator).map(|Entry| Entry.to_string()).collect())
50 } else {
51 None
52 }
53 })
54 .collect::<Vec<_>>()
55}
56
57use walkdir::WalkDir;
58
59use crate::Struct::Binary::Command::{Entry::Type as Return, Option::Struct as Option};