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/status.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'crates/mozart/src/commands/status.rs') diff --git a/crates/mozart/src/commands/status.rs b/crates/mozart/src/commands/status.rs index f0445bf..7cd7546 100644 --- a/crates/mozart/src/commands/status.rs +++ b/crates/mozart/src/commands/status.rs @@ -1,7 +1,7 @@ use crate::composer::Composer; use clap::Args; use mozart_core::composer::{InstallationSource, LocalPackage}; -use mozart_core::console::Console; +use mozart_core::console::IoInterface; use mozart_core::console_writeln; use mozart_core::console_writeln_error; use mozart_core::exit_code; @@ -23,7 +23,7 @@ struct VerRef { pub async fn execute( _args: &StatusArgs, cli: &super::Cli, - console: &Console, + io: std::sync::Arc>>, ) -> anyhow::Result<()> { let composer = Composer::require(cli.working_dir()?)?; @@ -105,45 +105,45 @@ pub async fn execute( } if errors.is_empty() && unpushed_changes.is_empty() && vcs_version_changes.is_empty() { - console_writeln_error!(console, "No local changes"); + console_writeln_error!(io, "No local changes"); return Ok(()); } if !errors.is_empty() { console_writeln_error!( - console, + io, "You have changes in the following dependencies:" ); for (path, changes) in &errors { if cli.is_verbose() { - console_writeln!(console, "{path}:"); - console_writeln!(console, "{}", &indent_block(changes)); + console_writeln!(io, "{path}:"); + console_writeln!(io, "{}", &indent_block(changes)); } else { - console_writeln!(console, "{}", path); + console_writeln!(io, "{}", path); } } } if !unpushed_changes.is_empty() { console_writeln_error!( - console, + io, "You have unpushed changes on the current branch in the following dependencies:" ); for (path, changes) in &unpushed_changes { if cli.is_verbose() { - console_writeln!(console, "{path}:"); - console_writeln!(console, "{}", &indent_block(changes)); + console_writeln!(io, "{path}:"); + console_writeln!(io, "{}", &indent_block(changes)); } else { - console_writeln!(console, "{}", path); + console_writeln!(io, "{}", path); } } } if !vcs_version_changes.is_empty() { console_writeln_error!( - console, + io, "You have version variations in the following dependencies:" ); @@ -159,23 +159,23 @@ pub async fn execute( } else { change.current.version.clone() }; - if console.is_very_verbose() { + if io.lock().unwrap().is_very_verbose() { prev.push_str(&format!(" ({})", change.previous.reference)); curr.push_str(&format!(" ({})", change.current.reference)); } - console_writeln!(console, "{path}:"); + console_writeln!(io, "{path}:"); console_writeln!( - console, + io, " From {prev} to {curr}" ); } else { - console_writeln!(console, "{}", path); + console_writeln!(io, "{}", path); } } } if !cli.is_verbose() { - console_writeln_error!(console, "Use --verbose (-v) to see a list of files"); + console_writeln_error!(io, "Use --verbose (-v) to see a list of files"); } let code = (if !errors.is_empty() { 1 } else { 0 }) -- cgit v1.3.1