diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-09 12:15:21 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-09 12:15:53 +0900 |
| commit | f18c18cd15f180b5067069ec6f10530515715f3d (patch) | |
| tree | 85ea3d3f10da9b32359dc3797fc7e6d262ae6752 /crates/mozart/src/commands | |
| parent | f0192390ae1d89981f59395307e885a595f86eef (diff) | |
| download | php-mozart-f18c18cd15f180b5067069ec6f10530515715f3d.tar.gz php-mozart-f18c18cd15f180b5067069ec6f10530515715f3d.tar.zst php-mozart-f18c18cd15f180b5067069ec6f10530515715f3d.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart/src/commands')
22 files changed, 331 insertions, 526 deletions
diff --git a/crates/mozart/src/commands/about.rs b/crates/mozart/src/commands/about.rs index 1dd6b85..04c3aa1 100644 --- a/crates/mozart/src/commands/about.rs +++ b/crates/mozart/src/commands/about.rs @@ -1,7 +1,6 @@ use clap::Args; use mozart_core::MOZART_VERSION; use mozart_core::console; -use mozart_core::console_format; use mozart_core::console_writeln; #[derive(Args)] @@ -14,11 +13,9 @@ pub async fn execute( ) -> anyhow::Result<()> { console_writeln!( console, - &console_format!( - r#"<info>Mozart - Dependency Manager for PHP - version {MOZART_VERSION}</info> + r#"<info>Mozart - Dependency Manager for PHP - version {MOZART_VERSION}</info> <comment>Mozart is a dependency manager tracking local dependencies of your projects and libraries. -See https://getcomposer.org/ for more information.</comment>"# - ), +See https://getcomposer.org/ for more information.</comment>"#, ); 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!("<warning>Package {} not found</warning>", package_name), + "<warning>Package {} not found</warning>", + 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!("<warning>{} for {}</warning>", kind, package_name), - ); + console_writeln_error!(console, "<warning>{} for {}</warning>", kind, package_name); } } @@ -125,7 +122,7 @@ fn handle_package( }; if show_only { - console_writeln!(console, &console_format!("<info>{}</info>", url)); + console_writeln!(console, "<info>{}</info>", 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!( - "<error>{} is not readable.</error>", - composer_json_path.display() - ), + "<error>{} is not readable.</error>", + 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!( - "<error>{} is not readable.</error>", - composer_json_path.display() - ), + "<error>{} is not readable.</error>", + 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!( - "<error>{} is not writable.</error>", - composer_json_path.display() - ), + "<error>{} is not writable.</error>", + 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!( - "<error>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.</error>" - ), + "<error>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.</error>", ); 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>Warning: Bumping dependency constraints is not recommended for libraries as it will narrow down your dependencies and may cause problems for your users.</warning>" - ), + "<warning>Warning: Bumping dependency constraints is not recommended for libraries as it will narrow down your dependencies and may cause problems for your users.</warning>", ); if package_type.is_none() { console_writeln_error!( io, - &console_format!( - "<warning>If your package is not a library, you can explicitly specify the \"type\" by using \"composer config type project\".</warning>" - ), + "<warning>If your package is not a library, you can explicitly specify the \"type\" by using \"composer config type project\".</warning>", ); console_writeln_error!( io, - &console_format!( - "<warning>Alternatively you can use {dev_only_flag_hint} to only bump dependencies within \"require-dev\".</warning>" - ), + "<warning>Alternatively you can use {dev_only_flag_hint} to only bump dependencies within \"require-dev\".</warning>", ); } } @@ -244,35 +229,26 @@ pub async fn do_bump( if dry_run { console_writeln!( io, - &console_format!( - "<info>{} would be updated with:</info>", - composer_json_path.display() - ), + "<info>{} would be updated with:</info>", + composer_json_path.display(), ); for (require_type, packages) in &updates { for (package, version) in packages { - console_writeln!( - io, - &console_format!("<info> - {require_type}.{package}: {version}</info>"), - ); + console_writeln!(io, "<info> - {require_type}.{package}: {version}</info>"); } } } else { console_writeln!( io, - &console_format!( - "<info>{} has been updated ({change_count} changes).</info>", - composer_json_path.display() - ), + "<info>{} has been updated ({change_count} changes).</info>", + composer_json_path.display(), ); } } else { console_writeln!( io, - &console_format!( - "<info>No requirements to update in {}.</info>", - composer_json_path.display() - ), + "<info>No requirements to update in {}.</info>", + 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!( - "<info>Checking {}platform requirements using the lock file</info>", - dev_text - ), + "<info>Checking {}platform requirements using the lock file</info>", + 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!( - "<info>Checking {}platform requirements for packages in the vendor dir</info>", - dev_text - ), + "<info>Checking {}platform requirements for packages in the vendor dir</info>", + dev_text, ); load_installed(&installed, args.no_dev, &mut installed_repo, &mut requires); } else { console_writeln_error!( console, - &console_format!( - "<warning>No vendor dir present, checking {}platform requirements from the lock file</warning>", - dev_text - ), + "<warning>No vendor dir present, checking {}platform requirements from the lock file</warning>", + 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!( - "<info>{padded_name}</info> <comment>{padded_version}</comment> {link_text} <info>success</info>{provider_suffix}", - ), + "<info>{padded_name}</info> <comment>{padded_version}</comment> {link_text} <info>success</info>{provider_suffix}", ); } Status::Failed => { console_writeln!( console, - &console_format!( - "<comment>{padded_name}</comment> <comment>{padded_version}</comment> {link_text} <error>failed</error>{provider_suffix}", - ), + "<comment>{padded_name}</comment> <comment>{padded_version}</comment> {link_text} <error>failed</error>{provider_suffix}", ); } Status::Missing => { console_writeln!( console, - &console_format!( - "<comment>{padded_name}</comment> <comment>{padded_version}</comment> {link_text} <error>missing</error>{provider_suffix}", - ), + "<comment>{padded_name}</comment> <comment>{padded_version}</comment> {link_text} <error>missing</error>{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!( - "<info>Cache directory does not exist ({key}): {}</info>", - path.display(), - ), + "<info>Cache directory does not exist ({key}): {}</info>", + path.display(), ); continue; } @@ -55,10 +53,8 @@ pub async fn execute( if !cache.is_enabled() { console_writeln_error!( console, - &console_format!( - "<info>Cache is not enabled ({key}): {}</info>", - path.display(), - ), + "<info>Cache is not enabled ({key}): {}</info>", + path.display(), ); continue; } @@ -66,10 +62,8 @@ pub async fn execute( if args.gc { console_writeln_error!( console, - &console_format!( - "<info>Garbage-collecting cache ({key}): {}</info>", - path.display(), - ), + "<info>Garbage-collecting cache ({key}): {}</info>", + 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!("<info>Clearing cache ({key}): {}</info>", path.display()), + "<info>Clearing cache ({key}): {}</info>", + path.display(), ); cache.clear()?; } } if args.gc { - console_writeln_error!( - console, - &console_format!("<info>All caches garbage-collected.</info>"), - ); + console_writeln_error!(console, "<info>All caches garbage-collected.</info>"); } else { - console_writeln_error!( - console, - &console_format!("<info>All caches cleared.</info>"), - ); + console_writeln_error!(console, "<info>All caches cleared.</info>"); } 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!( - "<info>{} {} can be installed.</info>", - package, - version.unwrap_or("") - ), + "<info>{} {} can be installed.</info>", + 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!("<info>No relationships found.</info>"), - ); + console_writeln!(console, "<info>No relationships found.</info>"); return; } @@ -683,16 +678,14 @@ pub fn print_table(results: &[DependencyResult], console: &mozart_core::console: } console_writeln!( console, - &format!( - "{:<name_w$} {:<ver_w$} {:<desc_w$} {}", - console_format!("<info>{}</info>", r.package_name), - console_format!("<comment>{}</comment>", r.package_version), - r.link_description, - console_format!("<comment>{}</comment>", r.link_constraint), - name_w = name_w, - ver_w = ver_w, - desc_w = desc_w, - ), + "{:<name_w$} {:<ver_w$} {:<desc_w$} {}", + console_format!("<info>{}</info>", r.package_name), + console_format!("<comment>{}</comment>", r.package_version), + r.link_description, + console_format!("<comment>{}</comment>", 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!("<info>No relationships found.</info>"), - ); + console_writeln!(console, "<info>No relationships found.</info>"); return; } @@ -726,14 +716,12 @@ pub fn print_tree( console_writeln!( console, - &format!( - "{}{:<} {} {} {}", - prefix, - console_format!("<info>{}</info>", r.package_name), - console_format!("<comment>{}</comment>", r.package_version), - r.link_description, - console_format!("<comment>{}</comment>", r.link_constraint), - ), + "{}{:<} {} {} {}", + prefix, + console_format!("<info>{}</info>", r.package_name), + console_format!("<comment>{}</comment>", r.package_version), + r.link_description, + console_format!("<comment>{}</comment>", 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#"<warning>Not all dependencies are installed. Make sure to run a "composer install" to install missing dependencies</warning>"# - ), + r#"<warning>Not all dependencies are installed. Make sure to run a "composer install" to install missing dependencies</warning>"#, ); break; } @@ -99,16 +97,14 @@ pub async fn execute( console_writeln!( console, - &console_format!( - "<info>{}</info>", - if class_map_authoritative { - "Generating optimized autoload files (authoritative)" - } else if optimize { - "Generating optimized autoload files" - } else { - "Generating autoload files" - } - ), + "<info>{}</info>", + 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!( - "<info>Generated optimized autoload files (authoritative) containing {number_of_classes} classes</info>", - ), + "<info>Generated optimized autoload files (authoritative) containing {number_of_classes} classes</info>", ); } else if optimize { console_writeln!( console, - &console_format!( - "<info>Generated optimized autoload files containing {number_of_classes} classes</info>", - ), + "<info>Generated optimized autoload files containing {number_of_classes} classes</info>", ); } else { - console_writeln!( - console, - &console_format!("<info>Generated autoload files</info>"), - ); + console_writeln!(console, "<info>Generated autoload files</info>"); } 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!("<comment>Available binaries:</comment>"), - ); + console_writeln!(console, "<comment>Available binaries:</comment>"); for (bin, is_local) in &bins { if *is_local { - console_writeln!(console, &console_format!("<info>- {bin} (local)</info>")); + console_writeln!(console, "<info>- {bin} (local)</info>"); } else { - console_writeln!(console, &console_format!("<info>- {bin}</info>")); + console_writeln!(console, "<info>- {bin}</info>"); } } 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<String, BTreeMap<String, Vec<String>>>, conso let mut prev: Option<String> = None; for (vendor, url_map) in fundings { console_writeln!(console, ""); - console_writeln!(console, &console_format!("<comment>{vendor}</comment>")); + console_writeln!(console, "<comment>{vendor}</comment>"); for (url, packages) in url_map { let line = format!(" <info>{}</info>", 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: <comment>{root_pretty_name}</comment>"), - ); - console_writeln!( - console, - &console_format!("Version: <comment>{root_version}</comment>"), - ); - console_writeln!( - console, - &console_format!("Licenses: <comment>{license_display}</comment>"), - ); + console_writeln!(console, "Name: <comment>{root_pretty_name}</comment>"); + console_writeln!(console, "Version: <comment>{root_version}</comment>"); + console_writeln!(console, "Licenses: <comment>{license_display}</comment>"); console_writeln!(console, "Dependencies:"); console_writeln!(console, ""); @@ -307,13 +297,11 @@ fn render_text( console_writeln!( console, - &format!( - "{:<nw$} {:<vw$} Licenses", - "Name", - "Version", - nw = name_width, - vw = version_width - ), + "{:<nw$} {:<vw$} Licenses", + "Name", + "Version", + nw = name_width, + vw = version_width, ); for entry in entries { @@ -329,13 +317,11 @@ fn render_text( }; console_writeln!( console, - &format!( - "{} {:<vw$} {}", - name_cell, - entry.version, - license_str, - vw = version_width - ), + "{} {:<vw$} {}", + name_cell, + entry.version, + license_str, + vw = version_width, ); } } @@ -379,7 +365,7 @@ fn render_json( 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(()) } @@ -409,31 +395,27 @@ fn render_summary(entries: &[LicenseEntry], console: &Console) { let border_col1 = "-".repeat(license_width + 2); let border_col2 = "-".repeat(count_width + 2); - console_writeln!(console, &format!(" {} {}", border_col1, border_col2),); + console_writeln!(console, " {} {}", border_col1, border_col2); console_writeln!( console, - &format!( - " {:<lw$} {:<cw$}", - "License", - COL2_HEADER, - lw = license_width, - cw = count_width - ), + " {:<lw$} {:<cw$}", + "License", + COL2_HEADER, + lw = license_width, + cw = count_width, ); - console_writeln!(console, &format!(" {} {}", border_col1, border_col2),); + console_writeln!(console, " {} {}", border_col1, border_col2); for (license, count) in &counts { console_writeln!( console, - &format!( - " {:<lw$} {:<cw$}", - license, - count, - lw = license_width, - cw = count_width - ), + " {:<lw$} {:<cw$}", + license, + count, + lw = license_width, + cw = count_width, ); } - console_writeln!(console, &format!(" {} {}", border_col1, border_col2),); + console_writeln!(console, " {} {}", border_col1, border_col2); } /// Mirror of `LicensesCommand::execute`'s `summary` accumulator. diff --git a/crates/mozart/src/commands/remove.rs b/crates/mozart/src/commands/remove.rs index f2a841c..d4d727f 100644 --- a/crates/mozart/src/commands/remove.rs +++ b/crates/mozart/src/commands/remove.rs @@ -152,10 +152,7 @@ pub async fn execute( if args.dev { if composer.require_dev.contains_key(&name) { - console_writeln!( - console, - &console_format!("<info>Removing {name} from require-dev</info>"), - ); + console_writeln!(console, "<info>Removing {name} from require-dev</info>"); 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!("<info>Removing {name} from require</info>"), - ); + console_writeln!(console, "<info>Removing {name} from require</info>"); composer.require.remove(&name); packages_removed.push(name); } else if composer.require_dev.contains_key(&name) { - console_writeln!( - console, - &console_format!("<info>Removing {name} from require-dev</info>"), - ); + console_writeln!(console, "<info>Removing {name} from require-dev</info>"); 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!( - "<comment>Not updating dependencies, only modifying composer.json.</comment>" - ), + "<comment>Not updating dependencies, only modifying composer.json.</comment>" ); 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!( - "<info>Using version constraint for {name} from Packagist...</info>" - ), + "<info>Using version constraint for {name} from Packagist...</info>" ); let best = version_selector @@ -970,7 +968,7 @@ pub async fn execute( console_writeln!( console, - &console_format!("<info>Using version {constraint} for {name}</info>"), + "<info>Using version {constraint} for {name}</info>", ); (name, constraint) @@ -1031,15 +1029,12 @@ pub async fn execute( if let Some(existing) = target.get(name) { console_writeln!( console, - &console_format!( - "<comment>Updating {name} from {existing} to {constraint} \ - in {section_name}</comment>" - ), + "<comment>Updating {name} from {existing} to {constraint} in {section_name}</comment>", ); } else { console_writeln!( console, - &console_format!("<info>Adding {name} ({constraint}) to {section_name}</info>"), + "<info>Adding {name} ({constraint}) to {section_name}</info>", ); } @@ -1067,7 +1062,7 @@ pub async fn execute( if args.dry_run { console_writeln!( console, - &console_format!("<comment>Dry run: composer.json not modified.</comment>"), + "<comment>Dry run: composer.json not modified.</comment>", ); } else { update_file(&composer_path, &raw)?; @@ -1085,9 +1080,7 @@ pub async fn execute( if args.no_update { console_writeln!( console, - &console_format!( - "<comment>Not updating dependencies, only modifying composer.json.</comment>" - ), + "<comment>Not updating dependencies, only modifying composer.json.</comment>" ); 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!("<info>scripts:</info>"), - ); + console_writeln_error!(console, "<info>scripts:</info>"); 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!(" {:<w$}", name, w = name_width - 2); - console_writeln!(console, &format!("{} {}", padded, desc)); + console_writeln!(console, "{} {}", padded, desc); } Ok(()) } diff --git a/crates/mozart/src/commands/search.rs b/crates/mozart/src/commands/search.rs index 4d8641f..14d50dd 100644 --- a/crates/mozart/src/commands/search.rs +++ b/crates/mozart/src/commands/search.rs @@ -139,7 +139,7 @@ fn render_json(results: &[SearchResult], console: &Console) -> 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!( - "<info>You are already using the latest available Mozart version {current_version} ({channel} channel).</info>" - ), + "<info>You are already using the latest available Mozart version {current_version} ({channel} channel).</info>" ); 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!("<comment>Old backups removed.</comment>"), - ); + console_writeln!(console, "<comment>Old backups removed.</comment>"); } return Ok(()); @@ -349,9 +343,7 @@ async fn update( console_writeln!( console, - &console_format!( - "<info>Mozart updated successfully from {current_version} to {target_version}</info>" - ), + "<info>Mozart updated successfully from {current_version} to {target_version}</info>" ); 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!("<comment>Old backups removed.</comment>"), - ); + console_writeln!(console, "<comment>Old backups removed.</comment>"); } Ok(()) @@ -393,7 +382,7 @@ fn rollback( console_writeln!( console, - &console_format!("<info>Rollback successful. Restored version {backup_version}</info>"), + "<info>Rollback successful. Restored version {backup_version}</info>", ); 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!( - "<warning>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.</warning>" - ), + "<warning>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.</warning>", ); } @@ -173,9 +171,7 @@ pub async fn execute( if !args.ignore.is_empty() && !args.outdated { console_writeln_error!( console, - &console_format!( - "<warning>You are using the option \"ignore\" for action other than \"outdated\", it will be ignored.</warning>" - ), + "<warning>You are using the option \"ignore\" for action other than \"outdated\", it will be ignored.</warning>", ); } @@ -571,7 +567,7 @@ fn render_package_list( console_writeln!( console, - &console_format!("<info>Direct dependencies required in composer.json:</info>"), + "<info>Direct dependencies required in composer.json:</info>", ); 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!("<info>Transitive dependencies not required in composer.json:</info>"), + "<info>Transitive dependencies not required in composer.json:</info>", ); 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!("<warning>{}</warning>", msg),); + console_writeln_error!(console, "<warning>{}</warning>", 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!("<info>Color legend:</info>"),); + console_writeln!(console, "<info>Color legend:</info>"); console_writeln!( console, - &format!( - "- {} release available - update recommended", - console_format!("<highlight>patch or minor</highlight>") - ), + "- {} release available - update recommended", + console_format!("<highlight>patch or minor</highlight>"), ); console_writeln!( console, - &format!( - "- {} release available - update possible", - console_format!("<comment>major</comment>") - ), + "- {} release available - update possible", + console_format!("<comment>major</comment>"), ); console_writeln!( console, - &format!("- {} version", console_format!("<info>up to date</info>")), + "- {} version", + console_format!("<info>up to date</info>"), ); } 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!("<info>name</info>"), detail.name), + "{} : {}", + console_format!("<info>name</info>"), + detail.name, ); console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>descrip.</info>"), - detail.description - ), + "{} : {}", + console_format!("<info>descrip.</info>"), + detail.description, ); console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>keywords</info>"), - detail.keywords.join(", ") - ), + "{} : {}", + console_format!("<info>keywords</info>"), + detail.keywords.join(", "), ); console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>versions</info>"), - format_version_highlight(&detail.version) - ), + "{} : {}", + console_format!("<info>versions</info>"), + format_version_highlight(&detail.version), ); // A13: released if let Some(ref date) = detail.release_date { console_writeln!( console, - &format!("{} : {}", console_format!("<info>released</info>"), date), + "{} : {}", + console_format!("<info>released</info>"), + date, ); } @@ -1000,43 +994,35 @@ async fn print_package_detail( }; console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>latest</info>"), - latest_str - ), + "{} : {}", + console_format!("<info>latest</info>"), + latest_str, ); } } console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>type</info>"), - detail.package_type.as_deref().unwrap_or("library") - ), + "{} : {}", + console_format!("<info>type</info>"), + detail.package_type.as_deref().unwrap_or("library"), ); for license_id in &detail.licenses { console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>license</info>"), - format_license_for_show(license_id), - ), + "{} : {}", + console_format!("<info>license</info>"), + format_license_for_show(license_id), ); } if let Some(ref homepage) = detail.homepage { console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>homepage</info>"), - homepage - ), + "{} : {}", + console_format!("<info>homepage</info>"), + 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!("<info>source</info>"), - src_type, - console_format!("<comment>{}</comment>", src_url), - src_ref - ), + "{} : [{}] {} {}", + console_format!("<info>source</info>"), + src_type, + console_format!("<comment>{}</comment>", 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!("<info>dist</info>"), - dist_type, - console_format!("<comment>{}</comment>", dist_url), - dist_ref - ), + "{} : [{}] {} {}", + console_format!("<info>dist</info>"), + dist_type, + console_format!("<comment>{}</comment>", dist_url), + dist_ref, ); } if let Some(ref path) = detail.install_path { console_writeln!( console, - &format!("{} : {}", console_format!("<info>path</info>"), path), + "{} : {}", + console_format!("<info>path</info>"), + path, ); } @@ -1081,11 +1065,9 @@ async fn print_package_detail( if detail.names.len() > 1 { console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>names</info>"), - detail.names.join(", ") - ), + "{} : {}", + console_format!("<info>names</info>"), + detail.names.join(", "), ); } @@ -1095,12 +1077,14 @@ async fn print_package_detail( && !obj.is_empty() { console_writeln!(console, ""); - console_writeln!(console, &console_format!("<info>support</info>"),); + console_writeln!(console, "<info>support</info>"); for (key, val) in obj { let v = val.as_str().unwrap_or(""); console_writeln!( console, - &format!("{} {}", key, console_format!("<comment>{}</comment>", v)), + "{} {}", + key, + console_format!("<comment>{}</comment>", 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!("<info>autoload</info>"),); + console_writeln!(console, "<info>autoload</info>"); 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!("<comment>{}</comment>", v_str) - ), + "{}: {} => {}", + loader_type, + k, + console_format!("<comment>{}</comment>", 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!("<comment>{}</comment>", v_str) - ), + "{}: {}", + loader_type, + console_format!("<comment>{}</comment>", v_str), ); } } @@ -1166,15 +1146,13 @@ fn print_links_section( return; } console_writeln!(console, ""); - console_writeln!(console, &console_format!("<info>{}</info>", label),); + console_writeln!(console, "<info>{}</info>", label); for (name, constraint) in links { console_writeln!( console, - &format!( - "{} {}", - name, - console_format!("<comment>{}</comment>", constraint) - ), + "{} {}", + name, + console_format!("<comment>{}</comment>", 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!( - "<warning>No dependencies installed. Try running mozart install or update.</warning>" - ), + "<warning>No dependencies installed. Try running mozart install or update.</warning>", ); } } @@ -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!("<warning>--path is not supported with --locked</warning>"), + "<warning>--path is not supported with --locked</warning>", ); 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!("<info>name</info>"), root.name), + "{} : {}", + console_format!("<info>name</info>"), + root.name, ); console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>descrip.</info>"), - root.description.as_deref().unwrap_or("") - ), + "{} : {}", + console_format!("<info>descrip.</info>"), + root.description.as_deref().unwrap_or(""), ); console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>type</info>"), - root.package_type.as_deref().unwrap_or("project") - ), + "{} : {}", + console_format!("<info>type</info>"), + root.package_type.as_deref().unwrap_or("project"), ); if let Some(ref license) = root.license { console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>license</info>"), - format_license_for_show(license), - ), + "{} : {}", + console_format!("<info>license</info>"), + format_license_for_show(license), ); } if let Some(ref homepage) = root.homepage { console_writeln!( console, - &format!( - "{} : {}", - console_format!("<info>homepage</info>"), - homepage - ), + "{} : {}", + console_format!("<info>homepage</info>"), + homepage, ); } // Requires if !root.require.is_empty() { console_writeln!(console, ""); - console_writeln!(console, &console_format!("<info>requires</info>"),); + console_writeln!(console, "<info>requires</info>"); for (name, constraint) in &root.require { console_writeln!( console, - &format!( - "{} {}", - name, - console_format!("<comment>{}</comment>", constraint) - ), + "{} {}", + name, + console_format!("<comment>{}</comment>", constraint), ); } } @@ -1578,15 +1546,13 @@ fn show_self( // Requires (dev) if !root.require_dev.is_empty() { console_writeln!(console, ""); - console_writeln!(console, &console_format!("<info>requires (dev)</info>"),); + console_writeln!(console, "<info>requires (dev)</info>"); for (name, constraint) in &root.require_dev { console_writeln!( console, - &format!( - "{} {}", - name, - console_format!("<comment>{}</comment>", constraint) - ), + "{} {}", + name, + console_format!("<comment>{}</comment>", constraint), ); } } @@ -1643,11 +1609,9 @@ fn show_tree( console_writeln!( console, - &console_format!( - "<info>{}</info> <comment>{}</comment>", - &root.name, - root.description.as_deref().unwrap_or("") - ), + "<info>{}</info> <comment>{}</comment>", + &root.name, + root.description.as_deref().unwrap_or(""), ); let mut visited_global: IndexSet<String> = IndexSet::new(); @@ -1693,19 +1657,19 @@ fn print_tree_node( console_writeln!( console, - &format!( - "{} {} {}", - prefix, - console_format!("<info>{}</info> <comment>{}</comment>", pkg_name, &version), - description - ), + "{} {} {}", + prefix, + console_format!("<info>{}</info> <comment>{}</comment>", 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!("<comment>{}</comment>", pkg_name), - constraint - ), + "{} {} {} (not installed)", + prefix, + console_format!("<comment>{}</comment>", 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!("<info>{:<width$}</info>", name, width = name_width), - console_format!( - "<comment>{:<width$}</comment>", - version, - width = version_width - ), + "{} {}", + console_format!("<info>{:<width$}</info>", name, width = name_width), + console_format!( + "<comment>{:<width$}</comment>", + 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!( - "<info>Available versions for locked packages (from Packagist):</info>" - ), + "<info>Available versions for locked packages (from Packagist):</info>", ); console_writeln!(console, ""); @@ -1927,9 +1886,7 @@ async fn show_available( console_writeln_error!( console, - &console_format!( - "<warning>No dependencies installed. Try running mozart install or update.</warning>" - ), + "<warning>No dependencies installed. Try running mozart install or update.</warning>", ); return Ok(()); } @@ -1937,9 +1894,7 @@ async fn show_available( console_writeln!( console, - &console_format!( - "<info>Available versions for installed packages (from Packagist):</info>" - ), + "<info>Available versions for installed packages (from Packagist):</info>", ); 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!("<info>Available versions for {pkg_name}:</info>"), - ); + console_writeln!(console, "<info>Available versions for {pkg_name}:</info>"); for v in &versions { console_writeln!( console, - &format!(" {}", console_format!("<comment>{}</comment>", &v.version)), + " {}", + console_format!("<comment>{}</comment>", &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!("<info>{}</info>", pkg_name) - ), + "{}: no versions found", + console_format!("<info>{}</info>", pkg_name), ); return; } @@ -2050,21 +2001,17 @@ async fn show_available_versions_inline( }; console_writeln!( console, - &format!( - "{}: {}{}", - console_format!("<info>{}</info>", pkg_name), - console_format!("<comment>{}</comment>", &shown.join(", ")), - rest - ), + "{}: {}{}", + console_format!("<info>{}</info>", pkg_name), + console_format!("<comment>{}</comment>", &shown.join(", ")), + rest, ); } Err(_) => { console_writeln!( console, - &format!( - "{}: (could not fetch from Packagist)", - console_format!("<comment>{}</comment>", pkg_name) - ), + "{}: (could not fetch from Packagist)", + console_format!("<comment>{}</comment>", 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!("<info>No local changes</info>")); + console_writeln_error!(console, "<info>No local changes</info>"); return Ok(()); } @@ -110,14 +109,14 @@ pub async fn execute( if !errors.is_empty() { console_writeln_error!( console, - &console_format!("<error>You have changes in the following dependencies:</error>") + "<error>You have changes in the following dependencies:</error>" ); for (path, changes) in &errors { if verbose { - console_writeln!(console, &console_format!("<info>{path}</info>:")); - console_writeln!(console, &indent_block(changes)); + console_writeln!(console, "<info>{path}</info>:"); + 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!( - "<warning>You have unpushed changes on the current branch in the following dependencies:</warning>" - ) + "<warning>You have unpushed changes on the current branch in the following dependencies:</warning>" ); for (path, changes) in &unpushed_changes { if verbose { - console_writeln!(console, &console_format!("<info>{path}</info>:")); - console_writeln!(console, &indent_block(changes)); + console_writeln!(console, "<info>{path}</info>:"); + 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!( - "<warning>You have version variations in the following dependencies:</warning>" - ) + "<warning>You have version variations in the following dependencies:</warning>" ); 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!("<info>{path}</info>:")); + console_writeln!(console, "<info>{path}</info>:"); console_writeln!( console, - &console_format!( - " From <comment>{prev}</comment> to <comment>{curr}</comment>" - ) + " From <comment>{prev}</comment> to <comment>{curr}</comment>" ); } 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!("<info>{name} is valid but your composer.lock has some {kind}</info>"), + "<info>{name} is valid but your composer.lock has some {kind}</info>", ); } else { - console_writeln!(console, &console_format!("<info>{name} is valid</info>"),); + console_writeln!(console, "<info>{name} i valid</info>"); } // Collect error and warning message lines |
