From f98b841d23218cb33828bc69826829eefd0d658a Mon Sep 17 00:00:00 2001 From: AminurAlam <64137875+AminurAlam@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:55:18 +0530 Subject: [PATCH] fix: dont format filecount when output is set to json --- src/display.rs | 10 ++++++++++ src/main.rs | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/display.rs b/src/display.rs index d24af1d..978d3b6 100644 --- a/src/display.rs +++ b/src/display.rs @@ -439,6 +439,9 @@ pub fn get_number_format(output_str: &str) -> Option<(u64, char)> { } pub fn human_readable_number(size: u64, output_str: &str) -> String { + if output_str == "count" { + return size.to_string(); + }; match get_number_format(output_str) { Some((x, u)) => { format!("{}{}", (size / x), u) @@ -539,6 +542,13 @@ mod tests { assert_eq!(s, "short 3 4.0K 100%"); } + #[test] + fn test_machine_readable_filecount() { + assert_eq!(human_readable_number(1, "count"), "1"); + assert_eq!(human_readable_number(1000, "count"), "1000"); + assert_eq!(human_readable_number(1024, "count"), "1024"); + } + #[test] fn test_human_readable_number() { assert_eq!(human_readable_number(1, ""), "1B"); diff --git a/src/main.rs b/src/main.rs index 9ecab8c..2b01312 100644 --- a/src/main.rs +++ b/src/main.rs @@ -319,7 +319,11 @@ fn print_output( if config.get_output_json(&options) { OUTPUT_TYPE.with(|wrapped| { - wrapped.replace(output_format); + if by_filecount { + wrapped.replace("count".to_string()); + } else { + wrapped.replace(output_format); + } }); println!("{}", serde_json::to_string(&tree).unwrap()); } else {