aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-12 03:19:34 +0900
committernsfisis <nsfisis@gmail.com>2026-06-12 03:19:34 +0900
commitefe5bdb1987411a473d4af15451a376d20928245 (patch)
tree54d3c9e7ab92cfc7d7ec3d90ca3f29e828d929c4 /crates/shirabe/src/command
parent981cae63d9777b877aa9f96907c7995ec020fbf9 (diff)
downloadphp-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/src/command')
-rw-r--r--crates/shirabe/src/command/config_command.rs14
-rw-r--r--crates/shirabe/src/command/diagnose_command.rs18
-rw-r--r--crates/shirabe/src/command/init_command.rs19
-rw-r--r--crates/shirabe/src/command/package_discovery_trait.rs138
-rw-r--r--crates/shirabe/src/command/require_command.rs62
-rw-r--r--crates/shirabe/src/command/update_command.rs8
6 files changed, 115 insertions, 144 deletions
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,
) {