mirror of
https://github.com/bootandy/dust.git
synced 2025-12-05 20:40:11 -08:00
fix: dont format filecount when output is set to json
This commit is contained in:
@@ -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 {
|
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) {
|
match get_number_format(output_str) {
|
||||||
Some((x, u)) => {
|
Some((x, u)) => {
|
||||||
format!("{}{}", (size / x), u)
|
format!("{}{}", (size / x), u)
|
||||||
@@ -539,6 +542,13 @@ mod tests {
|
|||||||
assert_eq!(s, "short 3 4.0K 100%");
|
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]
|
#[test]
|
||||||
fn test_human_readable_number() {
|
fn test_human_readable_number() {
|
||||||
assert_eq!(human_readable_number(1, ""), "1B");
|
assert_eq!(human_readable_number(1, ""), "1B");
|
||||||
|
|||||||
@@ -319,7 +319,11 @@ fn print_output(
|
|||||||
|
|
||||||
if config.get_output_json(&options) {
|
if config.get_output_json(&options) {
|
||||||
OUTPUT_TYPE.with(|wrapped| {
|
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());
|
println!("{}", serde_json::to_string(&tree).unwrap());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user