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/create_project.rs | 78 +++++++++++----------------- 1 file changed, 29 insertions(+), 49 deletions(-) (limited to 'crates/mozart/src/commands/create_project.rs') diff --git a/crates/mozart/src/commands/create_project.rs b/crates/mozart/src/commands/create_project.rs index b4e3c3c..2156477 100644 --- a/crates/mozart/src/commands/create_project.rs +++ b/crates/mozart/src/commands/create_project.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::downloader; @@ -142,7 +142,7 @@ fn remove_vcs_metadata(target_dir: &Path) -> anyhow::Result<()> { std::fs::remove_dir_all(&path)?; eprintln!( "{}", - console::comment(&format!("Removed VCS metadata directory: {vcs_dir}")) + console_format!("Removed VCS metadata directory: {vcs_dir}") ); } } @@ -177,37 +177,27 @@ pub async fn execute( ) -> anyhow::Result<()> { // --- Handle deprecated / no-op flags --- if args.prefer_source { - console.info(&format!( - "{}", - console::warning("Source installs not yet supported, falling back to dist.") + console.info(&console_format!( + "Source installs not yet supported, falling back to dist." )); } if args.dev { - console.info(&format!( - "{}", - console::warning( - "The --dev flag is deprecated. Dev packages are installed by default." - ) + console.info(&console_format!( + "The --dev flag is deprecated. Dev packages are installed by default." )); } if args.no_custom_installers { - console.info(&format!( - "{}", - console::warning( - "The --no-custom-installers flag is deprecated. Use --no-plugins instead." - ) + console.info(&console_format!( + "The --no-custom-installers flag is deprecated. Use --no-plugins instead." )); } if !args.repository.is_empty() || args.repository_url.is_some() || args.add_repository { - console.info(&format!( - "{}", - console::warning( - "Custom repository options (--repository, --repository-url, --add-repository) \ - are not yet supported and will be ignored." - ) + console.info(&console_format!( + "Custom repository options (--repository, --repository-url, --add-repository) \ + are not yet supported and will be ignored." )); } @@ -272,9 +262,8 @@ pub async fn execute( }; // --- Step 4: Fetch package versions and find best match --- - console.info(&format!( - "{}", - console::info(&format!("Creating project from package {package_name}")) + console.info(&console_format!( + "Creating project from package {package_name}" )); console.info("Loading composer repositories with package information"); @@ -310,9 +299,8 @@ pub async fn execute( let concrete_version = best.version.clone(); - console.info(&format!( - "{}", - console::info(&format!("Installing {package_name} ({concrete_version})")) + console.info(&console_format!( + "Installing {package_name} ({concrete_version})" )); // --- Step 5: Create target directory and download+extract --- @@ -342,9 +330,9 @@ pub async fn execute( other => anyhow::bail!("Unsupported dist type: {other}"), } - console.info(&format!( - "{}", - console::info(&format!("Created project in {}", target_dir.display())) + console.info(&console_format!( + "Created project in {}", + target_dir.display() )); // --- Step 7: VCS removal --- @@ -359,12 +347,9 @@ pub async fn execute( let composer_path = target_dir.join("composer.json"); if !composer_path.exists() { - console.info(&format!( - "{}", - console::warning(&format!( - "No composer.json found in {}. Skipping dependency installation.", - target_dir.display() - )) + console.info(&console_format!( + "No composer.json found in {}. Skipping dependency installation.", + target_dir.display() )); return Ok(()); } @@ -377,9 +362,8 @@ pub async fn execute( // --- Step 6 continued: dependency resolution and install --- if args.no_install { - console.info(&format!( - "{}", - console::comment("Skipping dependency installation (--no-install).") + console.info(&console_format!( + "Skipping dependency installation (--no-install)." )); return Ok(()); } @@ -450,13 +434,10 @@ pub async fn execute( .filter(|c| matches!(c.kind, super::update::ChangeKind::Install { .. })) .collect(); - console.info(&format!( - "{}", - console::info(&format!( - "Package operations: {} install{}, 0 updates, 0 removals", - installs.len(), - if installs.len() == 1 { "" } else { "s" }, - )) + console.info(&console_format!( + "Package operations: {} install{}, 0 updates, 0 removals", + installs.len(), + if installs.len() == 1 { "" } else { "s" } )); for change in &changes { @@ -479,9 +460,8 @@ pub async fn execute( .map(|s| s.eq_ignore_ascii_case("source")) .unwrap_or(false); if prefer_source { - console.info(&format!( - "{}", - console::warning("Source installs are not yet supported. Falling back to dist.") + console.info(&console_format!( + "Source installs are not yet supported. Falling back to dist." )); } -- cgit v1.3.1