mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
FEATURE: support only directories will be displayed. Flag -D
This commit is contained in:
@@ -132,4 +132,10 @@ pub fn build_cli() -> Command<'static> {
|
||||
.help("print sizes in powers of 1000 (e.g., 1.1G)")
|
||||
)
|
||||
.arg(Arg::new("inputs").multiple_occurrences(true))
|
||||
.arg(
|
||||
Arg::new("only_dir")
|
||||
.short('D')
|
||||
.long("only-dir")
|
||||
.help("Only directories will be displayed."),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ pub struct Config {
|
||||
pub ignore_hidden: Option<bool>,
|
||||
pub iso: Option<bool>,
|
||||
pub min_size: Option<String>,
|
||||
pub only_dir: Option<bool>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -61,6 +62,9 @@ impl Config {
|
||||
size_from_param
|
||||
}
|
||||
}
|
||||
pub fn get_only_dir(&self, options: &ArgMatches) -> bool {
|
||||
Some(true) == self.only_dir || options.is_present("only_dir")
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_min_size(input: &str, iso: bool) -> Option<usize> {
|
||||
|
||||
+14
-6
@@ -8,6 +8,7 @@ use std::path::PathBuf;
|
||||
pub fn get_biggest(
|
||||
top_level_nodes: Vec<Node>,
|
||||
min_size: Option<usize>,
|
||||
only_dir: bool,
|
||||
n: usize,
|
||||
depth: usize,
|
||||
using_a_filter: bool,
|
||||
@@ -23,14 +24,14 @@ pub fn get_biggest(
|
||||
let mut allowed_nodes = HashSet::new();
|
||||
|
||||
allowed_nodes.insert(root.name.as_path());
|
||||
heap = add_children(using_a_filter, min_size, &root, depth, heap);
|
||||
heap = add_children(using_a_filter, min_size, only_dir, &root, depth, heap);
|
||||
|
||||
for _ in number_top_level_nodes..n {
|
||||
let line = heap.pop();
|
||||
match line {
|
||||
Some(line) => {
|
||||
allowed_nodes.insert(line.name.as_path());
|
||||
heap = add_children(using_a_filter, min_size, line, depth, heap);
|
||||
heap = add_children(using_a_filter, min_size, only_dir, line, depth, heap);
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
@@ -41,15 +42,22 @@ pub fn get_biggest(
|
||||
fn add_children<'a>(
|
||||
using_a_filter: bool,
|
||||
min_size: Option<usize>,
|
||||
only_dir: bool,
|
||||
file_or_folder: &'a Node,
|
||||
depth: usize,
|
||||
mut heap: BinaryHeap<&'a Node>,
|
||||
) -> BinaryHeap<&'a Node> {
|
||||
if depth > file_or_folder.depth {
|
||||
heap.extend(file_or_folder.children.iter().filter(|c| match min_size {
|
||||
Some(ms) => c.size > ms as u64,
|
||||
None => !using_a_filter || c.name.is_file() || c.size > 0,
|
||||
}))
|
||||
heap.extend(
|
||||
file_or_folder
|
||||
.children
|
||||
.iter()
|
||||
.filter(|c| match min_size {
|
||||
Some(ms) => c.size > ms as u64,
|
||||
None => !using_a_filter || c.name.is_file() || c.size > 0,
|
||||
})
|
||||
.filter(|c| if only_dir { c.name.is_dir() } else { true }),
|
||||
)
|
||||
}
|
||||
heap
|
||||
}
|
||||
|
||||
@@ -181,6 +181,7 @@ fn main() {
|
||||
false => get_biggest(
|
||||
top_level_nodes,
|
||||
config.get_min_size(&options, iso),
|
||||
config.get_only_dir(&options),
|
||||
number_of_lines,
|
||||
depth,
|
||||
options.values_of("filter").is_some() || options.value_of("invert_filter").is_some(),
|
||||
|
||||
Reference in New Issue
Block a user