Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub struct Interface {
/// Limit depth of the tree in output.
#[clap(long, short)]
pub limit: Option<usize>,
/// Include paths matching a regex pattern. Repeatable.
#[clap(long, short = 'I', value_name = "PATTERN")]
pub include: Vec<String>,
/// Exclude paths matching a regex pattern. Repeatable.
#[clap(long, short = 'E', value_name = "PATTERN")]
pub exclude: Vec<String>,
Expand Down
17 changes: 17 additions & 0 deletions src/tre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct RunOptions {
pub output_json: bool,
pub root: String,
pub max_depth: Option<usize>,
pub include_patterns: Vec<Regex>,
pub exclude_patterns: Vec<Regex>,
pub coloring: cli::Coloring,
pub portable_aliases: bool,
Expand Down Expand Up @@ -58,6 +59,11 @@ impl From<cli::Interface> for RunOptions {
output_json: inputs.json,
root: inputs.path,
max_depth: inputs.limit,
include_patterns: inputs
.include
.iter()
.filter_map(|p| regex::Regex::new(p).ok())
.collect(),
exclude_patterns: inputs
.exclude
.iter()
Expand All @@ -84,6 +90,17 @@ pub fn run(option: RunOptions) {
}
};

let paths = if option.include_patterns.is_empty() {
paths
} else {
paths
.into_iter()
.filter(|(path, _)| {
let mut pattern_iters = option.include_patterns.iter();
pattern_iters.any(|p| p.is_match(path))
})
.collect()
};
let paths = if option.exclude_patterns.is_empty() {
paths
} else {
Expand Down