From 6f3802fd9f39c4e5847d130b4417b5cdfb66972d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 22 Feb 2026 22:53:09 +0900 Subject: refactor(console): add console_format! proc macro and migrate all commands Introduce a Symfony Console-style tag macro that replaces verbose patterns like `console::info(&format!("text {name}"))` with `console_format!("text {name}")`. Supports all 6 tag types (info, comment, error, question, highlight, warning) with format argument distribution across multiple tagged segments. Co-Authored-By: Claude Opus 4.6 --- crates/mozart/src/commands/require.rs | 85 +++++++++++++++++------------------ 1 file changed, 41 insertions(+), 44 deletions(-) (limited to 'crates/mozart/src/commands/require.rs') diff --git a/crates/mozart/src/commands/require.rs b/crates/mozart/src/commands/require.rs index 28b4e5e..2082f43 100644 --- a/crates/mozart/src/commands/require.rs +++ b/crates/mozart/src/commands/require.rs @@ -1,5 +1,5 @@ use clap::Args; -use mozart_core::console; +use mozart_core::console_format; use mozart_core::package::{self, Stability}; use mozart_core::validation; use mozart_registry::lockfile; @@ -170,7 +170,7 @@ async fn interactive_search_packages( Err(e) => { eprintln!( "{}", - console::warning(&format!("Search failed: {e}. Try again.")) + console_format!("Search failed: {e}. Try again.") ); continue; } @@ -186,9 +186,9 @@ async fn interactive_search_packages( if filtered.is_empty() { eprintln!( "{}", - console::warning(&format!( - "No new packages found for \"{query}\" (total: {total})." - )) + console_format!( + "No new packages found for \"{query}\" (total: {total})." + ) ); continue; } @@ -243,7 +243,10 @@ async fn interactive_search_packages( } else if num <= filtered.len() { filtered[num - 1].name.to_lowercase() } else { - eprintln!("{}", console::warning(&format!("Invalid selection: {num}"))); + eprintln!( + "{}", + console_format!("Invalid selection: {num}") + ); continue; } } else { @@ -256,7 +259,7 @@ async fn interactive_search_packages( match validation::parse_require_string(&package_name) { Ok((n, v)) => (n.to_lowercase(), v), Err(e) => { - eprintln!("{}", console::warning(&format!("Invalid: {e}"))); + eprintln!("{}", console_format!("Invalid: {e}")); continue; } } @@ -264,16 +267,16 @@ async fn interactive_search_packages( if !validation::validate_package_name(&package_name) { eprintln!( "{}", - console::warning(&format!("Invalid package name: \"{package_name}\"")) + console_format!("Invalid package name: \"{package_name}\"") ); continue; } eprintln!( "{}", - console::info(&format!( - "Using version constraint for {package_name} from Packagist..." - )) + console_format!( + "Using version constraint for {package_name} from Packagist..." + ) ); match packagist::fetch_package_versions(&package_name, None).await { @@ -292,17 +295,18 @@ async fn interactive_search_packages( }; eprintln!( "{}", - console::info(&format!("Using version {c} for {package_name}")) + console_format!( + "Using version {c} for {package_name}" + ) ); (package_name, c) } None => { eprintln!( "{}", - console::warning(&format!( - "Could not find a version of \"{package_name}\" matching \ - your minimum-stability. Try specifying it explicitly." - )) + console_format!( + "Could not find a version of \"{package_name}\" matching your minimum-stability. Try specifying it explicitly." + ) ); continue; } @@ -311,9 +315,9 @@ async fn interactive_search_packages( Err(e) => { eprintln!( "{}", - console::warning(&format!( - "Could not fetch versions for \"{package_name}\": {e}" - )) + console_format!( + "Could not fetch versions for \"{package_name}\": {e}" + ) ); continue; } @@ -403,19 +407,15 @@ pub async fn execute( // Handle deprecated flags if args.no_suggest { - console.info(&console::warning( - "The --no-suggest option is deprecated and has no effect.", + console.info(&console_format!( + "The --no-suggest option is deprecated and has no effect." )); } if args.update_with_dependencies { - console.info(&console::warning( - "The -w / --update-with-dependencies flag is deprecated. Use --with-dependencies instead." - )); + console.info(&console_format!("The -w / --update-with-dependencies flag is deprecated. Use --with-dependencies instead.")); } if args.update_with_all_dependencies { - console.info(&console::warning( - "The -W / --update-with-all-dependencies flag is deprecated. Use --with-all-dependencies instead." - )); + console.info(&console_format!("The -W / --update-with-all-dependencies flag is deprecated. Use --with-all-dependencies instead.")); } // Resolve working directory @@ -461,9 +461,9 @@ pub async fn execute( println!( "{}", - console::info(&format!( - "Using version constraint for {name} from Packagist..." - )) + console_format!( + "Using version constraint for {name} from Packagist..." + ) ); let versions = packagist::fetch_package_versions(&name, None).await?; @@ -488,7 +488,7 @@ pub async fn execute( println!( "{}", - console::info(&format!("Using version {constraint} for {name}")) + console_format!("Using version {constraint} for {name}") ); (name, constraint) @@ -510,14 +510,14 @@ pub async fn execute( if let Some(existing) = target.get(name) { println!( "{}", - console::comment(&format!( - "Updating {name} from {existing} to {constraint} in {section_name}" - )) + console_format!( + "Updating {name} from {existing} to {constraint} in {section_name}" + ) ); } else { println!( "{}", - console::info(&format!("Adding {name} ({constraint}) to {section_name}")) + console_format!("Adding {name} ({constraint}) to {section_name}") ); } @@ -536,7 +536,7 @@ pub async fn execute( if args.dry_run { println!( "{}", - console::comment("Dry run: composer.json not modified.") + console_format!("Dry run: composer.json not modified.") ); } else { package::write_to_file(&raw, &composer_path)?; @@ -546,7 +546,9 @@ pub async fn execute( if args.no_update { println!( "{}", - console::comment("Not updating dependencies, only modifying composer.json.") + console_format!( + "Not updating dependencies, only modifying composer.json." + ) ); return Ok(()); } @@ -622,10 +624,7 @@ pub async fn execute( match lockfile::LockFile::read_from_file(&lock_path) { Ok(l) => Some(l), Err(e) => { - console.info(&console::warning(&format!( - "Could not read existing composer.lock: {}. Treating as a fresh install.", - e - ))); + console.info(&console_format!("Could not read existing composer.lock: {}. Treating as a fresh install.", e)); None } } @@ -760,9 +759,7 @@ pub async fn execute( .map(|s| s.eq_ignore_ascii_case("source")) .unwrap_or(false); if prefer_source { - console.info(&mozart_core::console::warning( - "Warning: Source installs are not yet supported. Falling back to dist.", - )); + console.info(&console_format!("Warning: Source installs are not yet supported. Falling back to dist.")); } super::install::install_from_lock( -- cgit v1.3.1