aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/input
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-external-packages/src/symfony/console/input
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-external-packages/src/symfony/console/input')
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs67
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/array_input.rs23
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/input.rs33
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs122
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/string_input.rs10
5 files changed, 112 insertions, 143 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
index e9cb8d3..765f601 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
@@ -148,10 +148,7 @@ impl ArgvInput {
}
};
return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: shirabe_php_shim::sprintf(
- "The \"-%s\" option does not exist.",
- &[PhpMixed::String(bad)],
- ),
+ message: format!("The \"-{}\" option does not exist.", PhpMixed::String(bad),),
code: 0,
})
.into());
@@ -251,17 +248,15 @@ impl ArgvInput {
Some(symfony_command_name)
if !matches!(symfony_command_name, PhpMixed::Null) =>
{
- shirabe_php_shim::sprintf(
- "Too many arguments to \"%s\" command, expected arguments \"%s\".",
- &[
- symfony_command_name.clone(),
- PhpMixed::String(shirabe_php_shim::implode("\" \"", &names)),
- ],
+ format!(
+ "Too many arguments to \"{}\" command, expected arguments \"{}\".",
+ symfony_command_name.clone(),
+ PhpMixed::String(shirabe_php_shim::implode("\" \"", &names)),
)
}
- _ => shirabe_php_shim::sprintf(
- "Too many arguments, expected arguments \"%s\".",
- &[PhpMixed::String(shirabe_php_shim::implode("\" \"", &names))],
+ _ => format!(
+ "Too many arguments, expected arguments \"{}\".",
+ PhpMixed::String(shirabe_php_shim::implode("\" \"", &names)),
),
}
} else if symfony_command_name
@@ -269,17 +264,15 @@ impl ArgvInput {
.map(|n| !matches!(n, PhpMixed::Null))
.unwrap_or(false)
{
- shirabe_php_shim::sprintf(
- "No arguments expected for \"%s\" command, got \"%s\".",
- &[
- symfony_command_name.clone().unwrap(),
- PhpMixed::String(token.to_string()),
- ],
+ format!(
+ "No arguments expected for \"{}\" command, got \"{}\".",
+ symfony_command_name.clone().unwrap(),
+ PhpMixed::String(token.to_string()),
)
} else {
- shirabe_php_shim::sprintf(
- "No arguments expected, got \"%s\".",
- &[PhpMixed::String(token.to_string())],
+ format!(
+ "No arguments expected, got \"{}\".",
+ PhpMixed::String(token.to_string()),
)
};
@@ -295,9 +288,9 @@ impl ArgvInput {
fn add_short_option(&mut self, shortcut: &str, value: PhpMixed) -> anyhow::Result<()> {
if !self.inner.definition.has_shortcut(shortcut) {
return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: shirabe_php_shim::sprintf(
- "The \"-%s\" option does not exist.",
- &[PhpMixed::String(shortcut.to_string())],
+ message: format!(
+ "The \"-{}\" option does not exist.",
+ PhpMixed::String(shortcut.to_string()),
),
code: 0,
})
@@ -320,9 +313,9 @@ impl ArgvInput {
if !self.inner.definition.has_option(name) {
if !self.inner.definition.has_negation(name) {
return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: shirabe_php_shim::sprintf(
- "The \"--%s\" option does not exist.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"--{}\" option does not exist.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
})
@@ -332,9 +325,9 @@ impl ArgvInput {
let option_name = self.inner.definition.negation_to_name(name)?;
if !matches!(value, PhpMixed::Null) {
return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: shirabe_php_shim::sprintf(
- "The \"--%s\" option does not accept a value.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"--{}\" option does not accept a value.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
})
@@ -351,9 +344,9 @@ impl ArgvInput {
if !matches!(value, PhpMixed::Null) && !option.accept_value() {
return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: shirabe_php_shim::sprintf(
- "The \"--%s\" option does not accept a value.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"--{}\" option does not accept a value.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
})
@@ -379,9 +372,9 @@ impl ArgvInput {
if matches!(value, PhpMixed::Null) {
if option.is_value_required() {
return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: shirabe_php_shim::sprintf(
- "The \"--%s\" option requires a value.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"--{}\" option requires a value.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
})
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs
index 17c8aa8..ccc1916 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs
@@ -206,9 +206,9 @@ impl ArrayInput {
if !self.inner.definition.has_shortcut(shortcut) {
return Err(InvalidOptionException(InvalidArgumentException(
shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"-%s\" option does not exist.",
- &[PhpMixed::String(shortcut.to_string())],
+ message: format!(
+ "The \"-{}\" option does not exist.",
+ PhpMixed::String(shortcut.to_string()),
),
code: 0,
},
@@ -233,9 +233,9 @@ impl ArrayInput {
if !self.inner.definition.has_negation(name) {
return Err(InvalidOptionException(InvalidArgumentException(
shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"--%s\" option does not exist.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"--{}\" option does not exist.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
},
@@ -257,9 +257,9 @@ impl ArrayInput {
if option.is_value_required() {
return Err(InvalidOptionException(InvalidArgumentException(
shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"--%s\" option requires a value.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"--{}\" option requires a value.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
},
@@ -282,10 +282,7 @@ impl ArrayInput {
if !self.inner.definition.has_argument(name) {
return Err(
InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"%s\" argument does not exist.",
- &[name.clone()],
- ),
+ message: format!("The \"{}\" argument does not exist.", name.clone(),),
code: 0,
})
.into(),
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input.rs b/crates/shirabe-external-packages/src/symfony/console/input/input.rs
index 4c878bc..2c9a3a6 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/input.rs
@@ -79,12 +79,9 @@ impl Input {
if missing_arguments.len() > 0 {
return Err(RuntimeException(shirabe_php_shim::RuntimeException {
- message: shirabe_php_shim::sprintf(
- "Not enough arguments (missing: \"%s\").",
- &[PhpMixed::String(shirabe_php_shim::implode(
- ", ",
- &missing_arguments,
- ))],
+ message: format!(
+ "Not enough arguments (missing: \"{}\").",
+ PhpMixed::String(shirabe_php_shim::implode(", ", &missing_arguments,)),
),
code: 0,
})
@@ -116,9 +113,9 @@ impl Input {
{
return Err(
InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"%s\" argument does not exist.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"{}\" argument does not exist.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
})
@@ -143,9 +140,9 @@ impl Input {
{
return Err(
InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"%s\" argument does not exist.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"{}\" argument does not exist.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
})
@@ -183,9 +180,9 @@ impl Input {
if !self.definition.has_option(name) {
return Err(
InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"%s\" option does not exist.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"{}\" option does not exist.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
})
@@ -210,9 +207,9 @@ impl Input {
} else if !self.definition.has_option(name) {
return Err(
InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"%s\" option does not exist.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"{}\" option does not exist.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
})
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs b/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs
index 5a3eef5..917f02a 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs
@@ -90,9 +90,9 @@ impl InputDefinition {
if self.arguments.contains_key(argument.get_name()) {
return Err(LogicException(shirabe_php_shim::LogicException {
- message: shirabe_php_shim::sprintf(
- "An argument with name \"%s\" already exists.",
- &[PhpMixed::String(argument.get_name().to_string())],
+ message: format!(
+ "An argument with name \"{}\" already exists.",
+ PhpMixed::String(argument.get_name().to_string()),
),
code: 0,
})
@@ -101,12 +101,10 @@ impl InputDefinition {
if let Some(last_array_argument) = &self.last_array_argument {
return Err(LogicException(shirabe_php_shim::LogicException {
- message: shirabe_php_shim::sprintf(
- "Cannot add a required argument \"%s\" after an array argument \"%s\".",
- &[
- PhpMixed::String(argument.get_name().to_string()),
- PhpMixed::String(last_array_argument.get_name().to_string()),
- ],
+ message: format!(
+ "Cannot add a required argument \"{}\" after an array argument \"{}\".",
+ PhpMixed::String(argument.get_name().to_string()),
+ PhpMixed::String(last_array_argument.get_name().to_string()),
),
code: 0,
})
@@ -116,12 +114,10 @@ impl InputDefinition {
if argument.is_required() {
if let Some(last_optional_argument) = &self.last_optional_argument {
return Err(LogicException(shirabe_php_shim::LogicException {
- message: shirabe_php_shim::sprintf(
- "Cannot add a required argument \"%s\" after an optional one \"%s\".",
- &[
- PhpMixed::String(argument.get_name().to_string()),
- PhpMixed::String(last_optional_argument.get_name().to_string()),
- ],
+ message: format!(
+ "Cannot add a required argument \"{}\" after an optional one \"{}\".",
+ PhpMixed::String(argument.get_name().to_string()),
+ PhpMixed::String(last_optional_argument.get_name().to_string()),
),
code: 0,
})
@@ -150,10 +146,7 @@ impl InputDefinition {
if !self.has_argument(name) {
return Err(
InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"%s\" argument does not exist.",
- &[name.clone()],
- ),
+ message: format!("The \"{}\" argument does not exist.", name.clone(),),
code: 0,
})
.into(),
@@ -240,9 +233,9 @@ impl InputDefinition {
if let Some(existing) = self.options.get(option.get_name()) {
if !option.equals(existing) {
return Err(LogicException(shirabe_php_shim::LogicException {
- message: shirabe_php_shim::sprintf(
- "An option named \"%s\" already exists.",
- &[PhpMixed::String(option.get_name().to_string())],
+ message: format!(
+ "An option named \"{}\" already exists.",
+ PhpMixed::String(option.get_name().to_string()),
),
code: 0,
})
@@ -251,9 +244,9 @@ impl InputDefinition {
}
if self.negations.contains_key(option.get_name()) {
return Err(LogicException(shirabe_php_shim::LogicException {
- message: shirabe_php_shim::sprintf(
- "An option named \"%s\" already exists.",
- &[PhpMixed::String(option.get_name().to_string())],
+ message: format!(
+ "An option named \"{}\" already exists.",
+ PhpMixed::String(option.get_name().to_string()),
),
code: 0,
})
@@ -265,9 +258,9 @@ impl InputDefinition {
if let Some(existing_name) = self.shortcuts.get(&shortcut) {
if !option.equals(&self.options[existing_name]) {
return Err(LogicException(shirabe_php_shim::LogicException {
- message: shirabe_php_shim::sprintf(
- "An option with shortcut \"%s\" already exists.",
- &[PhpMixed::String(shortcut.clone())],
+ message: format!(
+ "An option with shortcut \"{}\" already exists.",
+ PhpMixed::String(shortcut.clone()),
),
code: 0,
})
@@ -290,9 +283,9 @@ impl InputDefinition {
let negated_name = format!("no-{}", option.get_name());
if self.options.contains_key(&negated_name) {
return Err(LogicException(shirabe_php_shim::LogicException {
- message: shirabe_php_shim::sprintf(
- "An option named \"%s\" already exists.",
- &[PhpMixed::String(negated_name.clone())],
+ message: format!(
+ "An option named \"{}\" already exists.",
+ PhpMixed::String(negated_name.clone()),
),
code: 0,
})
@@ -310,9 +303,9 @@ impl InputDefinition {
if !self.has_option(name) {
return Err(
InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"--%s\" option does not exist.",
- &[PhpMixed::String(name.to_string())],
+ message: format!(
+ "The \"--{}\" option does not exist.",
+ PhpMixed::String(name.to_string()),
),
code: 0,
})
@@ -365,9 +358,9 @@ impl InputDefinition {
match self.shortcuts.get(shortcut) {
None => Err(
InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"-%s\" option does not exist.",
- &[PhpMixed::String(shortcut.to_string())],
+ message: format!(
+ "The \"-{}\" option does not exist.",
+ PhpMixed::String(shortcut.to_string()),
),
code: 0,
})
@@ -382,9 +375,9 @@ impl InputDefinition {
match self.negations.get(negation) {
None => Err(
InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "The \"--%s\" option does not exist.",
- &[PhpMixed::String(negation.to_string())],
+ message: format!(
+ "The \"--{}\" option does not exist.",
+ PhpMixed::String(negation.to_string()),
),
code: 0,
})
@@ -404,46 +397,39 @@ impl InputDefinition {
for option in self.get_options().values() {
let mut value = String::new();
if option.accept_value() {
- value = shirabe_php_shim::sprintf(
- " %s%s%s",
- &[
- PhpMixed::String(if option.is_value_optional() {
- "[".to_string()
- } else {
- String::new()
- }),
- PhpMixed::String(shirabe_php_shim::strtoupper(option.get_name())),
- PhpMixed::String(if option.is_value_optional() {
- "]".to_string()
- } else {
- String::new()
- }),
- ],
+ value = format!(
+ " {}{}{}",
+ PhpMixed::String(if option.is_value_optional() {
+ "[".to_string()
+ } else {
+ String::new()
+ }),
+ PhpMixed::String(shirabe_php_shim::strtoupper(option.get_name())),
+ PhpMixed::String(if option.is_value_optional() {
+ "]".to_string()
+ } else {
+ String::new()
+ }),
);
}
let shortcut = match option.get_shortcut() {
Some(shortcut) => {
- shirabe_php_shim::sprintf("-%s|", &[PhpMixed::String(shortcut.to_string())])
+ format!("-{}|", PhpMixed::String(shortcut.to_string()))
}
None => String::new(),
};
let negation = if option.is_negatable() {
- shirabe_php_shim::sprintf(
- "|--no-%s",
- &[PhpMixed::String(option.get_name().to_string())],
- )
+ format!("|--no-{}", PhpMixed::String(option.get_name().to_string()),)
} else {
String::new()
};
- elements.push(shirabe_php_shim::sprintf(
- "[%s--%s%s%s]",
- &[
- PhpMixed::String(shortcut),
- PhpMixed::String(option.get_name().to_string()),
- PhpMixed::String(value),
- PhpMixed::String(negation),
- ],
+ elements.push(format!(
+ "[{}--{}{}{}]",
+ PhpMixed::String(shortcut),
+ PhpMixed::String(option.get_name().to_string()),
+ PhpMixed::String(value),
+ PhpMixed::String(negation),
));
}
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs
index aad1d86..bbc9e86 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs
@@ -102,13 +102,9 @@ impl StringInput {
// should never happen
return Err(
InvalidArgumentException(shirabe_php_shim::InvalidArgumentException {
- message: shirabe_php_shim::sprintf(
- "Unable to parse input near \"... %s ...\".",
- &[PhpMixed::String(shirabe_php_shim::substr(
- input,
- cursor,
- Some(10),
- ))],
+ message: format!(
+ "Unable to parse input near \"... {} ...\".",
+ PhpMixed::String(shirabe_php_shim::substr(input, cursor, Some(10),)),
),
code: 0,
})