diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-23 15:11:36 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-23 15:11:36 +0900 |
| commit | d6e0c6d34449224ac3687daf551a0acfd15cee32 (patch) | |
| tree | d6767718ad566542d4770d4688d9961e0f74ea3d /crates/mozart/src/commands/suggests.rs | |
| parent | 7e45efd8a1f488b1a684f9efe31ff39009fc9e54 (diff) | |
| download | php-mozart-d6e0c6d34449224ac3687daf551a0acfd15cee32.tar.gz php-mozart-d6e0c6d34449224ac3687daf551a0acfd15cee32.tar.zst php-mozart-d6e0c6d34449224ac3687daf551a0acfd15cee32.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src/commands/suggests.rs')
| -rw-r--r-- | crates/mozart/src/commands/suggests.rs | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/crates/mozart/src/commands/suggests.rs b/crates/mozart/src/commands/suggests.rs index 3fb2f00..1dd898f 100644 --- a/crates/mozart/src/commands/suggests.rs +++ b/crates/mozart/src/commands/suggests.rs @@ -1,5 +1,6 @@ use clap::Args; use mozart_core::console; +use mozart_core::console::Verbosity; use mozart_core::console_format; use std::collections::{BTreeMap, HashMap, HashSet}; use std::path::{Path, PathBuf}; @@ -43,7 +44,7 @@ struct Suggestion { pub async fn execute( args: &SuggestsArgs, cli: &super::Cli, - _console: &console::Console, + console: &console::Console, ) -> anyhow::Result<()> { let working_dir = match &cli.working_dir { Some(dir) => PathBuf::from(dir), @@ -134,26 +135,29 @@ pub async fn execute( let shown = filtered.len(); let diff = total_before_direct_filter.saturating_sub(shown); if diff > 0 { - println!( - "{} by transitive dependencies can be shown with {}", - console_format!("<info>{diff} additional suggestions</info>"), - console_format!("<info>--all</info>"), + console.write_stdout( + &format!( + "{} by transitive dependencies can be shown with {}", + console_format!("<info>{diff} additional suggestions</info>"), + console_format!("<info>--all</info>"), + ), + Verbosity::Normal, ); } } // 6. Render output if args.list { - render_list(&filtered); + render_list(&filtered, console); } else if args.by_suggestion && !args.by_package { - render_by_suggestion(&filtered); + render_by_suggestion(&filtered, console); } else if args.by_package && args.by_suggestion { - render_by_package(&filtered); - println!("{}", "-".repeat(78)); - render_by_suggestion(&filtered); + render_by_package(&filtered, console); + console.write_stdout(&"-".repeat(78), Verbosity::Normal); + render_by_suggestion(&filtered, console); } else { // Default: by-package - render_by_package(&filtered); + render_by_package(&filtered, console); } Ok(()) @@ -431,64 +435,70 @@ fn deduplicate_suggestions(suggestions: Vec<Suggestion>) -> Vec<Suggestion> { // ─── Rendering ─────────────────────────────────────────────────────────────── -fn render_list(suggestions: &[&Suggestion]) { +fn render_list(suggestions: &[&Suggestion], console: &console::Console) { let mut targets: Vec<&str> = suggestions.iter().map(|s| s.target.as_str()).collect(); targets.sort_unstable(); targets.dedup(); for t in targets { - println!("{}", console_format!("<info>{}</info>", t)); + console.write_stdout(&console_format!("<info>{}</info>", t), Verbosity::Normal); } } -fn render_by_package(suggestions: &[&Suggestion]) { +fn render_by_package(suggestions: &[&Suggestion], console: &console::Console) { // Group by source, preserving insertion order via BTreeMap (sorted) let mut grouped: BTreeMap<&str, Vec<&Suggestion>> = BTreeMap::new(); for s in suggestions { grouped.entry(s.source.as_str()).or_default().push(s); } for (source, items) in &grouped { - println!( - "{}", - console_format!("<comment>{}</comment> suggests:", source) + console.write_stdout( + &console_format!("<comment>{}</comment> suggests:", source), + Verbosity::Normal, ); for s in items { let reason = sanitize_reason(&s.reason); if reason.is_empty() { - println!("{}", console_format!(" - <info>{}</info>", &s.target)); + console.write_stdout( + &console_format!(" - <info>{}</info>", &s.target), + Verbosity::Normal, + ); } else { - println!( - "{}", - console_format!(" - <info>{}</info>: {}", &s.target, reason) + console.write_stdout( + &console_format!(" - <info>{}</info>: {}", &s.target, reason), + Verbosity::Normal, ); } } - println!(); + console.write_stdout("", Verbosity::Normal); } } -fn render_by_suggestion(suggestions: &[&Suggestion]) { +fn render_by_suggestion(suggestions: &[&Suggestion], console: &console::Console) { // Group by target let mut grouped: BTreeMap<&str, Vec<&Suggestion>> = BTreeMap::new(); for s in suggestions { grouped.entry(s.target.as_str()).or_default().push(s); } for (target, items) in &grouped { - println!( - "{}", - console_format!("<info>{}</info> is suggested by:", target) + console.write_stdout( + &console_format!("<info>{}</info> is suggested by:", target), + Verbosity::Normal, ); for s in items { let reason = sanitize_reason(&s.reason); if reason.is_empty() { - println!("{}", console_format!(" - <comment>{}</comment>", &s.source)); + console.write_stdout( + &console_format!(" - <comment>{}</comment>", &s.source), + Verbosity::Normal, + ); } else { - println!( - "{}", - console_format!(" - <comment>{}</comment>: {}", &s.source, reason) + console.write_stdout( + &console_format!(" - <comment>{}</comment>: {}", &s.source, reason), + Verbosity::Normal, ); } } - println!(); + console.write_stdout("", Verbosity::Normal); } } |
