From d6e0c6d34449224ac3687daf551a0acfd15cee32 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 23 Feb 2026 15:11:36 +0900 Subject: refactor(cli): route command output through Console abstraction Replace direct println\!/eprintln\! calls with console.write(), console.info(), and console.write_stdout() across all command handlers to respect verbosity settings. Co-Authored-By: Claude Opus 4.6 --- crates/mozart/src/commands/init.rs | 88 ++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 52 deletions(-) (limited to 'crates/mozart/src/commands/init.rs') diff --git a/crates/mozart/src/commands/init.rs b/crates/mozart/src/commands/init.rs index 15ec531..0b5ab9e 100644 --- a/crates/mozart/src/commands/init.rs +++ b/crates/mozart/src/commands/init.rs @@ -348,7 +348,7 @@ async fn build_interactive( let mut require = parse_requirements(&args.require)?; let interactive_require = - interactive_search_packages("require", &require, preferred_stability).await?; + interactive_search_packages("require", &require, preferred_stability, console).await?; for (name, constraint) in interactive_require { require.insert(name, constraint); } @@ -367,7 +367,8 @@ async fn build_interactive( .map(|(k, v)| (k.clone(), v.clone())) .collect(); let interactive_dev = - interactive_search_packages("require-dev", &all_required, preferred_stability).await?; + interactive_search_packages("require-dev", &all_required, preferred_stability, console) + .await?; for (name, constraint) in interactive_dev { require_dev.insert(name, constraint); } @@ -417,6 +418,7 @@ async fn interactive_search_packages( label: &str, already_required: &BTreeMap, preferred_stability: Stability, + console: &console::Console, ) -> anyhow::Result> { let stdin = std::io::stdin(); let mut selected: BTreeMap = BTreeMap::new(); @@ -442,10 +444,9 @@ async fn interactive_search_packages( let (results, total) = match packagist::search_packages(&query, None).await { Ok(r) => r, Err(e) => { - eprintln!( - "{}", - console_format!("Search failed: {e}. Try again.") - ); + console.info(&console_format!( + "Search failed: {e}. Try again." + )); continue; } }; @@ -461,21 +462,18 @@ async fn interactive_search_packages( .collect(); if filtered.is_empty() { - eprintln!( - "{}", - console_format!( - "No new packages found for \"{query}\" (total: {total})." - ) - ); + console.info(&console_format!( + "No new packages found for \"{query}\" (total: {total})." + )); continue; } - eprintln!( + console.info(&format!( "\nFound {} package{} for \"{}\":", filtered.len(), if filtered.len() == 1 { "" } else { "s" }, query, - ); + )); let name_width = filtered.iter().map(|r| r.name.len()).max().unwrap_or(0); for (idx, result) in filtered.iter().enumerate() { @@ -484,15 +482,15 @@ async fn interactive_search_packages( } else { format!(" — {}", result.description) }; - eprintln!( + console.info(&format!( " [{idx}] {:Invalid selection: {num}") - ); + console.info(&console_format!( + "Invalid selection: {num}" + )); continue; } } else { @@ -533,25 +530,21 @@ async fn interactive_search_packages( match validation::parse_require_string(&package_name) { Ok((n, v)) => (n.to_lowercase(), v), Err(e) => { - eprintln!("{}", console_format!("Invalid: {e}")); + console.info(&console_format!("Invalid: {e}")); continue; } } } else { if !validation::validate_package_name(&package_name) { - eprintln!( - "{}", - console_format!("Invalid package name: \"{package_name}\"") - ); + console.info(&console_format!( + "Invalid package name: \"{package_name}\"" + )); continue; } - eprintln!( - "{}", - console_format!( - "Using version constraint for {package_name} from Packagist..." - ) - ); + console.info(&console_format!( + "Using version constraint for {package_name} from Packagist..." + )); match packagist::fetch_package_versions(&package_name, None).await { Ok(versions) => { @@ -563,33 +556,24 @@ async fn interactive_search_packages( &best.version_normalized, stability, ); - eprintln!( - "{}", - console_format!( - "Using version {c} for {package_name}" - ) - ); + console.info(&console_format!( + "Using version {c} for {package_name}" + )); (package_name, c) } None => { - eprintln!( - "{}", - console_format!( - "Could not find a version of \"{package_name}\" matching \ - your minimum-stability. Try specifying it explicitly." - ) - ); + console.info(&console_format!( + "Could not find a version of \"{package_name}\" matching \ + your minimum-stability. Try specifying it explicitly." + )); continue; } } } Err(e) => { - eprintln!( - "{}", - console_format!( - "Could not fetch versions for \"{package_name}\": {e}" - ) - ); + console.info(&console_format!( + "Could not fetch versions for \"{package_name}\": {e}" + )); continue; } } -- cgit v1.3.1