Skip to content

Commit 78a3354

Browse files
committed
cfsctl: Switch to comfy_table
So we get correct line wrapping. Signed-off-by: Colin Walters <walters@verbum.org> Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com> Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 6f4176a commit 78a3354

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

crates/cfsctl/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rhel9 = ['composefs/rhel9']
2121
anyhow = { version = "1.0.87", default-features = false }
2222
fn-error-context = "0.2"
2323
clap = { version = "4.5.0", default-features = false, features = ["std", "help", "usage", "derive", "wrap_help"] }
24+
comfy-table = { version = "7.1", default-features = false }
2425
composefs = { workspace = true }
2526
composefs-boot = { workspace = true }
2627
composefs-oci = { workspace = true, optional = true }

crates/cfsctl/src/main.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::{
1313

1414
use anyhow::Result;
1515
use clap::{Parser, Subcommand, ValueEnum};
16+
use comfy_table::{presets::UTF8_FULL, Table};
1617

1718
use rustix::fs::CWD;
1819

@@ -427,10 +428,10 @@ where
427428
} else if images.is_empty() {
428429
println!("No images found");
429430
} else {
430-
println!(
431-
"{:<30} {:<12} {:<10} {:<8} {:<6} {:<5}",
432-
"NAME", "DIGEST", "ARCH", "SEALED", "LAYERS", "REFS"
433-
);
431+
let mut table = Table::new();
432+
table.load_preset(UTF8_FULL);
433+
table.set_header(["NAME", "DIGEST", "ARCH", "SEALED", "LAYERS", "REFS"]);
434+
434435
for img in images {
435436
let digest_short = img
436437
.manifest_digest
@@ -441,20 +442,22 @@ where
441442
} else {
442443
digest_short
443444
};
444-
println!(
445-
"{:<30} {:<12} {:<10} {:<8} {:<6} {:<5}",
446-
img.name,
445+
let arch = if img.architecture.is_empty() {
446+
"artifact"
447+
} else {
448+
&img.architecture
449+
};
450+
let sealed = if img.sealed { "yes" } else { "no" };
451+
table.add_row([
452+
img.name.as_str(),
447453
digest_display,
448-
if img.architecture.is_empty() {
449-
"artifact"
450-
} else {
451-
&img.architecture
452-
},
453-
if img.sealed { "yes" } else { "no" },
454-
img.layer_count,
455-
img.referrer_count
456-
);
454+
arch,
455+
sealed,
456+
&img.layer_count.to_string(),
457+
&img.referrer_count.to_string(),
458+
]);
457459
}
460+
println!("{table}");
458461
}
459462
}
460463
OciCommand::Inspect {

0 commit comments

Comments
 (0)