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