From 46845eff8d1398f35099a0ef914f77bcaf473287 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 10 May 2026 15:29:19 +0900 Subject: refactor(io): introduce IoInterface trait mirroring Composer IOInterface Add an `IoInterface` trait in mozart-core::console that mirrors `\Composer\IO\IOInterface`, implement it for `Console`, and switch commands, the auditor, and the suggested-packages reporter to accept the abstracted IO (typically `Arc>>` at the command boundary, `&dyn IoInterface` deeper down) instead of `&Console`. The console_writeln\!/write\! macros now go through `IoInterface::verbosity()` via the lock so any implementor works. --- crates/mozart/src/commands/licenses.rs | 49 ++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'crates/mozart/src/commands/licenses.rs') diff --git a/crates/mozart/src/commands/licenses.rs b/crates/mozart/src/commands/licenses.rs index 7a3847f..ece276d 100644 --- a/crates/mozart/src/commands/licenses.rs +++ b/crates/mozart/src/commands/licenses.rs @@ -1,7 +1,7 @@ use crate::composer::Composer; use clap::Args; use indexmap::IndexMap; -use mozart_core::console::Console; +use mozart_core::console::IoInterface; use mozart_core::console::hyperlink; use mozart_core::console_writeln; use mozart_core::package::Package; @@ -68,7 +68,7 @@ impl PackageUrls for LicenseEntry { pub async fn execute( args: &LicensesArgs, cli: &super::Cli, - console: &Console, + io: std::sync::Arc>>, ) -> anyhow::Result<()> { let working_dir = cli.working_dir()?; let format = args.format.as_deref().unwrap_or("text"); @@ -113,15 +113,15 @@ pub async fn execute( &root_version, &root_licenses, &entries, - console, + io, )?, - "summary" => render_summary(&entries, console), + "summary" => render_summary(&entries, io.clone()), _ => render_text( &root_pretty_name, &root_version, &root_licenses, &entries, - console, + io, ), } @@ -271,18 +271,18 @@ fn render_text( root_version: &str, root_licenses: &[String], entries: &[LicenseEntry], - console: &Console, + io: std::sync::Arc>>, ) { let license_display = if root_licenses.is_empty() { "none".to_string() } else { root_licenses.join(", ") }; - console_writeln!(console, "Name: {root_pretty_name}"); - console_writeln!(console, "Version: {root_version}"); - console_writeln!(console, "Licenses: {license_display}"); - console_writeln!(console, "Dependencies:"); - console_writeln!(console, ""); + console_writeln!(io, "Name: {root_pretty_name}"); + console_writeln!(io, "Version: {root_version}"); + console_writeln!(io, "Licenses: {license_display}"); + console_writeln!(io, "Dependencies:"); + console_writeln!(io, ""); if entries.is_empty() { return; @@ -302,7 +302,7 @@ fn render_text( .max("Version".len()); console_writeln!( - console, + io, "{: hyperlink(&url, &padded_name, console.decorated), + Some(url) => hyperlink(&url, &padded_name, io.lock().unwrap().is_decorated()), None => padded_name, }; console_writeln!( - console, + io, "{} {:>>, ) -> anyhow::Result<()> { let root_license_arr: Vec = root_licenses .iter() @@ -371,15 +371,18 @@ fn render_json( let formatter = serde_json::ser::PrettyFormatter::with_indent(b" "); let mut ser = serde_json::Serializer::with_formatter(buf, formatter); output.serialize(&mut ser)?; - console_writeln!(console, "{}", &String::from_utf8(ser.into_inner())?); + console_writeln!(io, "{}", &String::from_utf8(ser.into_inner())?); Ok(()) } -fn render_summary(entries: &[LicenseEntry], console: &Console) { +fn render_summary( + entries: &[LicenseEntry], + io: std::sync::Arc>>, +) { let counts = tally_licenses(entries); if counts.is_empty() { - console_writeln!(console, "No dependencies found."); + console_writeln!(io, "No dependencies found."); return; } @@ -401,19 +404,19 @@ fn render_summary(entries: &[LicenseEntry], console: &Console) { let border_col1 = "-".repeat(license_width + 2); let border_col2 = "-".repeat(count_width + 2); - console_writeln!(console, " {} {}", border_col1, border_col2); + console_writeln!(io, " {} {}", border_col1, border_col2); console_writeln!( - console, + io, " {: