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/clear_cache.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'crates/mozart/src/commands/clear_cache.rs') diff --git a/crates/mozart/src/commands/clear_cache.rs b/crates/mozart/src/commands/clear_cache.rs index 6a601da..dbca5c8 100644 --- a/crates/mozart/src/commands/clear_cache.rs +++ b/crates/mozart/src/commands/clear_cache.rs @@ -1,10 +1,10 @@ -use std::{borrow::Cow, path::Path}; - use crate::composer::Composer; use clap::Args; +use mozart_core::console::IoInterface; use mozart_core::console_writeln_error; use mozart_core::factory::create_config; use mozart_core::repository::cache::Cache; +use std::{borrow::Cow, path::Path}; #[derive(Args)] pub struct ClearCacheArgs { @@ -16,7 +16,7 @@ pub struct ClearCacheArgs { pub async fn execute( args: &ClearCacheArgs, cli: &super::Cli, - console: &mozart_core::console::Console, + io: std::sync::Arc>>, ) -> anyhow::Result<()> { let composer = Composer::try_load(cli.working_dir()?)?; let config = if let Some(composer) = &composer { @@ -42,7 +42,7 @@ pub async fn execute( if !path.exists() { console_writeln_error!( - console, + io, "Cache directory does not exist ({key}): {}", path.display(), ); @@ -52,7 +52,7 @@ pub async fn execute( let cache = Cache::new(path.to_owned(), config.cache_read_only); if !cache.is_enabled() { console_writeln_error!( - console, + io, "Cache is not enabled ({key}): {}", path.display(), ); @@ -61,7 +61,7 @@ pub async fn execute( if args.gc { console_writeln_error!( - console, + io, "Garbage-collecting cache ({key}): {}", path.display(), ); @@ -73,7 +73,7 @@ pub async fn execute( }; } else { console_writeln_error!( - console, + io, "Clearing cache ({key}): {}", path.display(), ); @@ -82,9 +82,9 @@ pub async fn execute( } if args.gc { - console_writeln_error!(console, "All caches garbage-collected."); + console_writeln_error!(io, "All caches garbage-collected."); } else { - console_writeln_error!(console, "All caches cleared."); + console_writeln_error!(io, "All caches cleared."); } Ok(()) -- cgit v1.3.1