Library/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
27/// Exclude:vec!["node_modules".to_string(), "target".to_string()],
28
29/// Root:".".to_string(),
30
31/// Separator:'/',
32
33/// };
34
35/// let paths = Fn(&options);
36
37/// for path in paths {
38
39/// println!("{:?}", path);
40
41/// }
42
43/// ```
44pub fn Fn(Option { Exclude, Root, Pattern, Separator, .. }:&Option) -> Return {
45 WalkDir::new(Root)
46 .follow_links(true)
47 .into_iter()
48 .filter_map(|Entry| {
49 let Path = Entry.expect("Cannot Entry.").path().display().to_string();
50
51 // TODO: Separate this into Entry/Exclude.rs
52 if !Exclude
53 .clone()
54 .into_iter()
55 .filter(|Exclude| *Pattern != *Exclude)
56 .any(|Exclude| Path.contains(&Exclude))
57 {
58 Some(Path.split(*Separator).map(|Entry| Entry.to_string()).collect())
59 } else {
60 None
61 }
62 })
63 .collect::<Vec<_>>()
64}
65
66use walkdir::WalkDir;
67
68use crate::Struct::Binary::Command::{Entry::Type as Return, Option::Struct as Option};