mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
By default only print last leaf of path
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
This commit is contained in:
+38
-31
@@ -15,35 +15,44 @@ pub fn test_main() {
|
||||
assert_cli::Assert::main_binary()
|
||||
.with_args(&["src/test_dir"])
|
||||
.stdout()
|
||||
.is(main_output())
|
||||
.is(main_output(true))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_main_long_paths() {
|
||||
assert_cli::Assert::main_binary()
|
||||
.with_args(&["-p", "src/test_dir"])
|
||||
.stdout()
|
||||
.is(main_output(false))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn main_output() -> String {
|
||||
fn main_output(short_paths: bool) -> String {
|
||||
format!(
|
||||
"{}
|
||||
{}
|
||||
{}
|
||||
{}",
|
||||
format_string("src/test_dir", true, " 4.0K", ""),
|
||||
format_string("src/test_dir/many", true, " 4.0K", "└─┬",),
|
||||
format_string("src/test_dir/many/hello_file", true, " 4.0K", " ├──",),
|
||||
format_string("src/test_dir/many/a_file", false, " 0B", " └──",),
|
||||
format_string("src/test_dir", true, short_paths, " 4.0K", ""),
|
||||
format_string("src/test_dir/many", true, short_paths, " 4.0K", "└─┬",),
|
||||
format_string("src/test_dir/many/hello_file", true, short_paths, " 4.0K", " ├──",),
|
||||
format_string("src/test_dir/many/a_file", false, short_paths, " 0B", " └──",),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn main_output() -> String {
|
||||
fn main_output(short_paths: bool) -> String {
|
||||
format!(
|
||||
"{}
|
||||
{}
|
||||
{}
|
||||
{}",
|
||||
format_string("src/test_dir", true, " 12K", ""),
|
||||
format_string("src/test_dir/many", true, " 8.0K", "└─┬",),
|
||||
format_string("src/test_dir/many/hello_file", true, " 4.0K", " ├──",),
|
||||
format_string("src/test_dir/many/a_file", false, " 0B", " └──",),
|
||||
format_string("src/test_dir", true, short_paths, " 12K", ""),
|
||||
format_string("src/test_dir/many", true, short_paths, " 8.0K", "└─┬",),
|
||||
format_string("src/test_dir/many/hello_file", true, short_paths, " 4.0K", " ├──",),
|
||||
format_string("src/test_dir/many/a_file", false, short_paths, " 0B", " └──",),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -51,7 +60,7 @@ fn main_output() -> String {
|
||||
pub fn test_apparent_size() {
|
||||
let r = format!(
|
||||
"{}",
|
||||
format_string("src/test_dir/many/hello_file", true, " 6B", " ├──",),
|
||||
format_string("src/test_dir/many/hello_file", true, true, " 6B", " ├──",),
|
||||
);
|
||||
|
||||
assert_cli::Assert::main_binary()
|
||||
@@ -97,9 +106,9 @@ fn soft_sym_link_output(dir: &str, file_path: &str, link_name: &str) -> String {
|
||||
"{}
|
||||
{}
|
||||
{}",
|
||||
format_string(dir, true, " 8.0K", ""),
|
||||
format_string(file_path, true, " 4.0K", "├──",),
|
||||
format_string(link_name, false, " 4.0K", "└──",),
|
||||
format_string(dir, true, true, " 8.0K", ""),
|
||||
format_string(file_path, true, true, " 4.0K", "├──",),
|
||||
format_string(link_name, false, true, " 4.0K", "└──",),
|
||||
)
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -108,9 +117,9 @@ fn soft_sym_link_output(dir: &str, file_path: &str, link_name: &str) -> String {
|
||||
"{}
|
||||
{}
|
||||
{}",
|
||||
format_string(dir, true, " 8.0K", ""),
|
||||
format_string(file_path, true, " 4.0K", "├──",),
|
||||
format_string(link_name, false, " 0B", "└──",),
|
||||
format_string(dir, true, true, " 8.0K", ""),
|
||||
format_string(file_path, true, true, " 4.0K", "├──",),
|
||||
format_string(link_name, false, true, " 0B", "└──",),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -156,14 +165,14 @@ fn hard_link_output(dir_s: &str, file_path_s: &str, link_name_s: &str) -> (Strin
|
||||
let r = format!(
|
||||
"{}
|
||||
{}",
|
||||
format_string(dir_s, true, " 4.0K", ""),
|
||||
format_string(file_path_s, true, " 4.0K", "└──")
|
||||
format_string(dir_s, true, true, " 4.0K", ""),
|
||||
format_string(file_path_s, true, true, " 4.0K", "└──")
|
||||
);
|
||||
let r2 = format!(
|
||||
"{}
|
||||
{}",
|
||||
format_string(dir_s, true, " 4.0K", ""),
|
||||
format_string(link_name_s, true, " 4.0K", "└──")
|
||||
format_string(dir_s, true, true, " 4.0K", ""),
|
||||
format_string(link_name_s, true, true, " 4.0K", "└──")
|
||||
);
|
||||
(r, r2)
|
||||
}
|
||||
@@ -173,9 +182,8 @@ fn hard_link_output(dir_s: &str, file_path_s: &str, link_name_s: &str) -> (Strin
|
||||
let r = format!(
|
||||
"{}
|
||||
{}",
|
||||
|
||||
format_string(dir_s, true, " 8.0K", ""),
|
||||
format_string(file_path_s, true, " 4.0K", "└──")
|
||||
format_string(dir_s, true, true, " 8.0K", ""),
|
||||
format_string(file_path_s, true, true, " 4.0K", "└──")
|
||||
);
|
||||
let r2 = format!(
|
||||
"{}
|
||||
@@ -214,8 +222,8 @@ fn recursive_sym_link_output(dir: &str, link_name: &str) -> String {
|
||||
format!(
|
||||
"{}
|
||||
{}",
|
||||
format_string(dir, true, " 4.0K", ""),
|
||||
format_string(link_name, true, " 4.0K", "└──",),
|
||||
format_string(dir, true, true, " 4.0K", ""),
|
||||
format_string(link_name, true, true, " 4.0K", "└──",),
|
||||
)
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -223,10 +231,9 @@ fn recursive_sym_link_output(dir: &str, link_name: &str) -> String {
|
||||
format!(
|
||||
"{}
|
||||
{}",
|
||||
format_string(dir, true, " 4.0K", ""),
|
||||
format_string(link_name, true, " 0B", "└──",),
|
||||
format_string(dir, true, true, " 4.0K", ""),
|
||||
format_string(link_name, true, true, " 0B", "└──",),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
// TODO: add test for bad path
|
||||
// TODO: add test for bad path
|
||||
|
||||
Reference in New Issue
Block a user