mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
803934d84b
Fixes #9 https://github.com/bootandy/dust/issues/9 Instead of printing the all sub tree leaves only the last leaf is now printed. See readme change for example The flag '-p' was added to print the sub tree the old way
55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
#[macro_use]
|
|
extern crate clap;
|
|
extern crate assert_cli;
|
|
extern crate walkdir;
|
|
|
|
use self::display::draw_it;
|
|
use clap::{App, AppSettings, Arg};
|
|
use utils::{find_big_ones, get_dir_tree};
|
|
|
|
mod display;
|
|
mod utils;
|
|
|
|
static DEFAULT_NUMBER_OF_LINES: &'static str = "15";
|
|
|
|
fn main() {
|
|
let options = App::new("Dust")
|
|
.setting(AppSettings::TrailingVarArg)
|
|
.arg(
|
|
Arg::with_name("number_of_lines")
|
|
.short("n")
|
|
.help("Number of lines of output to show")
|
|
.takes_value(true)
|
|
.default_value(DEFAULT_NUMBER_OF_LINES),
|
|
)
|
|
.arg(
|
|
Arg::with_name("display_full_paths")
|
|
.short("p")
|
|
.help("If set sub directories will not have their path shortened"),
|
|
)
|
|
.arg(
|
|
Arg::with_name("display_apparent_size")
|
|
.short("s")
|
|
.help("If set will use file length. Otherwise we use blocks"),
|
|
)
|
|
.arg(Arg::with_name("inputs").multiple(true))
|
|
.get_matches();
|
|
|
|
let filenames = {
|
|
match options.values_of("inputs") {
|
|
None => vec!["."],
|
|
Some(r) => r.collect(),
|
|
}
|
|
};
|
|
let number_of_lines = value_t!(options.value_of("number_of_lines"), usize).unwrap();
|
|
let use_apparent_size = options.is_present("display_apparent_size");
|
|
let use_full_path = options.is_present("display_full_paths");
|
|
|
|
let (permissions, nodes) = get_dir_tree(&filenames, use_apparent_size);
|
|
let biggest_ones = find_big_ones(nodes, number_of_lines);
|
|
draw_it(permissions, !use_full_path, filenames, biggest_ones);
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|