Fix ignore rules

This commit is contained in:
Olivier 'reivilibre' 2023-08-11 20:31:08 +01:00
parent 6b72672d29
commit 5137ac0640
2 changed files with 17 additions and 4 deletions

View File

@ -52,7 +52,11 @@ pub enum YamaScanCommand {
/// Show dust-style usage graph of the current directory, excluding excluded files.
#[command(alias = "du")]
Usage {},
Usage {
/// Specify an ignore rule. Can use multiple times.
#[arg(short = 'I', long = "ignore")]
ignore: Vec<String>,
},
}
#[tokio::main]
@ -66,7 +70,7 @@ async fn main() -> eyre::Result<()> {
.init();
match YamaScanCommand::parse() {
YamaScanCommand::Usage {} => {
YamaScanCommand::Usage { ignore } => {
let idd = InitialDisplayData {
short_paths: true,
is_reversed: false,
@ -76,7 +80,7 @@ async fn main() -> eyre::Result<()> {
iso: false,
};
let scan = scan::scan(Path::new("."), &Vec::new()).context("Couldn't scan")?;
let scan = scan::scan(Path::new("."), &ignore).context("Couldn't scan")?;
let top_nodes = assemble_display_tree_from_scan_entries(scan)?.children;
let root_display_node = dust_style_filetree_display::filter::get_biggest(

View File

@ -1,4 +1,5 @@
use eyre::{bail, eyre, Context, ContextCompat};
use ignore::overrides::OverrideBuilder;
use ignore::WalkBuilder;
use patricia_tree::PatriciaMap;
use std::cmp::max;
@ -117,9 +118,17 @@ pub fn scan(root: &Path, ignores: &Vec<String>) -> eyre::Result<PatriciaMap<Scan
.follow_links(false)
.same_file_system(true);
let mut overrides = OverrideBuilder::new(root);
for ign in ignores {
walker.add_ignore(ign);
overrides
.add(&("!".to_owned() + ign))
.with_context(|| format!("failed to add ignore rule: {ign:?}"))?;
}
walker.overrides(
overrides
.build()
.context("failed to create overrides with ignore entries")?,
);
let walker = walker.build();
for entry in walker {