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/config.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'crates/mozart/src/commands/config.rs') diff --git a/crates/mozart/src/commands/config.rs b/crates/mozart/src/commands/config.rs index 5012163..7f4fd06 100644 --- a/crates/mozart/src/commands/config.rs +++ b/crates/mozart/src/commands/config.rs @@ -5,6 +5,7 @@ use anyhow::anyhow; use clap::Args; use mozart_core::composer::composer_home; use mozart_core::config::resolve_references; +use mozart_core::console::IoInterface; use mozart_core::console_writeln; use mozart_core::factory::create_config; use std::collections::BTreeMap; @@ -407,7 +408,7 @@ fn load_config_section( pub async fn execute( args: &ConfigArgs, cli: &super::Cli, - console: &mozart_core::console::Console, + io: std::sync::Arc>>, ) -> anyhow::Result<()> { // 1. Handle --editor mode if args.editor { @@ -429,7 +430,7 @@ pub async fn execute( } // 4b. Read mode - execute_read(args, cli, &config_file_path, console) + execute_read(args, cli, &config_file_path, io.clone()) } fn execute_editor(args: &ConfigArgs, cli: &super::Cli) -> anyhow::Result<()> { @@ -972,7 +973,7 @@ fn execute_read( args: &ConfigArgs, cli: &super::Cli, config_file_path: &Path, - console: &mozart_core::console::Console, + io: std::sync::Arc>>, ) -> anyhow::Result<()> { // Build the effective config for config-section keys. // Global baseline (defaults + platform dirs + $COMPOSER_HOME/config.json), @@ -997,7 +998,7 @@ fn execute_read( if args.list { for (key, value) in config.entries() { console_writeln!( - console, + io, mozart_core::console::Verbosity::Quiet, "[{}] {}", key, @@ -1020,7 +1021,7 @@ fn execute_read( for entry in repos { if entry.get("name").and_then(|n| n.as_str()) == Some(repo_name) { console_writeln!( - console, + io, mozart_core::console::Verbosity::Quiet, "{}", &render_value(entry), @@ -1037,7 +1038,7 @@ fn execute_read( let raw = read_json_file(config_file_path, args.global)?; if let Some(v) = get_nested(&raw, key) { console_writeln!( - console, + io, mozart_core::console::Verbosity::Quiet, "{}", &render_value(v), @@ -1052,7 +1053,7 @@ fn execute_read( let raw = read_json_file(config_file_path, args.global)?; if let Some(v) = raw.get(key.as_str()) { console_writeln!( - console, + io, mozart_core::console::Verbosity::Quiet, "{}", &render_value(v), @@ -1066,7 +1067,7 @@ fn execute_read( match config.get(key) { Some(value) => { console_writeln!( - console, + io, mozart_core::console::Verbosity::Quiet, "{}", &render_value(&value), -- cgit v1.3.1