aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart/src/commands
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-23 01:30:45 +0900
committernsfisis <nsfisis@gmail.com>2026-02-23 01:57:21 +0900
commit9ef46a76b1d0c85e7a45de3874ca203a86dad567 (patch)
treefc99c2f5ce8c7509dc256b930b6bf39f022b45f9 /crates/mozart/src/commands
parent587a79ec395c3e7ed861b19099ffefefac64e3b5 (diff)
downloadphp-mozart-9ef46a76b1d0c85e7a45de3874ca203a86dad567.tar.gz
php-mozart-9ef46a76b1d0c85e7a45de3874ca203a86dad567.tar.zst
php-mozart-9ef46a76b1d0c85e7a45de3874ca203a86dad567.zip
fix(licenses): add table headers and bordered summary output
Match Composer's Symfony Table formatting: add Name/Version/Licenses header row to text output and use bordered ASCII table for summary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src/commands')
-rw-r--r--crates/mozart/src/commands/licenses.rs62
1 files changed, 54 insertions, 8 deletions
diff --git a/crates/mozart/src/commands/licenses.rs b/crates/mozart/src/commands/licenses.rs
index 577d0b5..d07305e 100644
--- a/crates/mozart/src/commands/licenses.rs
+++ b/crates/mozart/src/commands/licenses.rs
@@ -222,9 +222,28 @@ fn render_text(
return;
}
- // Compute column widths
- let name_width = entries.iter().map(|e| e.name.len()).max().unwrap_or(0);
- let version_width = entries.iter().map(|e| e.version.len()).max().unwrap_or(0);
+ // Compute column widths (factor in header strings for minimum width)
+ let name_width = entries
+ .iter()
+ .map(|e| e.name.len())
+ .max()
+ .unwrap_or(0)
+ .max("Name".len());
+ let version_width = entries
+ .iter()
+ .map(|e| e.version.len())
+ .max()
+ .unwrap_or(0)
+ .max("Version".len());
+
+ // Print header row
+ println!(
+ "{:<nw$} {:<vw$} Licenses",
+ "Name",
+ "Version",
+ nw = name_width,
+ vw = version_width
+ );
for entry in entries {
let license_str = if entry.licenses.is_empty() {
@@ -293,23 +312,50 @@ fn render_summary(entries: &[LicenseEntry]) {
return;
}
+ const COL2_HEADER: &str = "Number of dependencies";
+
+ // Compute column widths (at least as wide as the header strings)
let license_width = counts
.iter()
.map(|(l, _)| l.len())
.max()
.unwrap_or(0)
.max("License".len());
+ let count_width = counts
+ .iter()
+ .map(|(_, c)| c.to_string().len())
+ .max()
+ .unwrap_or(0)
+ .max(COL2_HEADER.len());
+ // Each column is padded with 1 space on each side, so the border dash count = width + 2
+ let border_col1 = "-".repeat(license_width + 2);
+ let border_col2 = "-".repeat(count_width + 2);
+
+ // Top border
+ println!(" {} {}", border_col1, border_col2);
+ // Header row (two leading spaces = one space indent + one space left-padding)
println!(
- "{:<lw$} Number of dependencies",
+ " {:<lw$} {:<cw$}",
"License",
- lw = license_width
+ COL2_HEADER,
+ lw = license_width,
+ cw = count_width
);
- println!("{:-<lw$} ----------------------", "", lw = license_width);
-
+ // Mid border
+ println!(" {} {}", border_col1, border_col2);
+ // Data rows
for (license, count) in &counts {
- println!("{:<lw$} {}", license, count, lw = license_width);
+ println!(
+ " {:<lw$} {:<cw$}",
+ license,
+ count,
+ lw = license_width,
+ cw = count_width
+ );
}
+ // Bottom border
+ println!(" {} {}", border_col1, border_col2);
}
// ─── Tests ───────────────────────────────────────────────────────────────────