Skip to main content

Format numbers as comma-separated strings

ID
5c7ac2a
date
2024-06-18 21:23:07+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
93160b6
message
Format numbers as comma-separated strings
changed files
3 files, 29 additions, 1 deletion

Changed files

Cargo.lock (12371) → Cargo.lock (13002)

diff --git a/Cargo.lock b/Cargo.lock
index ef4d592..dc50b4a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -52,6 +52,12 @@ dependencies = [
 ]
 
 [[package]]
+name = "arrayvec"
+version = "0.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
+
+[[package]]
 name = "clap"
 version = "4.5.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -113,6 +119,7 @@ version = "0.1.0"
 dependencies = [
  "clap",
  "colored",
+ "num-format",
  "tempdir",
  "walkdir",
 ]
@@ -136,6 +143,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
 
 [[package]]
+name = "itoa"
+version = "1.0.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
+
+[[package]]
 name = "lazy_static"
 version = "1.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -148,6 +161,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
 
 [[package]]
+name = "num-format"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3"
+dependencies = [
+ "arrayvec",
+ "itoa",
+]
+
+[[package]]
 name = "proc-macro2"
 version = "1.0.85"
 source = "registry+https://github.com/rust-lang/crates.io-index"

Cargo.toml (181) → Cargo.toml (202)

diff --git a/Cargo.toml b/Cargo.toml
index f8387b2..274b321 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,5 +6,6 @@ edition = "2021"
 [dependencies]
 clap = { version = "4.5.7", features = ["derive"] }
 colored = "2.1.0"
+num-format = "0.4.4"
 tempdir = "0.3.7"
 walkdir = "2"

src/main.rs (823) → src/main.rs (947)

diff --git a/src/main.rs b/src/main.rs
index d80a1f7..142f95b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,7 @@ use std::path::Path;
 
 use clap::Parser;
 use colored::*;
+use num_format::{Locale, ToFormattedString};
 
 mod can_be_deleted;
 mod emptydir;
@@ -26,7 +27,10 @@ fn main() -> Result<(), std::io::Error> {
         0 => println!("{}", "No empty directories found".blue()),
         1 => println!("{}", "1 directory deleted".green()),
         _ => {
-            let message = format!("{} directories deleted", count_deleted);
+            let message = format!(
+                "{} directories deleted",
+                count_deleted.to_formatted_string(&Locale::en)
+            );
             println!("{}", message.green());
         }
     }