aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart/src/commands/config.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-10 15:29:19 +0900
committernsfisis <nsfisis@gmail.com>2026-05-10 15:29:19 +0900
commit46845eff8d1398f35099a0ef914f77bcaf473287 (patch)
tree12c4850f1d2f438d0ba6c363fdc0e5036cd4601d /crates/mozart/src/commands/config.rs
parent212506c364b2342dd9e5fa789e8cff38835dfe52 (diff)
downloadphp-mozart-46845eff8d1398f35099a0ef914f77bcaf473287.tar.gz
php-mozart-46845eff8d1398f35099a0ef914f77bcaf473287.tar.zst
php-mozart-46845eff8d1398f35099a0ef914f77bcaf473287.zip
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<Mutex<Box<dyn IoInterface>>>` 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.
Diffstat (limited to 'crates/mozart/src/commands/config.rs')
-rw-r--r--crates/mozart/src/commands/config.rs17
1 files changed, 9 insertions, 8 deletions
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<std::sync::Mutex<Box<dyn IoInterface>>>,
) -> 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<std::sync::Mutex<Box<dyn IoInterface>>>,
) -> 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),