diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-12 03:19:34 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-12 03:19:34 +0900 |
| commit | efe5bdb1987411a473d4af15451a376d20928245 (patch) | |
| tree | 54d3c9e7ab92cfc7d7ec3d90ca3f29e828d929c4 /crates/shirabe | |
| parent | 981cae63d9777b877aa9f96907c7995ec020fbf9 (diff) | |
| download | php-shirabe-efe5bdb1987411a473d4af15451a376d20928245.tar.gz php-shirabe-efe5bdb1987411a473d4af15451a376d20928245.tar.zst php-shirabe-efe5bdb1987411a473d4af15451a376d20928245.zip | |
refactor(php-shim): replace literal sprintf calls with format!
Convert every sprintf() call with a compile-time literal format string to
format!, implementing Display for PhpMixed (delegating to php_to_string) so
PhpMixed values render with PHP string semantics through {}. Also merge the
format!-wrapped and conditional-literal dynamic sites into single format!
calls. Genuinely runtime format strings (table styles, configurable error
messages, command synopsis, progress-bar modifiers, regex-built messages)
still go through sprintf.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe')
28 files changed, 495 insertions, 625 deletions
diff --git a/crates/shirabe/src/advisory/auditor.rs b/crates/shirabe/src/advisory/auditor.rs index c12e131..c7558f4 100644 --- a/crates/shirabe/src/advisory/auditor.rs +++ b/crates/shirabe/src/advisory/auditor.rs @@ -551,16 +551,14 @@ impl Auditor { packages: &[CompletePackageInterfaceHandle], format: &str, ) -> Result<()> { - io.write_error(&sprintf( - "<error>Found %d abandoned package%s:</error>", - &[ - PhpMixed::Int(packages.len() as i64), - PhpMixed::String(if packages.len() > 1 { - "s".to_string() - } else { - String::new() - }), - ], + io.write_error(&format!( + "<error>Found {} abandoned package{}:</error>", + PhpMixed::Int(packages.len() as i64), + PhpMixed::String(if packages.len() > 1 { + "s".to_string() + } else { + String::new() + }), )); if format == Self::FORMAT_PLAIN { @@ -570,12 +568,10 @@ impl Auditor { } else { "No replacement was suggested".to_string() }; - io.write_error(&sprintf( - "%s is abandoned. %s.", - &[ - PhpMixed::String(self.get_package_name_with_link(pkg.clone().into())), - PhpMixed::String(replacement), - ], + io.write_error(&format!( + "{} is abandoned. {}.", + PhpMixed::String(self.get_package_name_with_link(pkg.clone().into())), + PhpMixed::String(replacement), )); } diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs index 7167f04..e8883ab 100644 --- a/crates/shirabe/src/autoload/autoload_generator.rs +++ b/crates/shirabe/src/autoload/autoload_generator.rs @@ -1597,9 +1597,10 @@ impl AutoloadGenerator { ); let value = Preg::replace("/ +$/m", "", &value).unwrap_or_default(); - file.push_str(&sprintf( - " public static $%s = %s;\n\n", - &[prop.clone().into(), value.clone().into()], + file.push_str(&format!( + " public static ${} = {};\n\n", + prop.clone(), + value.clone(), )); if "files" != prop.as_str() { initializer.push_str(&format!( diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs index 342797c..2bcb681 100644 --- a/crates/shirabe/src/command/config_command.rs +++ b/crates/shirabe/src/command/config_command.rs @@ -649,7 +649,7 @@ impl ConfigCommand { if !boolean_validator(&PhpMixed::String(values[0].clone())) { return Err(RuntimeException { - message: sprintf("\"%s\" is an invalid value", &[values[0].clone().into()]), + message: format!("\"{}\" is an invalid value", values[0].clone()), code: 0, } .into()); @@ -1169,10 +1169,7 @@ impl ConfigCommand { String::new() }; return Err(RuntimeException { - message: sprintf( - &format!("\"%s\" is an invalid value{}", suffix), - &[values[0].clone().into()], - ), + message: format!("\"{}\" is an invalid value{}", values[0].clone(), suffix), code: 0, } .into()); @@ -1239,9 +1236,10 @@ impl ConfigCommand { String::new() }; return Err(RuntimeException { - message: sprintf( - &format!("%s is an invalid value{}", suffix), - &[json_encode(&values_mixed).into()], + message: format!( + "{} is an invalid value{}", + PhpMixed::from(json_encode(&values_mixed)), + suffix ), code: 0, } diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index 2d6d1eb..aa75ad7 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -386,9 +386,9 @@ impl DiagnoseCommand { let limit = arr.get("limit").and_then(|v| v.as_int()).unwrap_or(0); if 10 > remaining { io.write("<warning>WARNING</warning>"); - io.write(&sprintf( - "<comment>GitHub has a rate limit on their API. You currently have <options=bold>%u</options=bold> out of <options=bold>%u</options=bold> requests left.\nSee https://developer.github.com/v3/#rate-limiting and also\n https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens</comment>", - &[remaining.into(), limit.into()], + io.write(&format!( + "<comment>GitHub has a rate limit on their API. You currently have <options=bold>{}</options=bold> out of <options=bold>{}</options=bold> requests left.\nSee https://developer.github.com/v3/#rate-limiting and also\n https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens</comment>", + remaining, limit, )); } else { self.output_result(PhpMixed::Bool(true)); @@ -1288,9 +1288,9 @@ impl DiagnoseCommand { ), other => { return Err(InvalidArgumentException { - message: sprintf( - "DiagnoseCommand: Unknown error type \"%s\". Please report at https://github.com/composer/composer/issues/new.", - &[other.to_string().into()], + message: format!( + "DiagnoseCommand: Unknown error type \"{}\". Please report at https://github.com/composer/composer/issues/new.", + other.to_string(), ), code: 0, } @@ -1367,9 +1367,9 @@ impl DiagnoseCommand { ), other => { return Err(InvalidArgumentException { - message: sprintf( - "DiagnoseCommand: Unknown warning type \"%s\". Please report at https://github.com/composer/composer/issues/new.", - &[other.to_string().into()], + message: format!( + "DiagnoseCommand: Unknown warning type \"{}\". Please report at https://github.com/composer/composer/issues/new.", + other.to_string(), ), code: 0, } diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index aea9faf..205494c 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -906,9 +906,9 @@ impl InitCommand { if !Preg::is_match(r"{^[^/][A-Za-z0-9\-_/]+/$}", &value_or_default).unwrap_or(false) { return Err(InvalidArgumentException { - message: sprintf( - "The src folder name \"%s\" is invalid. Please add a relative path with tailing forward slash. [A-Za-z0-9_-/]+/", - &[PhpMixed::String(value_or_default.clone())], + message: format!( + "The src folder name \"{}\" is invalid. Please add a relative path with tailing forward slash. [A-Za-z0-9_-/]+/", + PhpMixed::String(value_or_default.clone()), ), code: 0, } @@ -1057,9 +1057,9 @@ impl InitCommand { return false; } - let pattern = sprintf( - "{^/?%s(/\\*?)?$}", - &[PhpMixed::String(preg_quote(vendor, None))], + let pattern = format!( + "{{^/?{}(/\\*?)?$}}", + PhpMixed::String(preg_quote(vendor, None)), ); let lines = file(ignore_file, FILE_IGNORE_NEW_LINES).unwrap_or_default(); @@ -1240,9 +1240,10 @@ impl InitCommand { } if let (Some(name), Some(email)) = (author_name, author_email) { - return Some(sprintf( - "%s <%s>", - &[PhpMixed::String(name), PhpMixed::String(email)], + return Some(format!( + "{} <{}>", + PhpMixed::String(name), + PhpMixed::String(email), )); } diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs index aa12719..2fe856c 100644 --- a/crates/shirabe/src/command/package_discovery_trait.rs +++ b/crates/shirabe/src/command/package_discovery_trait.rs @@ -206,14 +206,12 @@ pub trait PackageDiscoveryTrait { if use_best_version_constraint { requirement.insert("version".to_string(), version.clone()); io.write_error3( - &sprintf( - "Using version <info>%s</info> for <info>%s</info>", - &[ - PhpMixed::String(version), - PhpMixed::String( - requirement.get("name").cloned().unwrap_or_default(), - ), - ], + &format!( + "Using version <info>{}</info> for <info>{}</info>", + PhpMixed::String(version), + PhpMixed::String( + requirement.get("name").cloned().unwrap_or_default(), + ), ), true, io_interface::NORMAL, @@ -323,36 +321,32 @@ pub trait PackageDiscoveryTrait { if let Some(ai) = &found_package.abandoned { let replacement = match ai { crate::repository::AbandonedInfo::Replacement(r) => { - sprintf("Use %s instead", &[PhpMixed::String(r.clone())]) + format!("Use {} instead", PhpMixed::String(r.clone())) } crate::repository::AbandonedInfo::Abandoned => { "No replacement was suggested".to_string() } }; - abandoned = sprintf( - "<warning>Abandoned. %s.</warning>", - &[PhpMixed::String(replacement)], + abandoned = format!( + "<warning>Abandoned. {}.</warning>", + PhpMixed::String(replacement), ); } - choices.push(sprintf( - " <info>%5s</info> %s %s", - &[ - PhpMixed::String(format!("[{}]", position)), - PhpMixed::String(found_package.name.clone()), - PhpMixed::String(abandoned), - ], + choices.push(format!( + " <info>{:>5}</info> {} {}", + PhpMixed::String(format!("[{}]", position)), + PhpMixed::String(found_package.name.clone()), + PhpMixed::String(abandoned), )); } io.write_error3("", true, io_interface::NORMAL); io.write_error3( - &sprintf( - "Found <info>%s</info> packages matching <info>%s</info>", - &[ - PhpMixed::Int(matches.len() as i64), - PhpMixed::String(package.clone()), - ], + &format!( + "Found <info>{}</info> packages matching <info>{}</info>", + PhpMixed::Int(matches.len() as i64), + PhpMixed::String(package.clone()), ), true, io_interface::NORMAL, @@ -464,12 +458,10 @@ pub trait PackageDiscoveryTrait { )?; io.write_error3( - &sprintf( - "Using version <info>%s</info> for <info>%s</info>", - &[ - PhpMixed::String(c.clone()), - PhpMixed::String(package.clone()), - ], + &format!( + "Using version <info>{}</info> for <info>{}</info>", + PhpMixed::String(c.clone()), + PhpMixed::String(package.clone()), ), true, io_interface::NORMAL, @@ -600,15 +592,13 @@ pub trait PackageDiscoveryTrait { )?; if let Some(candidate) = candidate { return Err(InvalidArgumentException { - message: sprintf( - &format!( - "Package %s has requirements incompatible with your PHP version, PHP extensions and Composer version{}", - self.get_platform_exception_details( - candidate.clone(), - platform_repo, - )?, - ), - &[PhpMixed::String(name.to_string())], + message: format!( + "Package {} has requirements incompatible with your PHP version, PHP extensions and Composer version{}", + PhpMixed::String(name.to_string()), + self.get_platform_exception_details( + candidate.clone(), + platform_repo, + )?, ), code: 0, } @@ -656,12 +646,10 @@ pub trait PackageDiscoveryTrait { } return Err(InvalidArgumentException { - message: sprintf( - "Could not find a version of package %s matching your minimum-stability (%s). Require it with an explicit version constraint allowing its desired stability.", - &[ - PhpMixed::String(name.to_string()), - PhpMixed::String(effective_minimum_stability.clone()), - ], + message: format!( + "Could not find a version of package {} matching your minimum-stability ({}). Require it with an explicit version constraint allowing its desired stability.", + PhpMixed::String(name.to_string()), + PhpMixed::String(effective_minimum_stability.clone()), ), code: 0, } @@ -700,18 +688,14 @@ pub trait PackageDiscoveryTrait { } return Err(InvalidArgumentException { - message: sprintf( - &format!( - "Could not find package %s in any version matching your PHP version, PHP extensions and Composer version{}%s", - self.get_platform_exception_details( - candidate.clone(), - platform_repo, - )?, - ), - &[ - PhpMixed::String(name.to_string()), - PhpMixed::String(additional), - ], + message: format!( + "Could not find package {} in any version matching your PHP version, PHP extensions and Composer version{}{}", + PhpMixed::String(name.to_string()), + self.get_platform_exception_details( + candidate.clone(), + platform_repo, + )?, + PhpMixed::String(additional), ), code: 0, } @@ -736,9 +720,9 @@ pub trait PackageDiscoveryTrait { true, ) { return Err(InvalidArgumentException { - message: sprintf( - "Could not find package %s. It was however found via repository search, which indicates a consistency issue with the repository.", - &[PhpMixed::String(name.to_string())], + message: format!( + "Could not find package {}. It was however found via repository search, which indicates a consistency issue with the repository.", + PhpMixed::String(name.to_string()), ), code: 0, } @@ -774,19 +758,15 @@ pub trait PackageDiscoveryTrait { } return Err(InvalidArgumentException { - message: sprintf( - &format!( - "Could not find package %s.\n\nDid you mean {}?\n %s", - if similar.len() > 1 { - "one of these" - } else { - "this" - }, - ), - &[ - PhpMixed::String(name.to_string()), - PhpMixed::String(implode("\n ", &similar)), - ], + message: format!( + "Could not find package {}.\n\nDid you mean {}?\n {}", + PhpMixed::String(name.to_string()), + if similar.len() > 1 { + "one of these" + } else { + "this" + }, + PhpMixed::String(implode("\n ", &similar)), ), code: 0, } @@ -794,12 +774,10 @@ pub trait PackageDiscoveryTrait { } return Err(InvalidArgumentException { - message: sprintf( - "Could not find a matching version of package %s. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (%s).", - &[ - PhpMixed::String(name.to_string()), - PhpMixed::String(effective_minimum_stability), - ], + message: format!( + "Could not find a matching version of package {}. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability ({}).", + PhpMixed::String(name.to_string()), + PhpMixed::String(effective_minimum_stability), ), code: 0, } diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs index dd91524..9e47a02 100644 --- a/crates/shirabe/src/command/require_command.rs +++ b/crates/shirabe/src/command/require_command.rs @@ -446,9 +446,9 @@ impl RequireCommand { let version_parser = VersionParser::new(); for (package, constraint) in &requirements { if strtolower(package) == composer.get_package().get_name() { - let msg = sprintf( - "<error>Root package '%s' cannot require itself in its composer.json</error>", - &[PhpMixed::String(package.clone())], + let msg = format!( + "<error>Root package '{}' cannot require itself in its composer.json</error>", + PhpMixed::String(package.clone()), ); self.get_io().write_error3(&msg, true, io_interface::NORMAL); @@ -464,48 +464,46 @@ impl RequireCommand { self.get_inconsistent_require_keys(&requirements, require_key); if (inconsistent_require_keys.len() as i64) > 0 { for package in &inconsistent_require_keys { - let warn_msg = sprintf( - "%s is currently present in the %s key and you ran the command %s the --dev flag, which will move it to the %s key.", - &[ - PhpMixed::String(package.clone()), - PhpMixed::String(remove_key.to_string()), - PhpMixed::String( - if input.borrow().get_option("dev")?.as_bool().unwrap_or(false) { - "with" - } else { - "without" - } - .to_string(), - ), - PhpMixed::String(require_key.to_string()), - ], + let warn_msg = format!( + "{} is currently present in the {} key and you ran the command {} the --dev flag, which will move it to the {} key.", + PhpMixed::String(package.clone()), + PhpMixed::String(remove_key.to_string()), + PhpMixed::String( + if input.borrow().get_option("dev")?.as_bool().unwrap_or(false) { + "with" + } else { + "without" + } + .to_string(), + ), + PhpMixed::String(require_key.to_string()), ); self.get_io().warning(&warn_msg, &[]); } if self.get_io().is_interactive() { - let q1 = sprintf( - "<info>Do you want to move %s?</info> [<comment>no</comment>]? ", - &[PhpMixed::String( + let q1 = format!( + "<info>Do you want to move {}?</info> [<comment>no</comment>]? ", + PhpMixed::String( if (inconsistent_require_keys.len() as i64) > 1 { "these requirements" } else { "this requirement" } .to_string(), - )], + ), ); if !self.get_io().ask_confirmation(q1, false) { - let q2 = sprintf( - "<info>Do you want to re-run the command %s --dev?</info> [<comment>yes</comment>]? ", - &[PhpMixed::String( + let q2 = format!( + "<info>Do you want to re-run the command {} --dev?</info> [<comment>yes</comment>]? ", + PhpMixed::String( if input.borrow().get_option("dev")?.as_bool().unwrap_or(false) { "without" } else { "with" } .to_string(), - )], + ), ); if !self.get_io().ask_confirmation(q2, true) { return Ok(0); @@ -1086,14 +1084,10 @@ impl RequireCommand { ); } self.get_io().write_error3( - &sprintf( - "Using version <info>%s</info> for <info>%s</info>", - &[ - PhpMixed::String( - requirements.get(package_name).cloned().unwrap_or_default(), - ), - PhpMixed::String(package_name.clone()), - ], + &format!( + "Using version <info>{}</info> for <info>{}</info>", + PhpMixed::String(requirements.get(package_name).cloned().unwrap_or_default(),), + PhpMixed::String(package_name.clone()), ), true, io_interface::NORMAL, diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs index 60d2eac..6f604d5 100644 --- a/crates/shirabe/src/command/update_command.rs +++ b/crates/shirabe/src/command/update_command.rs @@ -660,11 +660,11 @@ impl UpdateCommand { table.render(); if io.ask_confirmation( - sprintf( - "Would you like to continue and update the above package%s [<comment>yes</comment>]? ", - &[PhpMixed::String( + format!( + "Would you like to continue and update the above package{} [<comment>yes</comment>]? ", + PhpMixed::String( if 1 == packages.len() { "" } else { "s" }.to_string(), - )], + ), ), true, ) { diff --git a/crates/shirabe/src/config/json_config_source.rs b/crates/shirabe/src/config/json_config_source.rs index a83c386..8580135 100644 --- a/crates/shirabe/src/config/json_config_source.rs +++ b/crates/shirabe/src/config/json_config_source.rs @@ -35,9 +35,9 @@ impl JsonConfigSource { if self.file.borrow().exists() { if !is_writable(self.file.borrow().get_path()) { return Err(RuntimeException { - message: sprintf( - "The file \"%s\" is not writable.", - &[PhpMixed::String(self.file.borrow().get_path().to_string())], + message: format!( + "The file \"{}\" is not writable.", + PhpMixed::String(self.file.borrow().get_path().to_string()), ), code: 0, } @@ -46,9 +46,9 @@ impl JsonConfigSource { if !Filesystem::is_readable(self.file.borrow().get_path()) { return Err(RuntimeException { - message: sprintf( - "The file \"%s\" is not readable.", - &[PhpMixed::String(self.file.borrow().get_path().to_string())], + message: format!( + "The file \"{}\" is not readable.", + PhpMixed::String(self.file.borrow().get_path().to_string()), ), code: 0, } @@ -456,9 +456,9 @@ impl ConfigSourceInterface for JsonConfigSource { } let Some(index_to_insert) = index_to_insert else { return Err(RuntimeException { - message: sprintf( - "The referenced repository \"%s\" does not exist.", - &[PhpMixed::String(reference_name.to_string())], + message: format!( + "The referenced repository \"{}\" does not exist.", + PhpMixed::String(reference_name.to_string()), ), code: 0, } diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index dcf30dc..810e283 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -524,24 +524,20 @@ impl Application { if !is_proxy_command { self.io.write_error3( - &sprintf( - "Running %s (%s) with %s on %s", - &[ - composer::get_version().into(), - composer::RELEASE_DATE.into(), - (if defined("HHVM_VERSION") { - format!("HHVM {}", shirabe_php_shim::HHVM_VERSION.unwrap_or("")) - } else { - format!("PHP {}", PHP_VERSION) - }) - .into(), - (if function_exists("php_uname") { - format!("{} / {}", php_uname("s"), php_uname("r")) - } else { - "Unknown OS".to_string() - }) - .into(), - ], + &format!( + "Running {} ({}) with {} on {}", + composer::get_version(), + composer::RELEASE_DATE, + (if defined("HHVM_VERSION") { + format!("HHVM {}", shirabe_php_shim::HHVM_VERSION.unwrap_or("")) + } else { + format!("PHP {}", PHP_VERSION) + }), + (if function_exists("php_uname") { + format!("{} / {}", php_uname("s"), php_uname("r")) + } else { + "Unknown OS".to_string() + }), ), true, io_interface::DEBUG, @@ -562,9 +558,9 @@ impl Application { && command_name.as_deref() != Some("selfupdate") && time() > shirabe_php_shim::composer_dev_warning_time() { - self.io.write_error(&sprintf( - "<warning>Warning: This development build of Composer is over 60 days old. It is recommended to update it by running \"%s self-update\" to get the latest version.</warning>", - &[shirabe_php_shim::server_get("PHP_SELF").unwrap_or_default().into()], + self.io.write_error(&format!( + "<warning>Warning: This development build of Composer is over 60 days old. It is recommended to update it by running \"{} self-update\" to get the latest version.</warning>", + shirabe_php_shim::server_get("PHP_SELF").unwrap_or_default(), )); } @@ -605,7 +601,7 @@ impl Application { && unlink(&tempfile) && !file_exists(&tempfile)) { - return Ok(Some(sprintf("<error>PHP temp directory (%s) does not exist or is not writable to Composer. Set sys_temp_dir in your php.ini</error>", &[sys_get_temp_dir().into()]))); + return Ok(Some(format!("<error>PHP temp directory ({}) does not exist or is not writable to Composer. Set sys_temp_dir in your php.ini</error>", sys_get_temp_dir()))); } Ok(None) }) @@ -778,9 +774,9 @@ impl Application { .borrow() .has_parameter_option(PhpMixed::from(vec!["--version", "-V"]), true) { - self.io.write_error(&sprintf( - "<info>PHP</info> version <comment>%s</comment> (%s)", - &[PHP_VERSION.into(), PHP_BINARY.into()], + self.io.write_error(&format!( + "<info>PHP</info> version <comment>{}</comment> ({})", + PHP_VERSION, PHP_BINARY, )); self.io.write_error( "Run the \"diagnose\" command to get more detailed diagnostics output.", @@ -1132,20 +1128,15 @@ impl Application { if !composer::BRANCH_ALIAS_VERSION.is_empty() && composer::BRANCH_ALIAS_VERSION != "@package_branch_alias_version@" { - branch_alias_string = sprintf( - " (%s)", - &[composer::BRANCH_ALIAS_VERSION.to_string().into()], - ); + branch_alias_string = format!(" ({})", composer::BRANCH_ALIAS_VERSION.to_string(),); } - sprintf( - "<info>%s</info> version <comment>%s%s</comment> %s", - &[ - self.inner.get_name().into(), - self.inner.get_version().into(), - branch_alias_string.into(), - composer::RELEASE_DATE.into(), - ], + format!( + "<info>{}</info> version <comment>{}{}</comment> {}", + self.inner.get_name(), + self.inner.get_version(), + branch_alias_string, + composer::RELEASE_DATE, ) } diff --git a/crates/shirabe/src/dependency_resolver/pool_builder.rs b/crates/shirabe/src/dependency_resolver/pool_builder.rs index b96dc79..a517488 100644 --- a/crates/shirabe/src/dependency_resolver/pool_builder.rs +++ b/crates/shirabe/src/dependency_resolver/pool_builder.rs @@ -1086,21 +1086,19 @@ impl PoolBuilder { } self.io.write3( - &sprintf( - "Pool optimizer completed in %.3f seconds", - &[(microtime(true) - before).into()], + &format!( + "Pool optimizer completed in {:.3} seconds", + (microtime(true) - before), ), true, io_interface::VERY_VERBOSE, ); self.io.write3( - &sprintf( - "<info>Found %s package versions referenced in your dependency graph. %s (%d%%) were optimized away.</info>", - &[ - number_format(total, 0, ".", ",").into(), - number_format(filtered, 0, ".", ",").into(), - round(100.0 / total * filtered, 0).into(), - ], + &format!( + "<info>Found {} package versions referenced in your dependency graph. {} ({}%) were optimized away.</info>", + number_format(total, 0, ".", ","), + number_format(filtered, 0, ".", ","), + round(100.0 / total * filtered, 0), ), true, io_interface::VERY_VERBOSE, @@ -1138,21 +1136,19 @@ impl PoolBuilder { } self.io.write3( - &sprintf( - "Security advisory pool filter completed in %.3f seconds", - &[(microtime(true) - before).into()], + &format!( + "Security advisory pool filter completed in {:.3} seconds", + (microtime(true) - before), ), true, io_interface::VERY_VERBOSE, ); self.io.write3( - &sprintf( - "<info>Found %s package versions referenced in your dependency graph. %s (%d%%) were filtered away.</info>", - &[ - number_format(total, 0, ".", ",").into(), - number_format(filtered, 0, ".", ",").into(), - round(100.0 / total * filtered, 0).into(), - ], + &format!( + "<info>Found {} package versions referenced in your dependency graph. {} ({}%) were filtered away.</info>", + number_format(total, 0, ".", ","), + number_format(filtered, 0, ".", ","), + round(100.0 / total * filtered, 0), ), true, io_interface::VERY_VERBOSE, diff --git a/crates/shirabe/src/dependency_resolver/solver.rs b/crates/shirabe/src/dependency_resolver/solver.rs index 03dd575..1278970 100644 --- a/crates/shirabe/src/dependency_resolver/solver.rs +++ b/crates/shirabe/src/dependency_resolver/solver.rs @@ -263,9 +263,9 @@ impl Solver { self.run_sat()?; self.io.write_error3("", true, crate::io::DEBUG); self.io.write_error3( - &sprintf( - "Dependency resolution completed in %.3f seconds", - &[PhpMixed::Float(microtime(true) - before)], + &format!( + "Dependency resolution completed in {:.3} seconds", + microtime(true) - before, ), true, crate::io::VERBOSE, diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs index af23353..209c6ee 100644 --- a/crates/shirabe/src/downloader/download_manager.rs +++ b/crates/shirabe/src/downloader/download_manager.rs @@ -110,12 +110,10 @@ impl DownloadManager { let r#type = strtolower(r#type); if !self.downloaders.contains_key(&r#type) { return Err(InvalidArgumentException { - message: sprintf( - "Unknown downloader type: %s. Available types: %s.", - &[ - PhpMixed::String(r#type), - PhpMixed::String(implode(", ", &array_keys(&self.downloaders))), - ], + message: format!( + "Unknown downloader type: {}. Available types: {}.", + PhpMixed::String(r#type), + PhpMixed::String(implode(", ", &array_keys(&self.downloaders))), ), code: 0, } @@ -159,14 +157,12 @@ impl DownloadManager { let downloader_installation_source = downloader.borrow().get_installation_source(); if installation_source.as_deref() != Some(&downloader_installation_source) { return Err(LogicException { - message: sprintf( - "Downloader \"%s\" is a %s type downloader and can not be used to download %s for package %s", - &[ - PhpMixed::String(shirabe_php_shim::get_class_obj(&*downloader.borrow())), - PhpMixed::String(downloader_installation_source), - PhpMixed::String(installation_source.clone().unwrap_or_default()), - PhpMixed::String(package.to_string()), - ], + message: format!( + "Downloader \"{}\" is a {} type downloader and can not be used to download {} for package {}", + PhpMixed::String(shirabe_php_shim::get_class_obj(&*downloader.borrow())), + PhpMixed::String(downloader_installation_source), + PhpMixed::String(installation_source.clone().unwrap_or_default()), + PhpMixed::String(package.to_string()), ), code: 0, } diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs index 47dd959..b7145b6 100644 --- a/crates/shirabe/src/downloader/git_downloader.rs +++ b/crates/shirabe/src/downloader/git_downloader.rs @@ -824,9 +824,9 @@ impl VcsDownloader for GitDownloader { io_interface::NORMAL, ); self.inner.io.write_error3( - &sprintf( - " Cloning to cache at %s", - &[PhpMixed::String(cache_path.clone())], + &format!( + " Cloning to cache at {}", + PhpMixed::String(cache_path.clone()), ), true, io_interface::DEBUG, diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs index d209e1e..c54df20 100644 --- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs +++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs @@ -347,12 +347,10 @@ impl EventDispatcher { "?".to_string() }; self.io.write_error3( - &sprintf( - "> %s: %s", - &[ - PhpMixed::String(formatted_event_name_with_args.clone()), - PhpMixed::String(format!("{}->{}", prefix, method_name)), - ], + &format!( + "> {}: {}", + PhpMixed::String(formatted_event_name_with_args.clone()), + PhpMixed::String(format!("{}->{}", prefix, method_name)), ), true, crate::io::VERBOSE, @@ -364,12 +362,10 @@ impl EventDispatcher { match callable { Callable::String(ref callable_str) if self.is_composer_script(callable_str) => { self.io.write_error3( - &sprintf( - "> %s: %s", - &[ - PhpMixed::String(formatted_event_name_with_args.clone()), - PhpMixed::String(callable_str.clone()), - ], + &format!( + "> {}: {}", + PhpMixed::String(formatted_event_name_with_args.clone()), + PhpMixed::String(callable_str.clone()), ), true, crate::io::VERBOSE, @@ -424,15 +420,11 @@ impl EventDispatcher { ); let exit_code = self.execute_tty(&exec)?; if exit_code != 0 { - self.io.write_error3(&sprintf( - &format!( - "<error>Script %s handling the %s event returned with error code {}</error>", - exit_code - ), - &[ - PhpMixed::String(callable_str.clone()), - PhpMixed::String(event.get_name().to_string()), - ], + self.io.write_error3(&format!( + "<error>Script {} handling the {} event returned with error code {}</error>", + PhpMixed::String(callable_str.clone()), + PhpMixed::String(event.get_name().to_string()), + exit_code ), true, crate::io::QUIET); return Err(anyhow::anyhow!(ScriptExecutionException( @@ -454,9 +446,9 @@ impl EventDispatcher { )) .is_empty() { - self.io.write_error3(&sprintf( - "<warning>You made a reference to a non-existent script %s</warning>", - &[PhpMixed::String(callable_str.clone())], + self.io.write_error3(&format!( + "<warning>You made a reference to a non-existent script {}</warning>", + PhpMixed::String(callable_str.clone()), ), true, crate::io::QUIET); } @@ -481,12 +473,10 @@ impl EventDispatcher { Err(e) => { if e.downcast_ref::<ScriptExecutionException>().is_some() { self.io.write_error3( - &sprintf( - "<error>Script %s was called via %s</error>", - &[ - PhpMixed::String(callable_str.clone()), - PhpMixed::String(event.get_name().to_string()), - ], + &format!( + "<error>Script {} was called via {}</error>", + PhpMixed::String(callable_str.clone()), + PhpMixed::String(event.get_name().to_string()), ), true, crate::io::QUIET, @@ -526,17 +516,13 @@ impl EventDispatcher { r#return = if let PhpMixed::Bool(false) = v { 1 } else { 0 }; } Err(e) => { - let message = - "Script %s handling the %s event terminated with an exception"; self.io.write_error3( &format!( "<error>{}</error>", - sprintf( - message, - &[ - PhpMixed::String(callable_str.clone()), - PhpMixed::String(event.get_name().to_string()), - ], + format!( + "Script {} handling the {} event terminated with an exception", + PhpMixed::String(callable_str.clone()), + PhpMixed::String(event.get_name().to_string()), ) ), true, @@ -630,17 +616,13 @@ impl EventDispatcher { match result { Ok(v) => r#return = v, Err(e) => { - let message = - "Script %s handling the %s event terminated with an exception"; self.io.write_error3( &format!( "<error>{}</error>", - sprintf( - message, - &[ - PhpMixed::String(callable_str.clone()), - PhpMixed::String(event.get_name().to_string()), - ], + format!( + "Script {} handling the {} event terminated with an exception", + PhpMixed::String(callable_str.clone()), + PhpMixed::String(event.get_name().to_string()), ) ), true, @@ -676,19 +658,17 @@ impl EventDispatcher { if self.io.is_verbose() { self.io.write_error3( - &sprintf( - "> %s: %s", - &[ - PhpMixed::String(event.get_name().to_string()), - PhpMixed::String(exec.clone()), - ], + &format!( + "> {}: {}", + PhpMixed::String(event.get_name().to_string()), + PhpMixed::String(exec.clone()), ), true, crate::io::NORMAL, ); } else if self.event_needs_to_output(event) { self.io.write_error3( - &sprintf("> %s", &[PhpMixed::String(exec.clone())]), + &format!("> {}", PhpMixed::String(exec.clone())), true, crate::io::NORMAL, ); @@ -815,15 +795,11 @@ impl EventDispatcher { let exit_code = self.execute_tty(&exec)?; if exit_code != 0 { - self.io.write_error3(&sprintf( - &format!( - "<error>Script %s handling the %s event returned with error code {}</error>", - exit_code - ), - &[ - PhpMixed::String(callable_str.clone()), - PhpMixed::String(event.get_name().to_string()), - ], + self.io.write_error3(&format!( + "<error>Script {} handling the {} event returned with error code {}</error>", + PhpMixed::String(callable_str.clone()), + PhpMixed::String(event.get_name().to_string()), + exit_code ), true, crate::io::QUIET); return Err(anyhow::anyhow!(ScriptExecutionException( @@ -921,25 +897,21 @@ impl EventDispatcher { ) -> anyhow::Result<PhpMixed> { if self.io.is_verbose() { self.io.write_error3( - &sprintf( - "> %s: %s::%s", - &[ - PhpMixed::String(event.get_name().to_string()), - PhpMixed::String(class_name.to_string()), - PhpMixed::String(method_name.to_string()), - ], + &format!( + "> {}: {}::{}", + PhpMixed::String(event.get_name().to_string()), + PhpMixed::String(class_name.to_string()), + PhpMixed::String(method_name.to_string()), ), true, crate::io::NORMAL, ); } else if self.event_needs_to_output(event) { self.io.write_error3( - &sprintf( - "> %s::%s", - &[ - PhpMixed::String(class_name.to_string()), - PhpMixed::String(method_name.to_string()), - ], + &format!( + "> {}::{}", + PhpMixed::String(class_name.to_string()), + PhpMixed::String(method_name.to_string()), ), true, crate::io::NORMAL, @@ -1111,9 +1083,9 @@ impl EventDispatcher { let event_name = event.get_name().to_string(); if self.event_stack.iter().any(|n| n == &event_name) { return Err(anyhow::anyhow!(RuntimeException { - message: sprintf( - "Circular call to script handler '%s' detected", - &[PhpMixed::String(event_name)], + message: format!( + "Circular call to script handler '{}' detected", + PhpMixed::String(event_name), ), code: 0, })); diff --git a/crates/shirabe/src/installer.rs b/crates/shirabe/src/installer.rs index 3c68b90..86c9714 100644 --- a/crates/shirabe/src/installer.rs +++ b/crates/shirabe/src/installer.rs @@ -384,9 +384,10 @@ impl Installer { "No replacement was suggested".to_string() }; - self.io.write_error(&sprintf( - "<warning>Package %s is abandoned, you should avoid using it. %s.</warning>", - &[complete.get_pretty_name().into(), replacement.into()], + self.io.write_error(&format!( + "<warning>Package {} is abandoned, you should avoid using it. {}.</warning>", + complete.get_pretty_name(), + replacement, )); } @@ -461,13 +462,11 @@ impl Installer { } } if funding_count > 0 { - self.io.write_error(&sprintf( - "<info>%d package%s you are using %s looking for funding.</info>", - &[ - funding_count.into(), - (if 1 == funding_count { "" } else { "s" }).into(), - (if 1 == funding_count { "is" } else { "are" }).into(), - ], + self.io.write_error(&format!( + "<info>{} package{} you are using {} looking for funding.</info>", + funding_count, + (if 1 == funding_count { "" } else { "s" }), + (if 1 == funding_count { "is" } else { "are" }), )); self.io .write_error("<info>Use the `composer fund` command to find out more!</info>"); @@ -792,16 +791,14 @@ impl Installer { .as_bool() .unwrap_or(false) { - self.io.write_error(&sprintf( - "<info>Lock file operations: %d install%s, %d update%s, %d removal%s</info>", - &[ - (install_names.len() as i64).into(), - (if 1 == install_names.len() { "" } else { "s" }).into(), - (update_names.len() as i64).into(), - (if 1 == update_names.len() { "" } else { "s" }).into(), - (uninstalls.len() as i64).into(), - (if 1 == uninstalls.len() { "" } else { "s" }).into(), - ], + self.io.write_error(&format!( + "<info>Lock file operations: {} install{}, {} update{}, {} removal{}</info>", + (install_names.len() as i64), + (if 1 == install_names.len() { "" } else { "s" }), + (update_names.len() as i64), + (if 1 == update_names.len() { "" } else { "s" }), + (uninstalls.len() as i64), + (if 1 == uninstalls.len() { "" } else { "s" }), )); if !install_names.is_empty() { self.io.write_error3( @@ -1185,16 +1182,14 @@ impl Installer { if installs.is_empty() && updates.is_empty() && uninstalls.is_empty() { self.io.write_error("Nothing to install, update or remove"); } else { - self.io.write_error(&sprintf( - "<info>Package operations: %d install%s, %d update%s, %d removal%s</info>", - &[ - (installs.len() as i64).into(), - (if 1 == installs.len() { "" } else { "s" }).into(), - (updates.len() as i64).into(), - (if 1 == updates.len() { "" } else { "s" }).into(), - (uninstalls.len() as i64).into(), - (if 1 == uninstalls.len() { "" } else { "s" }).into(), - ], + self.io.write_error(&format!( + "<info>Package operations: {} install{}, {} update{}, {} removal{}</info>", + (installs.len() as i64), + (if 1 == installs.len() { "" } else { "s" }), + (updates.len() as i64), + (if 1 == updates.len() { "" } else { "s" }), + (uninstalls.len() as i64), + (if 1 == uninstalls.len() { "" } else { "s" }), )); if !installs.is_empty() { self.io.write_error3( diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs index 2371dfa..b2e0bb5 100644 --- a/crates/shirabe/src/io/console_io.rs +++ b/crates/shirabe/src/io/console_io.rs @@ -109,13 +109,11 @@ impl ConsoleIO { let mapped: Vec<String> = arr .into_iter() .map(|message| { - sprintf( - "[%.1fMiB/%.2fs] %s", - &[ - PhpMixed::Float(memory_usage), - PhpMixed::Float(time_spent), - PhpMixed::String(message), - ], + format!( + "[{:.1}MiB/{:.2}s] {}", + memory_usage, + time_spent, + PhpMixed::String(message), ) }) .collect(); diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs index 4df022b..8e87302 100644 --- a/crates/shirabe/src/package/loader/array_loader.rs +++ b/crates/shirabe/src/package/loader/array_loader.rs @@ -395,18 +395,16 @@ impl ArrayLoader { .unwrap_or(false); if !has_required { return Err(UnexpectedValueException { - message: sprintf( - "Package %s's source key should be specified as {\"type\": ..., \"url\": ..., \"reference\": ...},\n%s given.", - &[ - PhpMixed::String( - config - .get("name") - .and_then(|v| v.as_string()) - .unwrap_or("") - .to_string(), - ), - PhpMixed::String(json_encode(&source).unwrap_or_default()), - ], + message: format!( + "Package {}'s source key should be specified as {{\"type\": ..., \"url\": ..., \"reference\": ...}},\n{} given.", + PhpMixed::String( + config + .get("name") + .and_then(|v| v.as_string()) + .unwrap_or("") + .to_string(), + ), + PhpMixed::String(json_encode(&source).unwrap_or_default()), ), code: 0, } @@ -440,18 +438,16 @@ impl ArrayLoader { .unwrap_or(false); if !has_required { return Err(UnexpectedValueException { - message: sprintf( - "Package %s's dist key should be specified as {\"type\": ..., \"url\": ..., \"reference\": ..., \"shasum\": ...},\n%s given.", - &[ - PhpMixed::String( - config - .get("name") - .and_then(|v| v.as_string()) - .unwrap_or("") - .to_string(), - ), - PhpMixed::String(json_encode(&dist).unwrap_or_default()), - ], + message: format!( + "Package {}'s dist key should be specified as {{\"type\": ..., \"url\": ..., \"reference\": ..., \"shasum\": ...}},\n{} given.", + PhpMixed::String( + config + .get("name") + .and_then(|v| v.as_string()) + .unwrap_or("") + .to_string(), + ), + PhpMixed::String(json_encode(&dist).unwrap_or_default()), ), code: 0, } diff --git a/crates/shirabe/src/package/loader/validating_array_loader.rs b/crates/shirabe/src/package/loader/validating_array_loader.rs index e6db19e..4a1e2c2 100644 --- a/crates/shirabe/src/package/loader/validating_array_loader.rs +++ b/crates/shirabe/src/package/loader/validating_array_loader.rs @@ -195,9 +195,9 @@ impl ValidatingArrayLoader { for index in &license_keys { let license = licenses[index].clone(); if !is_string(&*license) { - self.warnings.push(sprintf( - "License %s should be a string.", - &[PhpMixed::String(json_encode(&*license).unwrap_or_default())], + self.warnings.push(format!( + "License {} should be a string.", + PhpMixed::String(json_encode(&*license).unwrap_or_default()), )); licenses.shift_remove(index); } @@ -218,23 +218,21 @@ impl ValidatingArrayLoader { if license_validator .validate(&trim(&license_to_validate, Some(" \t\n\r\0\u{0B}"))) { - self.warnings.push(sprintf( - "License %s must not contain extra spaces, make sure to trim it.", - &[PhpMixed::String( + self.warnings.push(format!( + "License {} must not contain extra spaces, make sure to trim it.", + PhpMixed::String( json_encode(&PhpMixed::String(license_str.clone())) .unwrap_or_default(), - )], + ), )); } else { - self.warnings.push(sprintf( - &format!( - "License %s is not a valid SPDX license identifier, see https://spdx.org/licenses/ if you use an open license.{}If the software is closed-source, you may use \"proprietary\" as license.", - PHP_EOL - ), - &[PhpMixed::String( + self.warnings.push(format!( + "License {} is not a valid SPDX license identifier, see https://spdx.org/licenses/ if you use an open license.{}If the software is closed-source, you may use \"proprietary\" as license.", + PhpMixed::String( json_encode(&PhpMixed::String(license_str.clone())) .unwrap_or_default(), - )], + ), + PHP_EOL )); } } @@ -251,11 +249,9 @@ impl ValidatingArrayLoader { Box::new(PhpMixed::Array(reindexed_map)), ); } else { - self.warnings.push(sprintf( - "License must be a string or array of strings, got %s.", - &[PhpMixed::String( - json_encode(&*license_val).unwrap_or_default(), - )], + self.warnings.push(format!( + "License must be a string or array of strings, got {}.", + PhpMixed::String(json_encode(&*license_val).unwrap_or_default(),), )); self.config.shift_remove("license"); } diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs index ed53143..c61d807 100644 --- a/crates/shirabe/src/package/locker.rs +++ b/crates/shirabe/src/package/locker.rs @@ -750,9 +750,9 @@ impl Locker { if name.is_empty() || version.is_empty() { return Err(LogicException { - message: sprintf( - "Package \"%s\" has no version or name and can not be locked", - &[PhpMixed::String(package.to_string())], + message: format!( + "Package \"{}\" has no version or name and can not be locked", + PhpMixed::String(package.to_string()), ), code: 0, } @@ -975,11 +975,8 @@ impl Locker { let _ = &results; let mut description = provider.get_pretty_version(); if provider.get_name() != link.get_target() { - 'outer: for (method, text) in [ - ("getReplaces", "replaced as %s by %s"), - ("getProvides", "provided as %s by %s"), - ] - .iter() + 'outer: for (method, verb) in + [("getReplaces", "replaced"), ("getProvides", "provided")].iter() { let provider_links = match *method { "getReplaces" => provider.get_replaces(), @@ -988,20 +985,17 @@ impl Locker { }; for provider_link in provider_links.values() { if provider_link.get_target() == link.get_target() { - description = sprintf( - text, - &[ - PhpMixed::String( - provider_link - .get_pretty_constraint() - .to_string(), - ), - PhpMixed::String(format!( - "{} {}", - provider.get_pretty_name(), - provider.get_pretty_version() - )), - ], + description = format!( + "{} as {} by {}", + verb, + PhpMixed::String( + provider_link.get_pretty_constraint().to_string(), + ), + PhpMixed::String(format!( + "{} {}", + provider.get_pretty_name(), + provider.get_pretty_version() + )), ); break 'outer; } diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs index 932584c..d9954af 100644 --- a/crates/shirabe/src/repository/platform_repository.rs +++ b/crates/shirabe/src/repository/platform_repository.rs @@ -1342,13 +1342,11 @@ impl PlatformRepository { .get_constant("RD_KAFKA_VERSION", None) .as_int() .unwrap_or(0); - let version_built = sprintf( - "%d.%d.%d", - &[ - PhpMixed::Int((lib_rd_kafka_version_int & 0x7F000000) >> 24), - PhpMixed::Int((lib_rd_kafka_version_int & 0x00FF0000) >> 16), - PhpMixed::Int((lib_rd_kafka_version_int & 0x0000FF00) >> 8), - ], + let version_built = format!( + "{}.{}.{}", + PhpMixed::Int((lib_rd_kafka_version_int & 0x7F000000) >> 24), + PhpMixed::Int((lib_rd_kafka_version_int & 0x00FF0000) >> 16), + PhpMixed::Int((lib_rd_kafka_version_int & 0x0000FF00) >> 8), ); self.add_library( &mut libraries, diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index b33aa05..9c285e0 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -95,9 +95,9 @@ impl GitBitbucketDriver { .unwrap_or(false) { return Err(InvalidArgumentException { - message: sprintf( - "The Bitbucket repository URL %s is invalid. It must be the HTTPS URL of a Bitbucket repository.", - &[PhpMixed::String(self.inner.url.clone())], + message: format!( + "The Bitbucket repository URL {} is invalid. It must be the HTTPS URL of a Bitbucket repository.", + PhpMixed::String(self.inner.url.clone()), ), code: 0, } @@ -154,24 +154,22 @@ impl GitBitbucketDriver { /// /// @phpstan-impure fn get_repo_data(&mut self) -> Result<bool> { - let resource = sprintf( - "https://api.bitbucket.org/2.0/repositories/%s/%s?%s", - &[ - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - PhpMixed::String(http_build_query_mixed( - &{ - let mut m: IndexMap<String, PhpMixed> = IndexMap::new(); - m.insert( - "fields".to_string(), - PhpMixed::String("-project,-owner".to_string()), - ); - m - }, - "", - "&", - )), - ], + let resource = format!( + "https://api.bitbucket.org/2.0/repositories/{}/{}?{}", + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), + PhpMixed::String(http_build_query_mixed( + &{ + let mut m: IndexMap<String, PhpMixed> = IndexMap::new(); + m.insert( + "fields".to_string(), + PhpMixed::String("-project,-owner".to_string()), + ); + m + }, + "", + "&", + )), ); let repo_data = self @@ -358,28 +356,24 @@ impl GitBitbucketDriver { if let PhpMixed::Array(support_map) = support_entry { support_map.insert( "source".to_string(), - Box::new(PhpMixed::String(sprintf( - "https://%s/%s/%s/src", - &[ - PhpMixed::String(self.inner.origin_url.clone()), - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - ], + Box::new(PhpMixed::String(format!( + "https://{}/{}/{}/src", + PhpMixed::String(self.inner.origin_url.clone()), + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), ))), ); } } else if let PhpMixed::Array(support_map) = support_entry { support_map.insert( "source".to_string(), - Box::new(PhpMixed::String(sprintf( - "https://%s/%s/%s/src/%s/?at=%s", - &[ - PhpMixed::String(self.inner.origin_url.clone()), - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - PhpMixed::String(hash.unwrap()), - PhpMixed::String(label.clone()), - ], + Box::new(PhpMixed::String(format!( + "https://{}/{}/{}/src/{}/?at={}", + PhpMixed::String(self.inner.origin_url.clone()), + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), + PhpMixed::String(hash.unwrap()), + PhpMixed::String(label.clone()), ))), ); } @@ -398,13 +392,11 @@ impl GitBitbucketDriver { if let PhpMixed::Array(support_map) = support_entry { support_map.insert( "issues".to_string(), - Box::new(PhpMixed::String(sprintf( - "https://%s/%s/%s/issues", - &[ - PhpMixed::String(self.inner.origin_url.clone()), - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - ], + Box::new(PhpMixed::String(format!( + "https://{}/{}/{}/issues", + PhpMixed::String(self.inner.origin_url.clone()), + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), ))), ); } @@ -444,14 +436,12 @@ impl GitBitbucketDriver { } } - let resource = sprintf( - "https://api.bitbucket.org/2.0/repositories/%s/%s/src/%s/%s", - &[ - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - PhpMixed::String(identifier), - PhpMixed::String(file.to_string()), - ], + let resource = format!( + "https://api.bitbucket.org/2.0/repositories/{}/{}/src/{}/{}", + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), + PhpMixed::String(identifier), + PhpMixed::String(file.to_string()), ); Ok(self @@ -474,13 +464,11 @@ impl GitBitbucketDriver { } } - let resource = sprintf( - "https://api.bitbucket.org/2.0/repositories/%s/%s/commit/%s?fields=date", - &[ - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - PhpMixed::String(identifier), - ], + let resource = format!( + "https://api.bitbucket.org/2.0/repositories/{}/{}/commit/{}?fields=date", + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), + PhpMixed::String(identifier), ); let commit = self .fetch_with_oauth_credentials(&resource, false)? @@ -517,13 +505,11 @@ impl GitBitbucketDriver { return fallback.get_dist(identifier).ok().flatten(); } - let url = sprintf( - "https://bitbucket.org/%s/%s/get/%s.zip", - &[ - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - PhpMixed::String(identifier.to_string()), - ], + let url = format!( + "https://bitbucket.org/{}/{}/get/{}.zip", + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), + PhpMixed::String(identifier.to_string()), ); let mut m: IndexMap<String, String> = IndexMap::new(); @@ -542,28 +528,26 @@ impl GitBitbucketDriver { if self.tags.is_none() { let mut tags: IndexMap<String, String> = IndexMap::new(); - let mut resource = sprintf( - "%s?%s", - &[ - PhpMixed::String(self.tags_url.clone()), - PhpMixed::String(http_build_query_mixed( - &{ - let mut m: IndexMap<String, PhpMixed> = IndexMap::new(); - m.insert("pagelen".to_string(), PhpMixed::Int(100)); - m.insert( - "fields".to_string(), - PhpMixed::String("values.name,values.target.hash,next".to_string()), - ); - m.insert( - "sort".to_string(), - PhpMixed::String("-target.date".to_string()), - ); - m - }, - "", - "&", - )), - ], + let mut resource = format!( + "{}?{}", + PhpMixed::String(self.tags_url.clone()), + PhpMixed::String(http_build_query_mixed( + &{ + let mut m: IndexMap<String, PhpMixed> = IndexMap::new(); + m.insert("pagelen".to_string(), PhpMixed::Int(100)); + m.insert( + "fields".to_string(), + PhpMixed::String("values.name,values.target.hash,next".to_string()), + ); + m.insert( + "sort".to_string(), + PhpMixed::String("-target.date".to_string()), + ); + m + }, + "", + "&", + )), ); let mut has_next = true; while has_next { @@ -623,30 +607,28 @@ impl GitBitbucketDriver { if self.branches.is_none() { let mut branches: IndexMap<String, String> = IndexMap::new(); - let mut resource = sprintf( - "%s?%s", - &[ - PhpMixed::String(self.branches_url.clone()), - PhpMixed::String(http_build_query_mixed( - &{ - let mut m: IndexMap<String, PhpMixed> = IndexMap::new(); - m.insert("pagelen".to_string(), PhpMixed::Int(100)); - m.insert( - "fields".to_string(), - PhpMixed::String( - "values.name,values.target.hash,values.heads,next".to_string(), - ), - ); - m.insert( - "sort".to_string(), - PhpMixed::String("-target.date".to_string()), - ); - m - }, - "", - "&", - )), - ], + let mut resource = format!( + "{}?{}", + PhpMixed::String(self.branches_url.clone()), + PhpMixed::String(http_build_query_mixed( + &{ + let mut m: IndexMap<String, PhpMixed> = IndexMap::new(); + m.insert("pagelen".to_string(), PhpMixed::Int(100)); + m.insert( + "fields".to_string(), + PhpMixed::String( + "values.name,values.target.hash,values.heads,next".to_string(), + ), + ); + m.insert( + "sort".to_string(), + PhpMixed::String("-target.date".to_string()), + ); + m + }, + "", + "&", + )), ); let mut has_next = true; while has_next { diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index aa1e135..5fb3439 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -82,9 +82,9 @@ impl GitHubDriver { .unwrap_or(false) { return Err(InvalidArgumentException { - message: sprintf( - "The GitHub repository URL %s is invalid.", - &[PhpMixed::String(self.inner.url.clone())], + message: format!( + "The GitHub repository URL {} is invalid.", + PhpMixed::String(self.inner.url.clone()), ), code: 0, } @@ -366,14 +366,12 @@ impl GitHubDriver { }) { support.insert( "source".to_string(), - Box::new(PhpMixed::String(sprintf( - "https://%s/%s/%s/tree/%s", - &[ - PhpMixed::String(self.inner.origin_url.clone()), - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - PhpMixed::String(label_str), - ], + Box::new(PhpMixed::String(format!( + "https://{}/{}/{}/tree/{}", + PhpMixed::String(self.inner.origin_url.clone()), + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), + PhpMixed::String(label_str), ))), ); } @@ -390,13 +388,11 @@ impl GitHubDriver { }) { support.insert( "issues".to_string(), - Box::new(PhpMixed::String(sprintf( - "https://%s/%s/%s/issues", - &[ - PhpMixed::String(self.inner.origin_url.clone()), - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - ], + Box::new(PhpMixed::String(format!( + "https://{}/{}/{}/issues", + PhpMixed::String(self.inner.origin_url.clone()), + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), ))), ); } @@ -1169,12 +1165,10 @@ impl GitHubDriver { e.get_headers().map(|h| h.as_slice()).unwrap_or(&[]), ); self.inner.io.write_error3( - &sprintf( - "<error>GitHub API limit (%d calls/hr) is exhausted. You are already authorized so you have to wait until %s before doing more requests</error>", - &[ - rate_limit.get("limit").cloned().unwrap_or(PhpMixed::Null), - rate_limit.get("reset").cloned().unwrap_or(PhpMixed::Null), - ], + &format!( + "<error>GitHub API limit ({} calls/hr) is exhausted. You are already authorized so you have to wait until {} before doing more requests</error>", + rate_limit.get("limit").cloned().unwrap_or(PhpMixed::Null), + rate_limit.get("reset").cloned().unwrap_or(PhpMixed::Null), ), true, io_interface::NORMAL, diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index 8ab30d4..bc47db8 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -88,9 +88,9 @@ impl GitLabDriver { .unwrap_or(false) { return Err(InvalidArgumentException { - message: sprintf( - "The GitLab repository URL %s is invalid. It must be the HTTP URL of a GitLab project.", - &[PhpMixed::String(self.inner.url.clone())], + message: format!( + "The GitLab repository URL {} is invalid. It must be the HTTP URL of a GitLab project.", + PhpMixed::String(self.inner.url.clone()), ), code: 0, } @@ -366,9 +366,10 @@ impl GitLabDriver { }) { support.insert( "source".to_string(), - Box::new(PhpMixed::String(sprintf( - "%s/-/tree/%s", - &[PhpMixed::String(web_url), PhpMixed::String(label_str)], + Box::new(PhpMixed::String(format!( + "{}/-/tree/{}", + PhpMixed::String(web_url), + PhpMixed::String(label_str), ))), ); } @@ -396,9 +397,9 @@ impl GitLabDriver { }) { support.insert( "issues".to_string(), - Box::new(PhpMixed::String(sprintf( - "%s/-/issues", - &[PhpMixed::String(web_url)], + Box::new(PhpMixed::String(format!( + "{}/-/issues", + PhpMixed::String(web_url), ))), ); } @@ -617,7 +618,7 @@ impl GitLabDriver { ]), true, ) { - format!("%{}", sprintf("%02X", &[PhpMixed::Int(ord(&character))])) + format!("%{}", format!("{:02X}", ord(&character))) } else { character }; diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs index 2373265..8505081 100644 --- a/crates/shirabe/src/util/auth_helper.rs +++ b/crates/shirabe/src/util/auth_helper.rs @@ -195,15 +195,12 @@ impl AuthHelper { message = format!( "{}\n", - sprintf( - &format!( - "GitHub API limit (%d calls/hr) is exhausted, could not fetch {}. {} You can also wait until %s for the rate limit to reset.", - url, message, - ), - &[ - rate_limit.get("limit").cloned().unwrap_or(PhpMixed::Null), - rate_limit.get("reset").cloned().unwrap_or(PhpMixed::Null), - ], + format!( + "GitHub API limit ({} calls/hr) is exhausted, could not fetch {}. {} You can also wait until {} for the rate limit to reset.", + rate_limit.get("limit").cloned().unwrap_or(PhpMixed::Null), + url, + message, + rate_limit.get("reset").cloned().unwrap_or(PhpMixed::Null), ), ); } else { diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index f54dfca..f693598 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -519,9 +519,10 @@ impl Filesystem { // Returning early-formatted Result is not possible without changing signature; panic to surface in tests. panic!( "{}", - sprintf( - "$from (%s) and $to (%s) must be absolute paths.", - &[from.to_string().into(), to.to_string().into()] + format!( + "$from ({}) and $to ({}) must be absolute paths.", + from.to_string(), + to.to_string() ) ); } @@ -583,9 +584,10 @@ impl Filesystem { if !self.is_absolute_path(from) || !self.is_absolute_path(to) { panic!( "{}", - sprintf( - "$from (%s) and $to (%s) must be absolute paths.", - &[from.to_string().into(), to.to_string().into()] + format!( + "$from ({}) and $to ({}) must be absolute paths.", + from.to_string(), + to.to_string() ) ); } diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs index a0ef54f..f1056cc 100644 --- a/crates/shirabe/src/util/http/curl_downloader.rs +++ b/crates/shirabe/src/util/http/curl_downloader.rs @@ -1527,15 +1527,13 @@ impl CurlDownloader { &job, anyhow::anyhow!( TransportException::new( - sprintf( - "IP \"%s\" is blocked for \"%s\".", - &[ - primary_ip.clone(), - progress_now - .get("url") - .cloned() - .unwrap_or(PhpMixed::Null), - ], + format!( + "IP \"{}\" is blocked for \"{}\".", + primary_ip.clone(), + progress_now + .get("url") + .cloned() + .unwrap_or(PhpMixed::Null), ), 0, ) @@ -1611,19 +1609,17 @@ impl CurlDownloader { if !target_url.is_empty() { self.io.write_error3( - &sprintf( - "Following redirect (%u) %s", - &[ - PhpMixed::Int( - job.get("attributes") - .and_then(|v| v.as_array()) - .and_then(|a| a.get("redirects")) - .and_then(|b| b.as_int()) - .unwrap_or(0) - + 1, - ), - PhpMixed::String(Url::sanitize(target_url.clone())), - ], + &format!( + "Following redirect ({}) {}", + PhpMixed::Int( + job.get("attributes") + .and_then(|v| v.as_array()) + .and_then(|a| a.get("redirects")) + .and_then(|b| b.as_int()) + .unwrap_or(0) + + 1, + ), + PhpMixed::String(Url::sanitize(target_url.clone())), ), true, crate::io::DEBUG, diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index ff6f066..fc26775 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -981,12 +981,10 @@ impl RemoteFilesystem { self.io.write_error3("", true, crate::io::DEBUG); self.io.write_error3( - &sprintf( - "Following redirect (%u) %s", - &[ - PhpMixed::Int(self.redirects), - PhpMixed::String(Url::sanitize(target_url.clone())), - ], + &format!( + "Following redirect ({}) {}", + PhpMixed::Int(self.redirects), + PhpMixed::String(Url::sanitize(target_url.clone())), ), true, crate::io::DEBUG, |
