client: display show-db output with human readable sizes
All checks were successful
Build and test / check-license (push) Successful in 55s
Build and test / check (push) Successful in 1m55s
Build and test / build (push) Successful in 3m25s
Build and test / test (push) Successful in 3m4s
Build and test / docs (push) Successful in 5m54s

This commit is contained in:
2025-12-16 14:36:49 +09:00
parent 256c1d1176
commit 57ac26b120
4 changed files with 30 additions and 4 deletions

10
Cargo.lock generated
View File

@@ -861,6 +861,15 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "humansize"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7"
dependencies = [
"libm",
]
[[package]]
name = "icu_collections"
version = "2.1.1"
@@ -1205,6 +1214,7 @@ dependencies = [
"dialoguer",
"futures-util",
"git2",
"humansize",
"indoc",
"itertools",
"landlock",

View File

@@ -29,6 +29,7 @@ const_format = "0.2.35"
derive_more = { version = "2.1.0", features = ["display", "error"] }
dialoguer = "0.12.0"
futures-util = "0.3.31"
humansize = "2.1.3"
indoc = "2.0.7"
itertools = "0.14.0"
nix = { version = "0.30.1", features = ["fs", "process", "socket", "user"] }

View File

@@ -26,6 +26,10 @@ pub struct ShowDbArgs {
/// Print the information as JSON
#[arg(short, long)]
json: bool,
/// Show sizes in bytes instead of human-readable format
#[arg(short, long)]
bytes: bool,
}
pub async fn show_databases(
@@ -60,7 +64,7 @@ pub async fn show_databases(
if args.json {
print_list_databases_output_status_json(&databases);
} else {
print_list_databases_output_status(&databases);
print_list_databases_output_status(&databases, args.bytes);
if databases.iter().any(|(_, res)| {
matches!(

View File

@@ -30,7 +30,10 @@ pub enum ListDatabasesError {
MySqlError(String),
}
pub fn print_list_databases_output_status(output: &ListDatabasesResponse) {
pub fn print_list_databases_output_status(
output: &ListDatabasesResponse,
display_size_as_bytes: bool,
) {
let mut final_database_list: Vec<&DatabaseRow> = Vec::new();
for (db_name, db_result) in output {
match db_result {
@@ -52,7 +55,11 @@ pub fn print_list_databases_output_status(output: &ListDatabasesResponse) {
"Users",
"Collation",
"Character Set",
if display_size_as_bytes {
"Size (Bytes)"
} else {
"Size"
}
]);
for db in final_database_list {
table.add_row(row![
@@ -61,7 +68,11 @@ pub fn print_list_databases_output_status(output: &ListDatabasesResponse) {
db.users.iter().map(|user| user.as_str()).join("\n"),
db.collation.as_deref().unwrap_or("N/A"),
db.character_set.as_deref().unwrap_or("N/A"),
db.size_bytes,
if display_size_as_bytes {
db.size_bytes.to_string()
} else {
humansize::format_size(db.size_bytes, humansize::DECIMAL)
}
]);
}