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/remove.rs | 80 +++++++++++------------------------- 1 file changed, 25 insertions(+), 55 deletions(-) (limited to 'crates/mozart/src/commands/remove.rs') diff --git a/crates/mozart/src/commands/remove.rs b/crates/mozart/src/commands/remove.rs index ee02ad8..2b1f1ec 100644 --- a/crates/mozart/src/commands/remove.rs +++ b/crates/mozart/src/commands/remove.rs @@ -1,5 +1,5 @@ use clap::Args; -use mozart_core::console; +use mozart_core::console_format; use mozart_core::package; use mozart_core::validation; use mozart_registry::lockfile; @@ -108,20 +108,10 @@ pub async fn execute( // Step 2: Handle deprecated flags if args.update_with_dependencies { - console.info(&format!( - "{}", - console::warning( - "The -w / --update-with-dependencies flag is deprecated. Use --with-all-dependencies instead." - ) - )); + console.info(&console_format!("The -w / --update-with-dependencies flag is deprecated. Use --with-all-dependencies instead.")); } if args.update_with_all_dependencies { - console.info(&format!( - "{}", - 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.")); } // Step 3: Resolve working directory and read composer.json @@ -160,41 +150,31 @@ pub async fn execute( if raw.require_dev.contains_key(&name) { println!( "{}", - console::info(&format!("Removing {name} from require-dev")) + console_format!("Removing {name} from require-dev") ); raw.require_dev.remove(&name); any_removed = true; } else { - console.info(&format!( - "{}", - console::warning(&format!( - "{name} is not required in require-dev and has not been removed." - )) - )); + console.info(&console_format!("{name} is not required in require-dev and has not been removed.")); } } else { // Auto-detect: look in require first, then require-dev if raw.require.contains_key(&name) { println!( "{}", - console::info(&format!("Removing {name} from require")) + console_format!("Removing {name} from require") ); raw.require.remove(&name); any_removed = true; } else if raw.require_dev.contains_key(&name) { println!( "{}", - console::info(&format!("Removing {name} from require-dev")) + console_format!("Removing {name} from require-dev") ); raw.require_dev.remove(&name); any_removed = true; } else { - console.info(&format!( - "{}", - console::warning(&format!( - "{name} is not required in your composer.json and has not been removed." - )) - )); + console.info(&console_format!("{name} is not required in your composer.json and has not been removed.")); } } } @@ -203,7 +183,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 if any_removed { package::write_to_file(&raw, &composer_path)?; @@ -213,7 +193,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(()); } @@ -291,13 +273,7 @@ pub async fn execute( match lockfile::LockFile::read_from_file(&lock_path) { Ok(l) => Some(l), Err(e) => { - console.info(&format!( - "{}", - 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 } } @@ -338,12 +314,7 @@ pub async fn execute( // For --minimal-changes, additionally pin packages beyond the allow list if args.minimal_changes { - console.info(&format!( - "{}", - console::info( - "Minimal changes mode: preserving locked versions for non-removed packages." - ) - )); + console.info(&console_format!("Minimal changes mode: preserving locked versions for non-removed packages.")); } resolved = super::update::apply_partial_update(resolved, lock, &allow_list); @@ -383,17 +354,14 @@ pub async fn execute( .filter(|c| matches!(c.kind, super::update::ChangeKind::Remove { .. })) .collect(); - console.info(&format!( - "{}", - console::info(&format!( - "Package operations: {} install{}, {} update{}, {} removal{}", - installs.len(), - if installs.len() == 1 { "" } else { "s" }, - updates.len(), - if updates.len() == 1 { "" } else { "s" }, - removals.len(), - if removals.len() == 1 { "" } else { "s" }, - )) + console.info(&console_format!( + "Package operations: {} install{}, {} update{}, {} removal{}", + installs.len(), + if installs.len() == 1 { "" } else { "s" }, + updates.len(), + if updates.len() == 1 { "" } else { "s" }, + removals.len(), + if removals.len() == 1 { "" } else { "s" }, )); // Print individual change lines @@ -561,7 +529,9 @@ async fn remove_unused( console.info(&format!("Found {} unused package(s).", unused.len())); if args.dry_run { - console.info(&console::comment("Dry run: lock file not modified.")); + console.info(&console_format!( + "Dry run: lock file not modified." + )); return Ok(()); } -- cgit v1.3.1