From f18c18cd15f180b5067069ec6f10530515715f3d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 9 May 2026 12:15:21 +0900 Subject: refactor(console): accept format args directly in console_writeln! macros Eliminate the nested &console_format!(...) boilerplate at every call site by teaching console_writeln!, console_write!, console_writeln_error!, and console_write_error! to accept a format literal + variadic args directly, matching the println!/eprintln! ergonomics. Propagate the format string span into generated code so rustc errors point to the right location. Co-Authored-By: Claude Sonnet 4.6 --- Cargo.lock | 2 + crates/mozart-console-macros/src/codegen.rs | 21 +- crates/mozart-console-macros/src/lib.rs | 6 +- crates/mozart-core/src/console.rs | 56 +++- crates/mozart-registry/Cargo.toml | 1 + crates/mozart-registry/src/advisory.rs | 127 ++++---- crates/mozart/Cargo.toml | 1 + crates/mozart/src/commands/about.rs | 7 +- crates/mozart/src/commands/archive.rs | 2 +- crates/mozart/src/commands/browse.rs | 17 +- crates/mozart/src/commands/bump.rs | 58 +--- crates/mozart/src/commands/check_platform_reqs.rs | 33 +- crates/mozart/src/commands/clear_cache.rs | 33 +- crates/mozart/src/commands/config.rs | 16 +- crates/mozart/src/commands/dependency.rs | 50 ++- crates/mozart/src/commands/diagnose.rs | 36 +-- crates/mozart/src/commands/dump_autoload.rs | 37 +-- crates/mozart/src/commands/exec.rs | 10 +- crates/mozart/src/commands/fund.rs | 8 +- crates/mozart/src/commands/licenses.rs | 72 ++--- crates/mozart/src/commands/remove.rs | 19 +- crates/mozart/src/commands/repository.rs | 8 +- crates/mozart/src/commands/require.rs | 19 +- crates/mozart/src/commands/run_script.rs | 7 +- crates/mozart/src/commands/search.rs | 4 +- crates/mozart/src/commands/self_update.rs | 21 +- crates/mozart/src/commands/show.rs | 363 +++++++++------------- crates/mozart/src/commands/status.rs | 33 +- crates/mozart/src/commands/validate.rs | 4 +- 29 files changed, 451 insertions(+), 620 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cbd1046..59e6c03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1090,6 +1090,7 @@ dependencies = [ "indexmap", "mozart-archiver", "mozart-autoload", + "mozart-console-macros", "mozart-core", "mozart-registry", "mozart-semver", @@ -1200,6 +1201,7 @@ dependencies = [ "flate2", "indexmap", "md5", + "mozart-console-macros", "mozart-core", "mozart-metadata-minifier", "mozart-php-serialize", diff --git a/crates/mozart-console-macros/src/codegen.rs b/crates/mozart-console-macros/src/codegen.rs index 002f808..8601e07 100644 --- a/crates/mozart-console-macros/src/codegen.rs +++ b/crates/mozart-console-macros/src/codegen.rs @@ -77,10 +77,11 @@ fn count_positional_placeholders(s: &str) -> usize { pub fn generate( segments: &[Segment], extra_args: &Punctuated, + span: proc_macro2::Span, ) -> TokenStream { // Single segment: pass all extra args if segments.len() == 1 { - return generate_single(&segments[0], extra_args); + return generate_single(&segments[0], extra_args, span); } // Multiple segments: distribute positional args across segments @@ -101,7 +102,7 @@ pub fn generate( pos = end; let ident = quote::format_ident!("__seg{}", i); - let expr = generate_single(segment, &slice); + let expr = generate_single(segment, &slice, span); seg_bindings.push(quote! { let #ident = #expr; }); seg_idents.push(ident); } @@ -124,11 +125,21 @@ fn segment_content(segment: &Segment) -> &str { } } -fn generate_single(segment: &Segment, args: &Punctuated) -> TokenStream { +fn spanned_lit(s: &str, span: proc_macro2::Span) -> proc_macro2::Literal { + let mut lit = proc_macro2::Literal::string(s); + lit.set_span(span); + lit +} + +fn generate_single( + segment: &Segment, + args: &Punctuated, + span: proc_macro2::Span, +) -> TokenStream { match segment { Segment::Plain(text) => { if has_placeholders(text) { - let lit = proc_macro2::Literal::string(text); + let lit = spanned_lit(text, span); quote! { ::std::format!(#lit, #args) } } else { quote! { ::std::string::String::from(#text) } @@ -137,7 +148,7 @@ fn generate_single(segment: &Segment, args: &Punctuated) - Segment::Tagged { tag, content } => { let func = quote::format_ident!("__format_{}_message", tag); if has_placeholders(content) { - let lit = proc_macro2::Literal::string(content); + let lit = spanned_lit(content, span); quote! { ::std::string::ToString::to_string( &::mozart_core::console::#func(&::std::format!(#lit, #args)) diff --git a/crates/mozart-console-macros/src/lib.rs b/crates/mozart-console-macros/src/lib.rs index 3af6f82..0678ecd 100644 --- a/crates/mozart-console-macros/src/lib.rs +++ b/crates/mozart-console-macros/src/lib.rs @@ -39,7 +39,11 @@ fn console_format_impl( let args: ConsoleFormatArgs = syn::parse2(input)?; let segments = parser::parse_format_string(&args.format_str) .map_err(|msg| syn::Error::new(args.format_str_span, msg))?; - Ok(codegen::generate(&segments, &args.extra_args)) + Ok(codegen::generate( + &segments, + &args.extra_args, + args.format_str_span, + )) } struct ConsoleFormatArgs { diff --git a/crates/mozart-core/src/console.rs b/crates/mozart-core/src/console.rs index e0c224f..e036b11 100644 --- a/crates/mozart-core/src/console.rs +++ b/crates/mozart-core/src/console.rs @@ -294,12 +294,18 @@ impl Console { /// ref: \Composer\IO\IOInterface::write() #[macro_export] macro_rules! console_writeln { - ($console:expr, $msg:expr $(,)?) => { - $crate::console_writeln!($console, $msg, $crate::console::Verbosity::Normal) + ($console:expr, $fmt:literal) => { + $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt,) }; - ($console:expr, $msg:expr, $verbosity:expr $(,)?) => { + ($console:expr, $fmt:literal, $($arg:tt)*) => { + $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt, $($arg)*) + }; + ($console:expr, $verbosity:expr, $fmt:literal) => { + $crate::console_writeln!($console, $verbosity, $fmt, $($arg)*,) + }; + ($console:expr, $verbosity:expr, $fmt:literal, $($arg:tt)*) => { if ($console).verbosity >= $verbosity { - println!("{}", $msg); + ::std::println!("{}", &::mozart_console_macros::console_format!($fmt, $($arg)*)); } }; } @@ -309,12 +315,18 @@ macro_rules! console_writeln { /// ref: \Composer\IO\IOInterface::write() #[macro_export] macro_rules! console_write { - ($console:expr, $msg:expr $(,)?) => { - $crate::console_write!($console, $msg, $crate::console::Verbosity::Normal) + ($console:expr, $fmt:literal) => { + $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt,) + }; + ($console:expr, $fmt:literal, $($arg:tt)*) => { + $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt, $($arg)*) + }; + ($console:expr, $verbosity:expr, $fmt:literal) => { + $crate::console_writeln!($console, $verbosity, $fmt, $($arg)*,) }; - ($console:expr, $msg:expr, $verbosity:expr $(,)?) => { + ($console:expr, $verbosity:expr, $fmt:literal, $($arg:tt)*) => { if ($console).verbosity >= $verbosity { - print!("{}", $msg); + ::std::print!("{}", &::mozart_console_macros::console_format!($fmt, $($arg)*)); } }; } @@ -324,12 +336,18 @@ macro_rules! console_write { /// ref: \Composer\IO\IOInterface::writeError() #[macro_export] macro_rules! console_writeln_error { - ($console:expr, $msg:expr $(,)?) => { - $crate::console_writeln_error!($console, $msg, $crate::console::Verbosity::Normal) + ($console:expr, $fmt:literal) => { + $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt,) }; - ($console:expr, $msg:expr, $verbosity:expr $(,)?) => { + ($console:expr, $fmt:literal, $($arg:tt)*) => { + $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt, $($arg)*) + }; + ($console:expr, $verbosity:expr, $fmt:literal) => { + $crate::console_writeln!($console, $verbosity, $fmt, $($arg)*,) + }; + ($console:expr, $verbosity:expr, $fmt:literal, $($arg:tt)*) => { if ($console).verbosity >= $verbosity { - eprintln!("{}", $msg); + ::std::eprintln!("{}", &::mozart_console_macros::console_format!($fmt, $($arg)*)); } }; } @@ -339,12 +357,18 @@ macro_rules! console_writeln_error { /// ref: \Composer\IO\IOInterface::writeError() #[macro_export] macro_rules! console_write_error { - ($console:expr, $msg:expr $(,)?) => { - $crate::console_write_error!($console, $msg, $crate::console::Verbosity::Normal) + ($console:expr, $fmt:literal) => { + $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt,) + }; + ($console:expr, $fmt:literal, $($arg:tt)*) => { + $crate::console_writeln!($console, $crate::console::Verbosity::Normal, $fmt, $($arg)*) + }; + ($console:expr, $verbosity:expr, $fmt:literal) => { + $crate::console_writeln!($console, $verbosity, $fmt, $($arg)*,) }; - ($console:expr, $msg:expr, $verbosity:expr $(,)?) => { + ($console:expr, $verbosity:expr, $fmt:literal, $($arg:tt)*) => { if ($console).verbosity >= $verbosity { - eprint!("{}", $msg); + ::std::eprint!("{}", &::mozart_console_macros::console_format!($fmt, $($arg)*)); } }; } diff --git a/crates/mozart-registry/Cargo.toml b/crates/mozart-registry/Cargo.toml index ceaaed0..6239973 100644 --- a/crates/mozart-registry/Cargo.toml +++ b/crates/mozart-registry/Cargo.toml @@ -4,6 +4,7 @@ version.workspace = true edition.workspace = true [dependencies] +mozart-console-macros.workspace = true mozart-core.workspace = true mozart-metadata-minifier.workspace = true mozart-php-serialize.workspace = true diff --git a/crates/mozart-registry/src/advisory.rs b/crates/mozart-registry/src/advisory.rs index 894a0ac..86d37af 100644 --- a/crates/mozart-registry/src/advisory.rs +++ b/crates/mozart-registry/src/advisory.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use indexmap::IndexMap; use mozart_core::advisory::{AbandonedHandling, AuditFormat}; use mozart_core::console::Console; -use mozart_core::{console_format, console_writeln, console_writeln_error}; +use mozart_core::{console_writeln, console_writeln_error}; use crate::packagist::SecurityAdvisory; use crate::repository::RepositorySet; @@ -154,7 +154,7 @@ impl Auditor { let msg = format!( "Found {ignored_total} ignored security vulnerability advisor{plurality} affecting {ignored_pkg_count} package{pkg_plurality}{punctuation}" ); - console_writeln_error!(console, &console_format!("{msg}")); + console_writeln_error!(console, "{msg}"); self.output_advisories_ignored(console, &ignored_advisories, format); } @@ -170,9 +170,9 @@ impl Auditor { "Found {active_total} security vulnerability advisor{plurality} affecting {active_pkg_count} package{pkg_plurality}{punctuation}" ); if options.warning_only { - console_writeln_error!(console, &console_format!("{msg}")); + console_writeln_error!(console, "{msg}"); } else { - console_writeln_error!(console, &console_format!("{msg}")); + console_writeln_error!(console, "{msg}"); } self.output_advisories(console, &advisories, format); } @@ -186,17 +186,17 @@ impl Auditor { } else { console_writeln_error!( console, - &console_format!("No security vulnerability advisories found.") + "No security vulnerability advisories found.", ); } if !unreachable_repos.is_empty() { console_writeln_error!( console, - &console_format!("The following repositories were unreachable:") + "The following repositories were unreachable:", ); for repo in &unreachable_repos { - console_writeln_error!(console, &format!(" - {repo}")); + console_writeln_error!(console, " - {repo}"); } } @@ -461,20 +461,18 @@ impl Auditor { vw = value_width ); - console_writeln_error!(console, &separator); + console_writeln_error!(console, "{}", separator); for (label, value) in &rows { console_writeln_error!( console, - &format!( - "| {:, ) { - console_writeln_error!(console, &format!("Package: {}", adv.package_name)); - console_writeln_error!(console, &format!("Version: {installed_version}")); + console_writeln_error!(console, "Package: {}", adv.package_name); + console_writeln_error!(console, "Version: {installed_version}"); console_writeln_error!( console, - &format!("Severity: {}", adv.severity.as_deref().unwrap_or("")) + "Severity: {}", + adv.severity.as_deref().unwrap_or(""), ); - console_writeln_error!(console, &format!("Advisory ID: {}", adv.advisory_id)); - console_writeln_error!( - console, - &format!("CVE: {}", adv.cve.as_deref().unwrap_or("NO CVE")) - ); - console_writeln_error!(console, &format!("Title: {}", adv.title)); - console_writeln_error!( - console, - &format!("URL: {}", adv.link.as_deref().unwrap_or("")) - ); - console_writeln_error!( - console, - &format!("Affected versions: {}", adv.affected_versions) - ); - console_writeln_error!(console, &format!("Reported at: {}", adv.reported_at)); + console_writeln_error!(console, "Advisory ID: {}", adv.advisory_id); + console_writeln_error!(console, "CVE: {}", adv.cve.as_deref().unwrap_or("NO CVE")); + console_writeln_error!(console, "Title: {}", adv.title); + console_writeln_error!(console, "URL: {}", adv.link.as_deref().unwrap_or("")); + console_writeln_error!(console, "Affected versions: {}", adv.affected_versions); + console_writeln_error!(console, "Reported at: {}", adv.reported_at); if let Some(reason) = ignore_reason { - console_writeln_error!(console, &format!("Ignore reason: {reason}")); + console_writeln_error!(console, "Ignore reason: {reason}"); } } @@ -565,7 +555,7 @@ impl Auditor { let plurality = if count == 1 { "" } else { "s" }; console_writeln_error!( console, - &console_format!("Found {count} abandoned package{plurality}:") + "Found {count} abandoned package{plurality}:", ); if format == AuditFormat::Plain { @@ -573,17 +563,16 @@ impl Auditor { match &pkg.replacement { Some(repl) => console_writeln_error!( console, - &format!( - "{} ({}) is abandoned. Use {} instead.", - pkg.name, pkg.version, repl - ), + "{} ({}) is abandoned. Use {} instead.", + pkg.name, + pkg.version, + repl, ), None => console_writeln_error!( console, - &format!( - "{} ({}) is abandoned. No replacement was suggested.", - pkg.name, pkg.version - ), + "{} ({}) is abandoned. No replacement was suggested.", + pkg.name, + pkg.version, ), } } @@ -612,27 +601,23 @@ impl Auditor { console_writeln_error!( console, - &format!( - "| {: anyhow::Result<()> { console_writeln!( console, - &console_format!( - r#"Mozart - Dependency Manager for PHP - version {MOZART_VERSION} + r#"Mozart - Dependency Manager for PHP - version {MOZART_VERSION} Mozart is a dependency manager tracking local dependencies of your projects and libraries. -See https://getcomposer.org/ for more information."# - ), +See https://getcomposer.org/ for more information."#, ); Ok(()) } diff --git a/crates/mozart/src/commands/archive.rs b/crates/mozart/src/commands/archive.rs index 82af052..a3311df 100644 --- a/crates/mozart/src/commands/archive.rs +++ b/crates/mozart/src/commands/archive.rs @@ -111,7 +111,7 @@ async fn archive( .map(|rel| rel.display().to_string()) .filter(|rel| rel.len() < absolute.len()) .unwrap_or(absolute); - console_writeln!(io, &format!("Created: {}", short_path)); + console_writeln!(io, "Created: {}", short_path); Ok(()) } diff --git a/crates/mozart/src/commands/browse.rs b/crates/mozart/src/commands/browse.rs index 538cf6a..c4c957b 100644 --- a/crates/mozart/src/commands/browse.rs +++ b/crates/mozart/src/commands/browse.rs @@ -1,7 +1,6 @@ use clap::Args; use mozart_core::composer::Composer; use mozart_core::console::Console; -use mozart_core::console_format; use mozart_core::console_writeln; use mozart_core::console_writeln_error; use mozart_core::exit_code; @@ -66,7 +65,8 @@ pub async fn execute(args: &BrowseArgs, cli: &super::Cli, console: &Console) -> return_code = 1; console_writeln_error!( console, - &console_format!("Package {} not found", package_name), + "Package {} not found", + package_name, ); } @@ -77,10 +77,7 @@ pub async fn execute(args: &BrowseArgs, cli: &super::Cli, console: &Console) -> } else { "Invalid or missing repository URL" }; - console_writeln_error!( - console, - &console_format!("{} for {}", kind, package_name), - ); + console_writeln_error!(console, "{} for {}", kind, package_name); } } @@ -125,7 +122,7 @@ fn handle_package( }; if show_only { - console_writeln!(console, &console_format!("{}", url)); + console_writeln!(console, "{}", url); } else { open_browser(&url, console)?; } @@ -156,10 +153,8 @@ fn open_browser(url: &str, console: &Console) -> anyhow::Result<()> { } else { console_writeln_error!( console, - &format!( - "No suitable browser opening command found, open yourself: {}", - url - ), + "No suitable browser opening command found, open yourself: {}", + url, ); } Ok(()) diff --git a/crates/mozart/src/commands/bump.rs b/crates/mozart/src/commands/bump.rs index a4c71b8..6c53784 100644 --- a/crates/mozart/src/commands/bump.rs +++ b/crates/mozart/src/commands/bump.rs @@ -2,7 +2,6 @@ use clap::Args; use indexmap::IndexMap; use mozart_core::composer::{Composer, LocalRepository}; use mozart_core::console::Console; -use mozart_core::console_format; use mozart_core::{console_writeln, console_writeln_error}; use std::collections::BTreeMap; use std::path::Path; @@ -69,10 +68,8 @@ pub async fn do_bump( if !is_readable(&composer_json_path) { console_writeln_error!( io, - &console_format!( - "{} is not readable.", - composer_json_path.display() - ), + "{} is not readable.", + composer_json_path.display(), ); return Ok(mozart_core::exit_code::GENERAL_ERROR); } @@ -82,10 +79,8 @@ pub async fn do_bump( Err(_) => { console_writeln_error!( io, - &console_format!( - "{} is not readable.", - composer_json_path.display() - ), + "{} is not readable.", + composer_json_path.display(), ); return Ok(mozart_core::exit_code::GENERAL_ERROR); } @@ -94,10 +89,8 @@ pub async fn do_bump( if !is_writable(&composer_json_path) { console_writeln_error!( io, - &console_format!( - "{} is not writable.", - composer_json_path.display() - ), + "{} is not writable.", + composer_json_path.display(), ); return Ok(mozart_core::exit_code::GENERAL_ERROR); } @@ -125,9 +118,7 @@ pub async fn do_bump( if !lock.is_fresh(&contents) { console_writeln_error!( io, - &console_format!( - "The lock file is not up to date with the latest changes in composer.json. Run the appropriate `update` to fix that before you use the `bump` command." - ), + "The lock file is not up to date with the latest changes in composer.json. Run the appropriate `update` to fix that before you use the `bump` command.", ); return Ok(ERROR_LOCK_OUTDATED); } @@ -140,22 +131,16 @@ pub async fn do_bump( if package_type != Some("project") && !dev_only { console_writeln_error!( io, - &console_format!( - "Warning: Bumping dependency constraints is not recommended for libraries as it will narrow down your dependencies and may cause problems for your users." - ), + "Warning: Bumping dependency constraints is not recommended for libraries as it will narrow down your dependencies and may cause problems for your users.", ); if package_type.is_none() { console_writeln_error!( io, - &console_format!( - "If your package is not a library, you can explicitly specify the \"type\" by using \"composer config type project\"." - ), + "If your package is not a library, you can explicitly specify the \"type\" by using \"composer config type project\".", ); console_writeln_error!( io, - &console_format!( - "Alternatively you can use {dev_only_flag_hint} to only bump dependencies within \"require-dev\"." - ), + "Alternatively you can use {dev_only_flag_hint} to only bump dependencies within \"require-dev\".", ); } } @@ -244,35 +229,26 @@ pub async fn do_bump( if dry_run { console_writeln!( io, - &console_format!( - "{} would be updated with:", - composer_json_path.display() - ), + "{} would be updated with:", + composer_json_path.display(), ); for (require_type, packages) in &updates { for (package, version) in packages { - console_writeln!( - io, - &console_format!(" - {require_type}.{package}: {version}"), - ); + console_writeln!(io, " - {require_type}.{package}: {version}"); } } } else { console_writeln!( io, - &console_format!( - "{} has been updated ({change_count} changes).", - composer_json_path.display() - ), + "{} has been updated ({change_count} changes).", + composer_json_path.display(), ); } } else { console_writeln!( io, - &console_format!( - "No requirements to update in {}.", - composer_json_path.display() - ), + "No requirements to update in {}.", + composer_json_path.display(), ); } diff --git a/crates/mozart/src/commands/check_platform_reqs.rs b/crates/mozart/src/commands/check_platform_reqs.rs index c8dadf9..1a10882 100644 --- a/crates/mozart/src/commands/check_platform_reqs.rs +++ b/crates/mozart/src/commands/check_platform_reqs.rs @@ -1,6 +1,5 @@ use clap::Args; use mozart_core::console::Console; -use mozart_core::console_format; use mozart_core::console_writeln; use mozart_core::console_writeln_error; use mozart_core::installer::{InstalledCandidate, InstalledRepoLite}; @@ -84,10 +83,8 @@ pub async fn execute( } console_writeln_error!( console, - &console_format!( - "Checking {}platform requirements using the lock file", - dev_text - ), + "Checking {}platform requirements using the lock file", + dev_text, ); load_lock(&lock_path, args.no_dev, &mut installed_repo, &mut requires)?; } else { @@ -100,19 +97,15 @@ pub async fn execute( let installed = mozart_registry::installed::InstalledPackages::read(&vendor_dir)?; console_writeln_error!( console, - &console_format!( - "Checking {}platform requirements for packages in the vendor dir", - dev_text - ), + "Checking {}platform requirements for packages in the vendor dir", + dev_text, ); load_installed(&installed, args.no_dev, &mut installed_repo, &mut requires); } else { console_writeln_error!( console, - &console_format!( - "No vendor dir present, checking {}platform requirements from the lock file", - dev_text - ), + "No vendor dir present, checking {}platform requirements from the lock file", + dev_text, ); if lock_path.exists() { load_lock(&lock_path, args.no_dev, &mut installed_repo, &mut requires)?; @@ -406,7 +399,7 @@ fn print_table(results: &[CheckRow], format: &str, console: &Console) -> anyhow: }) }) .collect(); - console_writeln!(console, &serde_json::to_string_pretty(&rows)?); + console_writeln!(console, "{}", &serde_json::to_string_pretty(&rows)?); return Ok(()); } @@ -446,25 +439,19 @@ fn print_table(results: &[CheckRow], format: &str, console: &Console) -> anyhow: Status::Success => { console_writeln!( console, - &console_format!( - "{padded_name} {padded_version} {link_text} success{provider_suffix}", - ), + "{padded_name} {padded_version} {link_text} success{provider_suffix}", ); } Status::Failed => { console_writeln!( console, - &console_format!( - "{padded_name} {padded_version} {link_text} failed{provider_suffix}", - ), + "{padded_name} {padded_version} {link_text} failed{provider_suffix}", ); } Status::Missing => { console_writeln!( console, - &console_format!( - "{padded_name} {padded_version} {link_text} missing{provider_suffix}", - ), + "{padded_name} {padded_version} {link_text} missing{provider_suffix}", ); } } diff --git a/crates/mozart/src/commands/clear_cache.rs b/crates/mozart/src/commands/clear_cache.rs index 6912fbf..ee8aad9 100644 --- a/crates/mozart/src/commands/clear_cache.rs +++ b/crates/mozart/src/commands/clear_cache.rs @@ -2,8 +2,8 @@ use std::{borrow::Cow, path::Path}; use clap::Args; use mozart_core::composer::Composer; +use mozart_core::console_writeln_error; use mozart_core::factory::create_config; -use mozart_core::{console_format, console_writeln_error}; use mozart_registry::cache::Cache; #[derive(Args)] @@ -43,10 +43,8 @@ pub async fn execute( if !path.exists() { console_writeln_error!( console, - &console_format!( - "Cache directory does not exist ({key}): {}", - path.display(), - ), + "Cache directory does not exist ({key}): {}", + path.display(), ); continue; } @@ -55,10 +53,8 @@ pub async fn execute( if !cache.is_enabled() { console_writeln_error!( console, - &console_format!( - "Cache is not enabled ({key}): {}", - path.display(), - ), + "Cache is not enabled ({key}): {}", + path.display(), ); continue; } @@ -66,10 +62,8 @@ pub async fn execute( if args.gc { console_writeln_error!( console, - &console_format!( - "Garbage-collecting cache ({key}): {}", - path.display(), - ), + "Garbage-collecting cache ({key}): {}", + path.display(), ); match key { "cache-files-dir" => cache.gc(config.cache_files_ttl, config.cache_files_maxsize)?, @@ -80,22 +74,17 @@ pub async fn execute( } else { console_writeln_error!( console, - &console_format!("Clearing cache ({key}): {}", path.display()), + "Clearing cache ({key}): {}", + path.display(), ); cache.clear()?; } } if args.gc { - console_writeln_error!( - console, - &console_format!("All caches garbage-collected."), - ); + console_writeln_error!(console, "All caches garbage-collected."); } else { - console_writeln_error!( - console, - &console_format!("All caches cleared."), - ); + console_writeln_error!(console, "All caches cleared."); } Ok(()) diff --git a/crates/mozart/src/commands/config.rs b/crates/mozart/src/commands/config.rs index 58d593a..7227556 100644 --- a/crates/mozart/src/commands/config.rs +++ b/crates/mozart/src/commands/config.rs @@ -998,8 +998,10 @@ fn execute_read( for (key, value) in config.entries() { console_writeln!( console, - &format!("[{}] {}", key, render_value(&value)), mozart_core::console::Verbosity::Quiet, + "[{}] {}", + key, + render_value(&value), ); } return Ok(()); @@ -1019,8 +1021,9 @@ fn execute_read( if entry.get("name").and_then(|n| n.as_str()) == Some(repo_name) { console_writeln!( console, - &render_value(entry), mozart_core::console::Verbosity::Quiet, + "{}", + &render_value(entry), ); return Ok(()); } @@ -1035,8 +1038,9 @@ fn execute_read( if let Some(v) = get_nested(&raw, key) { console_writeln!( console, - &render_value(v), mozart_core::console::Verbosity::Quiet, + "{}", + &render_value(v), ); return Ok(()); } @@ -1049,8 +1053,9 @@ fn execute_read( if let Some(v) = raw.get(key.as_str()) { console_writeln!( console, - &render_value(v), mozart_core::console::Verbosity::Quiet, + "{}", + &render_value(v), ); return Ok(()); } @@ -1062,8 +1067,9 @@ fn execute_read( Some(value) => { console_writeln!( console, - &render_value(&value), mozart_core::console::Verbosity::Quiet, + "{}", + &render_value(&value), ); } None => { diff --git a/crates/mozart/src/commands/dependency.rs b/crates/mozart/src/commands/dependency.rs index 8b84fe4..f4e7430 100644 --- a/crates/mozart/src/commands/dependency.rs +++ b/crates/mozart/src/commands/dependency.rs @@ -92,11 +92,9 @@ pub fn do_execute( if inverted { console_writeln!( console, - &console_format!( - "{} {} can be installed.", - package, - version.unwrap_or("") - ), + "{} {} can be installed.", + package, + version.unwrap_or(""), ); return Ok(()); } @@ -648,10 +646,7 @@ fn sample_versions_from_constraint( /// Columns: package name | version | link description | link constraint pub fn print_table(results: &[DependencyResult], console: &mozart_core::console::Console) { if results.is_empty() { - console_writeln!( - console, - &console_format!("No relationships found."), - ); + console_writeln!(console, "No relationships found."); return; } @@ -683,16 +678,14 @@ pub fn print_table(results: &[DependencyResult], console: &mozart_core::console: } console_writeln!( console, - &format!( - "{:{}", r.package_name), - console_format!("{}", r.package_version), - r.link_description, - console_format!("{}", r.link_constraint), - name_w = name_w, - ver_w = ver_w, - desc_w = desc_w, - ), + "{:{}", r.package_name), + console_format!("{}", r.package_version), + r.link_description, + console_format!("{}", r.link_constraint), + name_w = name_w, + ver_w = ver_w, + desc_w = desc_w, ); } } @@ -712,10 +705,7 @@ pub fn print_tree( console: &mozart_core::console::Console, ) { if results.is_empty() && depth == 0 { - console_writeln!( - console, - &console_format!("No relationships found."), - ); + console_writeln!(console, "No relationships found."); return; } @@ -726,14 +716,12 @@ pub fn print_tree( console_writeln!( console, - &format!( - "{}{:<} {} {} {}", - prefix, - console_format!("{}", r.package_name), - console_format!("{}", r.package_version), - r.link_description, - console_format!("{}", r.link_constraint), - ), + "{}{:<} {} {} {}", + prefix, + console_format!("{}", r.package_name), + console_format!("{}", r.package_version), + r.link_description, + console_format!("{}", r.link_constraint), ); if !r.children.is_empty() { diff --git a/crates/mozart/src/commands/diagnose.rs b/crates/mozart/src/commands/diagnose.rs index fd2297a..af18fdc 100644 --- a/crates/mozart/src/commands/diagnose.rs +++ b/crates/mozart/src/commands/diagnose.rs @@ -58,37 +58,34 @@ fn output_result(label: &str, result: &CheckResult, exit_code: &mut i32, console CheckResult::Ok(detail) => { let ok = "OK".green().bold(); match detail { - Some(d) => console_writeln!( - console, - &format!("{prefix}{ok} {}", format!("({d})").bright_black()) - ), - None => console_writeln!(console, &format!("{prefix}{ok}")), + Some(d) => { + console_writeln!(console, "{prefix}{ok} {}", format!("({d})").bright_black()) + } + None => console_writeln!(console, "{prefix}{ok}"), } } CheckResult::Warning(msgs) => { - console_writeln!(console, &format!("{prefix}{}", "WARNING".yellow().bold())); + console_writeln!(console, "{prefix}{}", "WARNING".yellow().bold()); for msg in msgs { - console_writeln!(console, &format!("{}", msg.yellow())); + console_writeln!(console, "{}", msg.yellow()); } if *exit_code < 1 { *exit_code = 1; } } CheckResult::Fail(msgs) => { - console_writeln!(console, &format!("{prefix}{}", "FAIL".red().bold())); + console_writeln!(console, "{prefix}{}", "FAIL".red().bold()); for msg in msgs { - console_writeln!(console, &format!("{}", msg.red())); + console_writeln!(console, "{}", msg.red()); } *exit_code = 2; } CheckResult::Skip(reason) => { console_writeln!( console, - &format!( - "{prefix}{} {}", - "SKIP".cyan().bold(), - format!("({reason})").bright_black() - ) + "{prefix}{} {}", + "SKIP".cyan().bold(), + format!("({reason})").bright_black(), ); } } @@ -372,7 +369,7 @@ pub async fn execute( // Step 4b (`checkVersion`) is deferred until self-update lands. // Step 5: Mozart version line. - console_writeln!(console, &format!("Mozart version {MOZART_VERSION}")); + console_writeln!(console, "Mozart version {MOZART_VERSION}"); // Step 6: Mozart and its dependencies for vulnerabilities. Deferred — needs // a Mozart Auditor port. @@ -474,13 +471,8 @@ pub async fn execute( { console_writeln!( console, - &format!( - "{}", - format!( - "The COMPOSER_IPRESOLVE env var is set to {val} which may result in network failures below." - ) - .yellow() - ) + "{}", + format!("The COMPOSER_IPRESOLVE env var is set to {val} which may result in network failures below.").yellow(), ); } diff --git a/crates/mozart/src/commands/dump_autoload.rs b/crates/mozart/src/commands/dump_autoload.rs index 0d12220..f2db011 100644 --- a/crates/mozart/src/commands/dump_autoload.rs +++ b/crates/mozart/src/commands/dump_autoload.rs @@ -1,7 +1,7 @@ use clap::Args; use mozart_autoload::AutoloadGeneratorExt; use mozart_core::composer::{AutoloadDumpOptions, Composer, PlatformRequirementFilter}; -use mozart_core::{console_format, console_writeln}; +use mozart_core::console_writeln; #[derive(Args, Default)] pub struct DumpAutoloadArgs { @@ -69,9 +69,7 @@ pub async fn execute( missing = true; console_writeln!( console, - &console_format!( - r#"Not all dependencies are installed. Make sure to run a "composer install" to install missing dependencies"# - ), + r#"Not all dependencies are installed. Make sure to run a "composer install" to install missing dependencies"#, ); break; } @@ -99,16 +97,14 @@ pub async fn execute( console_writeln!( console, - &console_format!( - "{}", - if class_map_authoritative { - "Generating optimized autoload files (authoritative)" - } else if optimize { - "Generating optimized autoload files" - } else { - "Generating autoload files" - } - ), + "{}", + if class_map_authoritative { + "Generating optimized autoload files (authoritative)" + } else if optimize { + "Generating optimized autoload files" + } else { + "Generating autoload files" + } ); let dev_mode = if args.dev { @@ -148,22 +144,15 @@ pub async fn execute( if class_map_authoritative { console_writeln!( console, - &console_format!( - "Generated optimized autoload files (authoritative) containing {number_of_classes} classes", - ), + "Generated optimized autoload files (authoritative) containing {number_of_classes} classes", ); } else if optimize { console_writeln!( console, - &console_format!( - "Generated optimized autoload files containing {number_of_classes} classes", - ), + "Generated optimized autoload files containing {number_of_classes} classes", ); } else { - console_writeln!( - console, - &console_format!("Generated autoload files"), - ); + console_writeln!(console, "Generated autoload files"); } if missing_dependencies || args.strict_psr && class_map.has_psr_violations() { diff --git a/crates/mozart/src/commands/exec.rs b/crates/mozart/src/commands/exec.rs index bf32997..27d1a8a 100644 --- a/crates/mozart/src/commands/exec.rs +++ b/crates/mozart/src/commands/exec.rs @@ -1,6 +1,5 @@ use clap::Args; use mozart_core::composer::Composer; -use mozart_core::console_format; use mozart_core::console_writeln; use std::path::{Path, PathBuf}; @@ -36,15 +35,12 @@ pub async fn execute( bin_dir.display(), ); } - console_writeln!( - console, - &console_format!("Available binaries:"), - ); + console_writeln!(console, "Available binaries:"); for (bin, is_local) in &bins { if *is_local { - console_writeln!(console, &console_format!("- {bin} (local)")); + console_writeln!(console, "- {bin} (local)"); } else { - console_writeln!(console, &console_format!("- {bin}")); + console_writeln!(console, "- {bin}"); } } return Ok(()); diff --git a/crates/mozart/src/commands/fund.rs b/crates/mozart/src/commands/fund.rs index 707e9ee..1f334b3 100644 --- a/crates/mozart/src/commands/fund.rs +++ b/crates/mozart/src/commands/fund.rs @@ -157,15 +157,15 @@ fn render_text(fundings: &BTreeMap>>, conso let mut prev: Option = None; for (vendor, url_map) in fundings { console_writeln!(console, ""); - console_writeln!(console, &console_format!("{vendor}")); + console_writeln!(console, "{vendor}"); for (url, packages) in url_map { let line = format!(" {}", packages.join(", ")); if prev.as_deref() != Some(line.as_str()) { - console_writeln!(console, &console_format!("{line}")); + console_writeln!(console, "{line}"); prev = Some(line); } let link = hyperlink(url, url, console.decorated); - console_writeln!(console, &format!(" {link}")); + console_writeln!(console, " {link}"); } } @@ -192,7 +192,7 @@ fn render_json( } else { fundings.serialize(&mut ser)?; } - console_writeln!(console, &String::from_utf8(ser.into_inner())?); + console_writeln!(console, "{}", &String::from_utf8(ser.into_inner())?); Ok(()) } diff --git a/crates/mozart/src/commands/licenses.rs b/crates/mozart/src/commands/licenses.rs index 468fde7..394cc39 100644 --- a/crates/mozart/src/commands/licenses.rs +++ b/crates/mozart/src/commands/licenses.rs @@ -3,7 +3,6 @@ use indexmap::IndexMap; use mozart_core::composer::Composer; use mozart_core::console::Console; use mozart_core::console::hyperlink; -use mozart_core::console_format; use mozart_core::console_writeln; use mozart_core::package_info; use mozart_core::package_info::PackageUrls; @@ -273,18 +272,9 @@ fn render_text( } else { root_licenses.join(", ") }; - console_writeln!( - console, - &console_format!("Name: {root_pretty_name}"), - ); - console_writeln!( - console, - &console_format!("Version: {root_version}"), - ); - console_writeln!( - console, - &console_format!("Licenses: {license_display}"), - ); + console_writeln!(console, "Name: {root_pretty_name}"); + console_writeln!(console, "Version: {root_version}"); + console_writeln!(console, "Licenses: {license_display}"); console_writeln!(console, "Dependencies:"); console_writeln!(console, ""); @@ -307,13 +297,11 @@ fn render_text( console_writeln!( console, - &format!( - "{:Removing {name} from require-dev"), - ); + console_writeln!(console, "Removing {name} from require-dev"); composer.require_dev.remove(&name); packages_removed.push(name); } else { @@ -164,17 +161,11 @@ pub async fn execute( )); } } else if composer.require.contains_key(&name) { - console_writeln!( - console, - &console_format!("Removing {name} from require"), - ); + console_writeln!(console, "Removing {name} from require"); composer.require.remove(&name); packages_removed.push(name); } else if composer.require_dev.contains_key(&name) { - console_writeln!( - console, - &console_format!("Removing {name} from require-dev"), - ); + console_writeln!(console, "Removing {name} from require-dev"); composer.require_dev.remove(&name); packages_removed.push(name); } else { @@ -192,9 +183,7 @@ pub async fn execute( if args.no_update { console_writeln!( console, - &console_format!( - "Not updating dependencies, only modifying composer.json." - ), + "Not updating dependencies, only modifying composer.json." ); return Ok(()); } diff --git a/crates/mozart/src/commands/repository.rs b/crates/mozart/src/commands/repository.rs index 27c822c..3905c77 100644 --- a/crates/mozart/src/commands/repository.rs +++ b/crates/mozart/src/commands/repository.rs @@ -104,7 +104,7 @@ fn list_repositories( && let Some((key, val)) = obj.iter().next() && val == &serde_json::Value::Bool(false) { - console_writeln!(console, &format!("[{key}] disabled")); + console_writeln!(console, "[{key}] disabled"); continue; } @@ -118,7 +118,7 @@ fn list_repositories( .unwrap_or("unknown"); let url = entry.get("url").map(render_value).unwrap_or_default(); - console_writeln!(console, &format!("[{name}] {repo_type} {url}")); + console_writeln!(console, "[{name}] {repo_type} {url}"); } Ok(()) @@ -223,7 +223,7 @@ fn execute_get_url( // Assoc-keyed fast path (mirrors Composer's `isset($repos[$name])` check). if let Some(repo) = repos_raw.as_object().and_then(|obj| obj.get(name)) { if let Some(url) = repo.get("url").and_then(|u| u.as_str()) { - console_writeln!(console, url); + console_writeln!(console, "{}", url); return Ok(()); } anyhow::bail!("The {} repository does not have a URL", name); @@ -234,7 +234,7 @@ fn execute_get_url( for repo in &repos { if repo.get("name").and_then(|n| n.as_str()) == Some(name) { if let Some(url) = repo.get("url").and_then(|u| u.as_str()) { - console_writeln!(console, url); + console_writeln!(console, "{}", url); return Ok(()); } anyhow::bail!("The {} repository does not have a URL", name); diff --git a/crates/mozart/src/commands/require.rs b/crates/mozart/src/commands/require.rs index 22f7a8d..3ccba96 100644 --- a/crates/mozart/src/commands/require.rs +++ b/crates/mozart/src/commands/require.rs @@ -949,9 +949,7 @@ pub async fn execute( console_writeln!( console, - &console_format!( - "Using version constraint for {name} from Packagist..." - ), + "Using version constraint for {name} from Packagist..." ); let best = version_selector @@ -970,7 +968,7 @@ pub async fn execute( console_writeln!( console, - &console_format!("Using version {constraint} for {name}"), + "Using version {constraint} for {name}", ); (name, constraint) @@ -1031,15 +1029,12 @@ pub async fn execute( if let Some(existing) = target.get(name) { console_writeln!( console, - &console_format!( - "Updating {name} from {existing} to {constraint} \ - in {section_name}" - ), + "Updating {name} from {existing} to {constraint} in {section_name}", ); } else { console_writeln!( console, - &console_format!("Adding {name} ({constraint}) to {section_name}"), + "Adding {name} ({constraint}) to {section_name}", ); } @@ -1067,7 +1062,7 @@ pub async fn execute( if args.dry_run { console_writeln!( console, - &console_format!("Dry run: composer.json not modified."), + "Dry run: composer.json not modified.", ); } else { update_file(&composer_path, &raw)?; @@ -1085,9 +1080,7 @@ pub async fn execute( if args.no_update { console_writeln!( console, - &console_format!( - "Not updating dependencies, only modifying composer.json." - ), + "Not updating dependencies, only modifying composer.json." ); return Ok(()); } diff --git a/crates/mozart/src/commands/run_script.rs b/crates/mozart/src/commands/run_script.rs index abfb93a..ade389e 100644 --- a/crates/mozart/src/commands/run_script.rs +++ b/crates/mozart/src/commands/run_script.rs @@ -168,16 +168,13 @@ fn list_scripts( return Ok(()); } - console_writeln_error!( - console, - &mozart_core::console_format!("scripts:"), - ); + console_writeln_error!(console, "scripts:"); let name_width = scripts.keys().map(|n| n.len() + 2).max().unwrap_or(0); for name in scripts.keys() { let desc = descriptions.get(name).map(|s| s.as_str()).unwrap_or(""); let padded = format!(" {: anyhow::Result<() let formatter = serde_json::ser::PrettyFormatter::with_indent(b" "); let mut ser = serde_json::Serializer::with_formatter(buf, formatter); output.serialize(&mut ser)?; - console_writeln!(console, &String::from_utf8(ser.into_inner())?); + console_writeln!(console, "{}", &String::from_utf8(ser.into_inner())?); Ok(()) } @@ -189,7 +189,7 @@ fn render_text(results: &[SearchResult], console: &Console) { format!("{}{}", result.name, " ".repeat(padding_width)) }; - console_writeln!(console, &format!("{padded_name}{warning}{desc_display}")); + console_writeln!(console, "{padded_name}{warning}{desc_display}"); } } diff --git a/crates/mozart/src/commands/self_update.rs b/crates/mozart/src/commands/self_update.rs index d5ddda0..a326914 100644 --- a/crates/mozart/src/commands/self_update.rs +++ b/crates/mozart/src/commands/self_update.rs @@ -1,6 +1,5 @@ use clap::Args; use mozart_core::MOZART_VERSION; -use mozart_core::console_format; use mozart_core::console_writeln; use std::io::Write; use std::path::{Path, PathBuf}; @@ -280,19 +279,14 @@ async fn update( if args.version.is_none() && target_version == current_version { console_writeln!( console, - &console_format!( - "You are already using the latest available Mozart version {current_version} ({channel} channel)." - ), + "You are already using the latest available Mozart version {current_version} ({channel} channel)." ); if args.clean_backups { // Preserve the most recent backup let latest = find_latest_backup(data_dir).ok(); clean_backups(data_dir, latest.as_deref())?; - console_writeln!( - console, - &console_format!("Old backups removed."), - ); + console_writeln!(console, "Old backups removed."); } return Ok(()); @@ -349,9 +343,7 @@ async fn update( console_writeln!( console, - &console_format!( - "Mozart updated successfully from {current_version} to {target_version}" - ), + "Mozart updated successfully from {current_version} to {target_version}" ); console.info(&format!( "Use `mozart self-update --rollback` to return to version {current_version}" @@ -359,10 +351,7 @@ async fn update( if args.clean_backups { clean_backups(data_dir, Some(&backup_path))?; - console_writeln!( - console, - &console_format!("Old backups removed."), - ); + console_writeln!(console, "Old backups removed."); } Ok(()) @@ -393,7 +382,7 @@ fn rollback( console_writeln!( console, - &console_format!("Rollback successful. Restored version {backup_version}"), + "Rollback successful. Restored version {backup_version}", ); let _ = current_exe; // suppress unused warning diff --git a/crates/mozart/src/commands/show.rs b/crates/mozart/src/commands/show.rs index 8bd53cb..6a07fb0 100644 --- a/crates/mozart/src/commands/show.rs +++ b/crates/mozart/src/commands/show.rs @@ -117,9 +117,7 @@ pub async fn execute( if args.installed && !args.self_info { console_writeln_error!( console, - &console_format!( - "You are using the deprecated option \"installed\". Only installed packages are shown by default now. The --all option can be used to show all packages." - ), + "You are using the deprecated option \"installed\". Only installed packages are shown by default now. The --all option can be used to show all packages.", ); } @@ -173,9 +171,7 @@ pub async fn execute( if !args.ignore.is_empty() && !args.outdated { console_writeln_error!( console, - &console_format!( - "You are using the option \"ignore\" for action other than \"outdated\", it will be ignored." - ), + "You are using the option \"ignore\" for action other than \"outdated\", it will be ignored.", ); } @@ -571,7 +567,7 @@ fn render_package_list( console_writeln!( console, - &console_format!("Direct dependencies required in composer.json:"), + "Direct dependencies required in composer.json:", ); if direct_entries.is_empty() { console_writeln!(console, "Everything up to date"); @@ -582,7 +578,7 @@ fn render_package_list( console_writeln!(console, ""); console_writeln!( console, - &console_format!("Transitive dependencies not required in composer.json:"), + "Transitive dependencies not required in composer.json:", ); if transitive_entries.is_empty() { console_writeln!(console, "Everything up to date"); @@ -700,18 +696,21 @@ fn print_package_rows( }; console_writeln!( console, - &format!( - "{}{} {} {} {}", - ascii_prefix, name_str, version_str, latest_str, entry.description - ), + "{}{} {} {} {}", + ascii_prefix, + name_str, + version_str, + latest_str, + entry.description, ); } else { console_writeln!( console, - &format!( - "{}{} {} {}", - ascii_prefix, name_str, version_str, entry.description - ), + "{}{} {} {}", + ascii_prefix, + name_str, + version_str, + entry.description, ); } @@ -730,7 +729,7 @@ fn print_package_rows( entry.name, replacement ) }; - console_writeln_error!(console, &console_format!("{}", msg),); + console_writeln_error!(console, "{}", msg); } } } @@ -738,24 +737,21 @@ fn print_package_rows( /// Print the color legend before the list (A6, mirrors Composer 626-642). fn print_color_legend(console: &mozart_core::console::Console) { if console.decorated { - console_writeln!(console, &console_format!("Color legend:"),); + console_writeln!(console, "Color legend:"); console_writeln!( console, - &format!( - "- {} release available - update recommended", - console_format!("patch or minor") - ), + "- {} release available - update recommended", + console_format!("patch or minor"), ); console_writeln!( console, - &format!( - "- {} release available - update possible", - console_format!("major") - ), + "- {} release available - update possible", + console_format!("major"), ); console_writeln!( console, - &format!("- {} version", console_format!("up to date")), + "- {} version", + console_format!("up to date"), ); } else { console_writeln!(console, "Legend:"); @@ -801,7 +797,7 @@ fn render_list_json( .collect(); let output = serde_json::json!({ section_key: json_entries }); - console_writeln!(console, &serde_json::to_string_pretty(&output)?,); + console_writeln!(console, "{}", &serde_json::to_string_pretty(&output)?); Ok(()) } @@ -945,38 +941,36 @@ async fn print_package_detail( console_writeln!( console, - &format!("{} : {}", console_format!("name"), detail.name), + "{} : {}", + console_format!("name"), + detail.name, ); console_writeln!( console, - &format!( - "{} : {}", - console_format!("descrip."), - detail.description - ), + "{} : {}", + console_format!("descrip."), + detail.description, ); console_writeln!( console, - &format!( - "{} : {}", - console_format!("keywords"), - detail.keywords.join(", ") - ), + "{} : {}", + console_format!("keywords"), + detail.keywords.join(", "), ); console_writeln!( console, - &format!( - "{} : {}", - console_format!("versions"), - format_version_highlight(&detail.version) - ), + "{} : {}", + console_format!("versions"), + format_version_highlight(&detail.version), ); // A13: released if let Some(ref date) = detail.release_date { console_writeln!( console, - &format!("{} : {}", console_format!("released"), date), + "{} : {}", + console_format!("released"), + date, ); } @@ -1000,43 +994,35 @@ async fn print_package_detail( }; console_writeln!( console, - &format!( - "{} : {}", - console_format!("latest"), - latest_str - ), + "{} : {}", + console_format!("latest"), + latest_str, ); } } console_writeln!( console, - &format!( - "{} : {}", - console_format!("type"), - detail.package_type.as_deref().unwrap_or("library") - ), + "{} : {}", + console_format!("type"), + detail.package_type.as_deref().unwrap_or("library"), ); for license_id in &detail.licenses { console_writeln!( console, - &format!( - "{} : {}", - console_format!("license"), - format_license_for_show(license_id), - ), + "{} : {}", + console_format!("license"), + format_license_for_show(license_id), ); } if let Some(ref homepage) = detail.homepage { console_writeln!( console, - &format!( - "{} : {}", - console_format!("homepage"), - homepage - ), + "{} : {}", + console_format!("homepage"), + homepage, ); } @@ -1045,13 +1031,11 @@ async fn print_package_detail( let src_ref = detail.source_ref.as_deref().unwrap_or(""); console_writeln!( console, - &format!( - "{} : [{}] {} {}", - console_format!("source"), - src_type, - console_format!("{}", src_url), - src_ref - ), + "{} : [{}] {} {}", + console_format!("source"), + src_type, + console_format!("{}", src_url), + src_ref, ); } @@ -1060,20 +1044,20 @@ async fn print_package_detail( let dist_ref = detail.dist_ref.as_deref().unwrap_or(""); console_writeln!( console, - &format!( - "{} : [{}] {} {}", - console_format!("dist"), - dist_type, - console_format!("{}", dist_url), - dist_ref - ), + "{} : [{}] {} {}", + console_format!("dist"), + dist_type, + console_format!("{}", dist_url), + dist_ref, ); } if let Some(ref path) = detail.install_path { console_writeln!( console, - &format!("{} : {}", console_format!("path"), path), + "{} : {}", + console_format!("path"), + path, ); } @@ -1081,11 +1065,9 @@ async fn print_package_detail( if detail.names.len() > 1 { console_writeln!( console, - &format!( - "{} : {}", - console_format!("names"), - detail.names.join(", ") - ), + "{} : {}", + console_format!("names"), + detail.names.join(", "), ); } @@ -1095,12 +1077,14 @@ async fn print_package_detail( && !obj.is_empty() { console_writeln!(console, ""); - console_writeln!(console, &console_format!("support"),); + console_writeln!(console, "support"); for (key, val) in obj { let v = val.as_str().unwrap_or(""); console_writeln!( console, - &format!("{} {}", key, console_format!("{}", v)), + "{} {}", + key, + console_format!("{}", v), ); } } @@ -1108,7 +1092,7 @@ async fn print_package_detail( // A13: autoload if let Some(ref autoload) = detail.autoload { console_writeln!(console, ""); - console_writeln!(console, &console_format!("autoload"),); + console_writeln!(console, "autoload"); if let Some(obj) = autoload.as_object() { for (loader_type, config) in obj { match config { @@ -1117,12 +1101,10 @@ async fn print_package_detail( let v_str = v.as_str().unwrap_or(""); console_writeln!( console, - &format!( - "{}: {} => {}", - loader_type, - k, - console_format!("{}", v_str) - ), + "{}: {} => {}", + loader_type, + k, + console_format!("{}", v_str), ); } } @@ -1131,11 +1113,9 @@ async fn print_package_detail( let v_str = item.as_str().unwrap_or(""); console_writeln!( console, - &format!( - "{}: {}", - loader_type, - console_format!("{}", v_str) - ), + "{}: {}", + loader_type, + console_format!("{}", v_str), ); } } @@ -1166,15 +1146,13 @@ fn print_links_section( return; } console_writeln!(console, ""); - console_writeln!(console, &console_format!("{}", label),); + console_writeln!(console, "{}", label); for (name, constraint) in links { console_writeln!( console, - &format!( - "{} {}", - name, - console_format!("{}", constraint) - ), + "{} {}", + name, + console_format!("{}", constraint), ); } } @@ -1241,7 +1219,7 @@ async fn print_package_detail_json( } } - console_writeln!(console, &serde_json::to_string_pretty(&obj)?,); + console_writeln!(console, "{}", &serde_json::to_string_pretty(&obj)?); Ok(()) } @@ -1265,9 +1243,7 @@ async fn execute_installed( if !root.require.is_empty() || !root.require_dev.is_empty() { console_writeln_error!( console, - &console_format!( - "No dependencies installed. Try running mozart install or update." - ), + "No dependencies installed. Try running mozart install or update.", ); } } @@ -1287,7 +1263,7 @@ async fn execute_installed( Some(p) => { let install_path = vendor_dir.join(&p.name); let path_str = resolve_path(&install_path); - console_writeln!(console, &format!("{} {}", p.name, path_str),); + console_writeln!(console, "{} {}", p.name, path_str); } None => { anyhow::bail!( @@ -1333,7 +1309,7 @@ async fn execute_installed( for pkg in &packages { let install_path = vendor_dir.join(&pkg.name); let path_str = resolve_path(&install_path); - console_writeln!(console, &format!("{} {}", pkg.name, path_str),); + console_writeln!(console, "{} {}", pkg.name, path_str); } return Ok(()); } @@ -1342,7 +1318,7 @@ async fn execute_installed( let show_latest = args.latest || args.outdated; if args.name_only && !show_latest { for pkg in &packages { - console_writeln!(console, &pkg.name); + console_writeln!(console, "{}", &pkg.name); } return Ok(()); } @@ -1355,7 +1331,7 @@ async fn execute_installed( if args.name_only { for e in &entries { - console_writeln!(console, &e.name); + console_writeln!(console, "{}", &e.name); } return Ok(()); } @@ -1460,7 +1436,7 @@ async fn execute_locked( if args.path { console_writeln_error!( console, - &console_format!("--path is not supported with --locked"), + "--path is not supported with --locked", ); return Ok(()); } @@ -1469,7 +1445,7 @@ async fn execute_locked( let show_latest = args.latest || args.outdated; if args.name_only && !show_latest { for pkg in &packages { - console_writeln!(console, &pkg.name); + console_writeln!(console, "{}", &pkg.name); } return Ok(()); } @@ -1482,7 +1458,7 @@ async fn execute_locked( if args.name_only { for e in &entries { - console_writeln!(console, &e.name); + console_writeln!(console, "{}", &e.name); } return Ok(()); } @@ -1514,63 +1490,55 @@ fn show_self( let root = mozart_core::package::read_from_file(&composer_json_path)?; if args.name_only { - console_writeln!(console, &root.name); + console_writeln!(console, "{}", &root.name); return Ok(()); } console_writeln!( console, - &format!("{} : {}", console_format!("name"), root.name), + "{} : {}", + console_format!("name"), + root.name, ); console_writeln!( console, - &format!( - "{} : {}", - console_format!("descrip."), - root.description.as_deref().unwrap_or("") - ), + "{} : {}", + console_format!("descrip."), + root.description.as_deref().unwrap_or(""), ); console_writeln!( console, - &format!( - "{} : {}", - console_format!("type"), - root.package_type.as_deref().unwrap_or("project") - ), + "{} : {}", + console_format!("type"), + root.package_type.as_deref().unwrap_or("project"), ); if let Some(ref license) = root.license { console_writeln!( console, - &format!( - "{} : {}", - console_format!("license"), - format_license_for_show(license), - ), + "{} : {}", + console_format!("license"), + format_license_for_show(license), ); } if let Some(ref homepage) = root.homepage { console_writeln!( console, - &format!( - "{} : {}", - console_format!("homepage"), - homepage - ), + "{} : {}", + console_format!("homepage"), + homepage, ); } // Requires if !root.require.is_empty() { console_writeln!(console, ""); - console_writeln!(console, &console_format!("requires"),); + console_writeln!(console, "requires"); for (name, constraint) in &root.require { console_writeln!( console, - &format!( - "{} {}", - name, - console_format!("{}", constraint) - ), + "{} {}", + name, + console_format!("{}", constraint), ); } } @@ -1578,15 +1546,13 @@ fn show_self( // Requires (dev) if !root.require_dev.is_empty() { console_writeln!(console, ""); - console_writeln!(console, &console_format!("requires (dev)"),); + console_writeln!(console, "requires (dev)"); for (name, constraint) in &root.require_dev { console_writeln!( console, - &format!( - "{} {}", - name, - console_format!("{}", constraint) - ), + "{} {}", + name, + console_format!("{}", constraint), ); } } @@ -1643,11 +1609,9 @@ fn show_tree( console_writeln!( console, - &console_format!( - "{} {}", - &root.name, - root.description.as_deref().unwrap_or("") - ), + "{} {}", + &root.name, + root.description.as_deref().unwrap_or(""), ); let mut visited_global: IndexSet = IndexSet::new(); @@ -1693,19 +1657,19 @@ fn print_tree_node( console_writeln!( console, - &format!( - "{} {} {}", - prefix, - console_format!("{} {}", pkg_name, &version), - description - ), + "{} {} {}", + prefix, + console_format!("{} {}", pkg_name, &version), + description, ); if visited.contains(&key) || depth >= MAX_DEPTH { if visited.contains(&key) { console_writeln!( console, - &format!("{} {} (circular dependency)", child_prefix, pkg_name), + "{} {} (circular dependency)", + child_prefix, + pkg_name, ); } return; @@ -1753,12 +1717,10 @@ fn print_tree_node( if !is_platform_package(&key) { console_writeln!( console, - &format!( - "{} {} {} (not installed)", - prefix, - console_format!("{}", pkg_name), - constraint - ), + "{} {} {} (not installed)", + prefix, + console_format!("{}", pkg_name), + constraint, ); } } @@ -1829,6 +1791,7 @@ fn show_platform( .collect(); console_writeln!( console, + "{}", &serde_json::to_string_pretty(&serde_json::json!({ "platform": json_entries }))?, ); return Ok(()); @@ -1843,7 +1806,7 @@ fn show_platform( if args.name_only { for (name, _, _) in &platform_packages { - console_writeln!(console, name); + console_writeln!(console, "{}", name); } return Ok(()); } @@ -1862,14 +1825,12 @@ fn show_platform( for (name, version, _source) in &platform_packages { console_writeln!( console, - &format!( - "{} {}", - console_format!("{:", name, width = name_width), - console_format!( - "{:", - version, - width = version_width - ), + "{} {}", + console_format!("{:", name, width = name_width), + console_format!( + "{:", + version, + width = version_width ), ); } @@ -1902,9 +1863,7 @@ async fn show_available( let lock = mozart_registry::lockfile::LockFile::read_from_file(&lock_path)?; console_writeln!( console, - &console_format!( - "Available versions for locked packages (from Packagist):" - ), + "Available versions for locked packages (from Packagist):", ); console_writeln!(console, ""); @@ -1927,9 +1886,7 @@ async fn show_available( console_writeln_error!( console, - &console_format!( - "No dependencies installed. Try running mozart install or update." - ), + "No dependencies installed. Try running mozart install or update.", ); return Ok(()); } @@ -1937,9 +1894,7 @@ async fn show_available( console_writeln!( console, - &console_format!( - "Available versions for installed packages (from Packagist):" - ), + "Available versions for installed packages (from Packagist):", ); console_writeln!(console, ""); @@ -1971,7 +1926,7 @@ async fn show_available( } } let output = serde_json::json!({ "packages": json_entries }); - console_writeln!(console, &serde_json::to_string_pretty(&output)?,); + console_writeln!(console, "{}", &serde_json::to_string_pretty(&output)?); return Ok(()); } @@ -1993,7 +1948,7 @@ async fn show_available_versions( ) -> anyhow::Result<()> { let versions = mozart_registry::packagist::fetch_package_versions(pkg_name, repo_cache).await?; if versions.is_empty() { - console_writeln!(console, &format!("No versions found for {pkg_name}"),); + console_writeln!(console, "No versions found for {pkg_name}"); return Ok(()); } @@ -2004,18 +1959,16 @@ async fn show_available_versions( "name": pkg_name, "versions": version_strings, }); - console_writeln!(console, &serde_json::to_string_pretty(&output)?,); + console_writeln!(console, "{}", &serde_json::to_string_pretty(&output)?); return Ok(()); } - console_writeln!( - console, - &console_format!("Available versions for {pkg_name}:"), - ); + console_writeln!(console, "Available versions for {pkg_name}:"); for v in &versions { console_writeln!( console, - &format!(" {}", console_format!("{}", &v.version)), + " {}", + console_format!("{}", &v.version), ); } Ok(()) @@ -2031,10 +1984,8 @@ async fn show_available_versions_inline( if versions.is_empty() { console_writeln!( console, - &format!( - "{}: no versions found", - console_format!("{}", pkg_name) - ), + "{}: no versions found", + console_format!("{}", pkg_name), ); return; } @@ -2050,21 +2001,17 @@ async fn show_available_versions_inline( }; console_writeln!( console, - &format!( - "{}: {}{}", - console_format!("{}", pkg_name), - console_format!("{}", &shown.join(", ")), - rest - ), + "{}: {}{}", + console_format!("{}", pkg_name), + console_format!("{}", &shown.join(", ")), + rest, ); } Err(_) => { console_writeln!( console, - &format!( - "{}: (could not fetch from Packagist)", - console_format!("{}", pkg_name) - ), + "{}: (could not fetch from Packagist)", + console_format!("{}", pkg_name), ); } } diff --git a/crates/mozart/src/commands/status.rs b/crates/mozart/src/commands/status.rs index 8647078..30d7396 100644 --- a/crates/mozart/src/commands/status.rs +++ b/crates/mozart/src/commands/status.rs @@ -2,7 +2,6 @@ use clap::Args; use indexmap::IndexMap; use mozart_core::composer::{Composer, InstallationSource, LocalPackage}; use mozart_core::console::Console; -use mozart_core::console_format; use mozart_core::console_writeln; use mozart_core::console_writeln_error; use mozart_core::exit_code; @@ -100,7 +99,7 @@ pub async fn execute( } if errors.is_empty() && unpushed_changes.is_empty() && vcs_version_changes.is_empty() { - console_writeln_error!(console, &console_format!("No local changes")); + console_writeln_error!(console, "No local changes"); return Ok(()); } @@ -110,14 +109,14 @@ pub async fn execute( if !errors.is_empty() { console_writeln_error!( console, - &console_format!("You have changes in the following dependencies:") + "You have changes in the following dependencies:" ); for (path, changes) in &errors { if verbose { - console_writeln!(console, &console_format!("{path}:")); - console_writeln!(console, &indent_block(changes)); + console_writeln!(console, "{path}:"); + console_writeln!(console, "{}", &indent_block(changes)); } else { - console_writeln!(console, path); + console_writeln!(console, "{}", path); } } } @@ -125,16 +124,14 @@ pub async fn execute( if !unpushed_changes.is_empty() { console_writeln_error!( console, - &console_format!( - "You have unpushed changes on the current branch in the following dependencies:" - ) + "You have unpushed changes on the current branch in the following dependencies:" ); for (path, changes) in &unpushed_changes { if verbose { - console_writeln!(console, &console_format!("{path}:")); - console_writeln!(console, &indent_block(changes)); + console_writeln!(console, "{path}:"); + console_writeln!(console, "{}", &indent_block(changes)); } else { - console_writeln!(console, path); + console_writeln!(console, "{}", path); } } } @@ -142,9 +139,7 @@ pub async fn execute( if !vcs_version_changes.is_empty() { console_writeln_error!( console, - &console_format!( - "You have version variations in the following dependencies:" - ) + "You have version variations in the following dependencies:" ); for (path, change) in &vcs_version_changes { if verbose { @@ -162,15 +157,13 @@ pub async fn execute( prev.push_str(&format!(" ({})", change.previous.reference)); curr.push_str(&format!(" ({})", change.current.reference)); } - console_writeln!(console, &console_format!("{path}:")); + console_writeln!(console, "{path}:"); console_writeln!( console, - &console_format!( - " From {prev} to {curr}" - ) + " From {prev} to {curr}" ); } else { - console_writeln!(console, path); + console_writeln!(console, "{}", path); } } } diff --git a/crates/mozart/src/commands/validate.rs b/crates/mozart/src/commands/validate.rs index df200e2..539ff20 100644 --- a/crates/mozart/src/commands/validate.rs +++ b/crates/mozart/src/commands/validate.rs @@ -399,10 +399,10 @@ fn output_result( let kind = if check_lock { "errors" } else { "warnings" }; console_writeln!( console, - &console_format!("{name} is valid but your composer.lock has some {kind}"), + "{name} is valid but your composer.lock has some {kind}", ); } else { - console_writeln!(console, &console_format!("{name} is valid"),); + console_writeln!(console, "{name} i valid"); } // Collect error and warning message lines -- cgit v1.3.1