diff options
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/helper')
12 files changed, 129 insertions, 180 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs index 26ad169..170c557 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs @@ -51,13 +51,11 @@ impl DebugFormatterHelper { }, ); - shirabe_php_shim::sprintf( - "%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - shirabe_php_shim::PhpMixed::String(message.to_string()), - ], + format!( + "{}<bg=blue;fg=white> {} </> <fg=blue>{}</>\n", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), + shirabe_php_shim::PhpMixed::String(message.to_string()), ) } @@ -78,24 +76,20 @@ impl DebugFormatterHelper { self.started.get_mut(id).unwrap().out = false; } if !self.started[id].err { - message.push_str(&shirabe_php_shim::sprintf( - "%s<bg=red;fg=white> %s </> ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), - ], + message.push_str(&format!( + "{}<bg=red;fg=white> {} </> ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), )); self.started.get_mut(id).unwrap().err = true; } message.push_str(&shirabe_php_shim::str_replace( "\n", - &shirabe_php_shim::sprintf( - "\n%s<bg=red;fg=white> %s </> ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), - ], + &format!( + "\n{}<bg=red;fg=white> {} </> ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), ), buffer, )); @@ -105,24 +99,20 @@ impl DebugFormatterHelper { self.started.get_mut(id).unwrap().err = false; } if !self.started[id].out { - message.push_str(&shirabe_php_shim::sprintf( - "%s<bg=green;fg=white> %s </> ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - ], + message.push_str(&format!( + "{}<bg=green;fg=white> {} </> ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), )); self.started.get_mut(id).unwrap().out = true; } message.push_str(&shirabe_php_shim::str_replace( "\n", - &shirabe_php_shim::sprintf( - "\n%s<bg=green;fg=white> %s </> ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - ], + &format!( + "\n{}<bg=green;fg=white> {} </> ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), ), buffer, )); @@ -140,25 +130,21 @@ impl DebugFormatterHelper { }; if successful { - return shirabe_php_shim::sprintf( - "%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", - &[ - shirabe_php_shim::PhpMixed::String(trailing_eol.to_string()), - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - shirabe_php_shim::PhpMixed::String(message.to_string()), - ], - ); - } - - let message = shirabe_php_shim::sprintf( - "%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", - &[ + return format!( + "{}{}<bg=green;fg=white> {} </> <fg=green>{}</>\n", shirabe_php_shim::PhpMixed::String(trailing_eol.to_string()), shirabe_php_shim::PhpMixed::String(self.get_border(id)), shirabe_php_shim::PhpMixed::String(prefix.to_string()), shirabe_php_shim::PhpMixed::String(message.to_string()), - ], + ); + } + + let message = format!( + "{}{}<bg=red;fg=white> {} </> <fg=red>{}</>\n", + shirabe_php_shim::PhpMixed::String(trailing_eol.to_string()), + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), + shirabe_php_shim::PhpMixed::String(message.to_string()), ); if let Some(session) = self.started.get_mut(id) { @@ -170,11 +156,11 @@ impl DebugFormatterHelper { } fn get_border(&self, id: &str) -> String { - shirabe_php_shim::sprintf( - "<bg=%s> </>", - &[shirabe_php_shim::PhpMixed::String( + format!( + "<bg={}> </>", + shirabe_php_shim::PhpMixed::String( COLORS[self.started[id].border as usize].to_string(), - )], + ), ) } } diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs index 64c166c..333af92 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs @@ -85,9 +85,9 @@ impl DescriptorHelper { if !self.descriptors.contains_key(&format) { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Unsupported format \"%s\".", - &[shirabe_php_shim::PhpMixed::String(format.clone())], + message: format!( + "Unsupported format \"{}\".", + shirabe_php_shim::PhpMixed::String(format.clone()), ), code: 0, }, diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs index ef33f93..5b26b75 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs @@ -14,14 +14,12 @@ pub struct FormatterHelper { impl FormatterHelper { /// Formats a message within a section. pub fn format_section(&self, section: &str, message: &str, style: &str) -> String { - shirabe_php_shim::sprintf( - "<%s>[%s]</%s> %s", - &[ - shirabe_php_shim::PhpMixed::String(style.to_string()), - shirabe_php_shim::PhpMixed::String(section.to_string()), - shirabe_php_shim::PhpMixed::String(style.to_string()), - shirabe_php_shim::PhpMixed::String(message.to_string()), - ], + format!( + "<{}>[{}]</{}> {}", + shirabe_php_shim::PhpMixed::String(style.to_string()), + shirabe_php_shim::PhpMixed::String(section.to_string()), + shirabe_php_shim::PhpMixed::String(style.to_string()), + shirabe_php_shim::PhpMixed::String(message.to_string()), ) } @@ -38,10 +36,11 @@ impl FormatterHelper { let mut lines: Vec<String> = Vec::new(); for message in &messages { let message = OutputFormatter::escape(message).unwrap(); - lines.push(shirabe_php_shim::sprintf( - if large { " %s " } else { " %s " }, - &[shirabe_php_shim::PhpMixed::String(message.clone())], - )); + lines.push(if large { + format!(" {} ", message) + } else { + format!(" {} ", message) + }); len = std::cmp::max(Helper::width(&message) + (if large { 4 } else { 2 }), len); } @@ -65,13 +64,11 @@ impl FormatterHelper { let mut i = 0; while i < messages.len() { - messages[i] = shirabe_php_shim::sprintf( - "<%s>%s</%s>", - &[ - shirabe_php_shim::PhpMixed::String(style.to_string()), - shirabe_php_shim::PhpMixed::String(messages[i].clone()), - shirabe_php_shim::PhpMixed::String(style.to_string()), - ], + messages[i] = format!( + "<{}>{}</{}>", + shirabe_php_shim::PhpMixed::String(style.to_string()), + shirabe_php_shim::PhpMixed::String(messages[i].clone()), + shirabe_php_shim::PhpMixed::String(style.to_string()), ); i += 1; } diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs index b599f11..3122f82 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs @@ -110,31 +110,18 @@ impl Helper { pub fn format_memory(memory: i64) -> String { if memory >= 1024 * 1024 * 1024 { - return shirabe_php_shim::sprintf( - "%.1f GiB", - &[shirabe_php_shim::PhpMixed::Float( - memory as f64 / 1024.0 / 1024.0 / 1024.0, - )], - ); + return format!("{:.1} GiB", memory as f64 / 1024.0 / 1024.0 / 1024.0,); } if memory >= 1024 * 1024 { - return shirabe_php_shim::sprintf( - "%.1f MiB", - &[shirabe_php_shim::PhpMixed::Float( - memory as f64 / 1024.0 / 1024.0, - )], - ); + return format!("{:.1} MiB", memory as f64 / 1024.0 / 1024.0,); } if memory >= 1024 { - return shirabe_php_shim::sprintf( - "%d KiB", - &[shirabe_php_shim::PhpMixed::Int(memory / 1024)], - ); + return format!("{} KiB", shirabe_php_shim::PhpMixed::Int(memory / 1024),); } - shirabe_php_shim::sprintf("%d B", &[shirabe_php_shim::PhpMixed::Int(memory)]) + format!("{} B", shirabe_php_shim::PhpMixed::Int(memory)) } /// @deprecated since Symfony 5.3 diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/helper_set.rs b/crates/shirabe-external-packages/src/symfony/console/helper/helper_set.rs index a7ef820..292a7a4 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/helper_set.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/helper_set.rs @@ -60,9 +60,9 @@ impl HelperSet { if !self.has(name) { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The helper \"%s\" is not defined.", - &[shirabe_php_shim::PhpMixed::String(name.to_string())], + message: format!( + "The helper \"{}\" is not defined.", + shirabe_php_shim::PhpMixed::String(name.to_string()), ), code: 0, }, diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs index 7652cac..bd26003 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs @@ -95,11 +95,9 @@ impl ProcessHelper { } None => { anyhow::bail!(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Invalid command provided to \"%s()\": the command should be an array whose first element is either the path to the binary to run or a \"Process\" object.", - &[shirabe_php_shim::PhpMixed::String( - "ProcessHelper::run".to_string() - )], + message: format!( + "Invalid command provided to \"{}()\": the command should be an array whose first element is either the path to the binary to run or a \"Process\" object.", + shirabe_php_shim::PhpMixed::String("ProcessHelper::run".to_string()), ), code: 0, }); @@ -130,12 +128,12 @@ impl ProcessHelper { let message = if process.is_successful() { "Command ran successfully".to_string() } else { - shirabe_php_shim::sprintf( - "%s Command did not run successfully", - &[match process.get_exit_code() { + format!( + "{} Command did not run successfully", + match process.get_exit_code() { Some(code) => shirabe_php_shim::PhpMixed::Int(code), None => shirabe_php_shim::PhpMixed::Null, - }], + }, ) }; let stopped = Self::formatter_stop( @@ -151,11 +149,9 @@ impl ProcessHelper { if !process.is_successful() && error.is_some() { output.borrow().writeln( - &[shirabe_php_shim::sprintf( - "<error>%s</error>", - &[shirabe_php_shim::PhpMixed::String( - self.escape_string(error.unwrap()), - )], + &[format!( + "<error>{}</error>", + shirabe_php_shim::PhpMixed::String(self.escape_string(error.unwrap()),), )], output_interface::OUTPUT_NORMAL, ); diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs b/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs index bd6fe86..f14e53a 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs @@ -815,9 +815,9 @@ impl ProgressBar { shirabe_php_shim::PhpMixed::String(s) => s, shirabe_php_shim::PhpMixed::Int(i) => i.to_string(), shirabe_php_shim::PhpMixed::Float(f) => { - shirabe_php_shim::sprintf("%s", &[shirabe_php_shim::PhpMixed::Float(f)]) + format!("{}", shirabe_php_shim::PhpMixed::Float(f)) } - other => shirabe_php_shim::sprintf("%s", &[other]), + other => format!("{}", other), }) }; diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs index 7ddb620..dcd761c 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs @@ -301,9 +301,10 @@ impl QuestionHelper { let padding = shirabe_php_shim::str_repeat(" ", (max_width - Helper::width(key)) as usize); - messages.push(shirabe_php_shim::sprintf( - &format!(" [<{tag}>%s{padding}</{tag}>] %s"), - &[PhpMixed::String(key.clone()), (**value).clone()], + messages.push(format!( + " [<{tag}>{}{padding}</{tag}>] {}", + PhpMixed::String(key.clone()), + (**value).clone(), )); } diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs index dd14513..9b388d9 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs @@ -32,33 +32,31 @@ impl SymfonyQuestionHelper { let default = question.get_default(); if question.is_multiline() { - text += &shirabe_php_shim::sprintf( - " (press %s to continue)", - &[PhpMixed::String(self.get_eof_shortcut())], + text += &format!( + " (press {} to continue)", + PhpMixed::String(self.get_eof_shortcut()), ); } // switch (true) if matches!(default, PhpMixed::Null) { - text = shirabe_php_shim::sprintf(" <info>%s</info>:", &[PhpMixed::String(text)]); + text = format!(" <info>{}</info>:", PhpMixed::String(text)); } else if question .as_any() .downcast_ref::<ConfirmationQuestion>() .is_some() { - text = shirabe_php_shim::sprintf( - " <info>%s (yes/no)</info> [<comment>%s</comment>]:", - &[ - PhpMixed::String(text), - PhpMixed::String( - if shirabe_php_shim::boolval(&default) { - "yes" - } else { - "no" - } - .to_string(), - ), - ], + text = format!( + " <info>{} (yes/no)</info> [<comment>{}</comment>]:", + PhpMixed::String(text), + PhpMixed::String( + if shirabe_php_shim::boolval(&default) { + "yes" + } else { + "no" + } + .to_string(), + ), ); } else if let Some(choice_question) = question .as_any() @@ -78,38 +76,32 @@ impl SymfonyQuestionHelper { }) .collect(); - text = shirabe_php_shim::sprintf( - " <info>%s</info> [<comment>%s</comment>]:", - &[ - PhpMixed::String(text), - PhpMixed::String(OutputFormatter::escape(&resolved.join(", ")).unwrap()), - ], + text = format!( + " <info>{}</info> [<comment>{}</comment>]:", + PhpMixed::String(text), + PhpMixed::String(OutputFormatter::escape(&resolved.join(", ")).unwrap()), ); } else if let Some(choice_question) = question.as_any().downcast_ref::<ChoiceQuestion>() { let choices = choice_question.get_choices(); - text = shirabe_php_shim::sprintf( - " <info>%s</info> [<comment>%s</comment>]:", - &[ - PhpMixed::String(text), - PhpMixed::String( - OutputFormatter::escape( - &choices - .get(&default.to_string()) - .map(|v| (**v).clone()) - .unwrap_or(default.clone()) - .to_string(), - ) - .unwrap(), - ), - ], + text = format!( + " <info>{}</info> [<comment>{}</comment>]:", + PhpMixed::String(text), + PhpMixed::String( + OutputFormatter::escape( + &choices + .get(&default.to_string()) + .map(|v| (**v).clone()) + .unwrap_or(default.clone()) + .to_string(), + ) + .unwrap(), + ), ); } else { - text = shirabe_php_shim::sprintf( - " <info>%s</info> [<comment>%s</comment>]:", - &[ - PhpMixed::String(text), - PhpMixed::String(OutputFormatter::escape(&default.to_string()).unwrap()), - ], + text = format!( + " <info>{}</info> [<comment>{}</comment>]:", + PhpMixed::String(text), + PhpMixed::String(OutputFormatter::escape(&default.to_string()).unwrap()), ); } diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs index 6f52458..5189efd 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs @@ -119,10 +119,7 @@ impl Table { Ok(Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Style \"%s\" is not defined.", - &[PhpMixed::from(name)], - ), + message: format!("Style \"{}\" is not defined.", PhpMixed::from(name),), code: 0, }, ))) @@ -271,12 +268,10 @@ impl Table { ) -> anyhow::Result<Result<&mut Self, RuntimeException>> { if !Self::output_is_console_section(&self.output) { return Ok(Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: shirabe_php_shim::sprintf( - "Output should be an instance of \"%s\" when calling \"%s\".", - &[ - PhpMixed::from("Symfony\\Component\\Console\\Output\\ConsoleSectionOutput"), - PhpMixed::from("Symfony\\Component\\Console\\Helper\\Table::appendRow"), - ], + message: format!( + "Output should be an instance of \"{}\" when calling \"{}\".", + PhpMixed::from("Symfony\\Component\\Console\\Output\\ConsoleSectionOutput"), + PhpMixed::from("Symfony\\Component\\Console\\Helper\\Table::appendRow"), ), code: 0, }))); @@ -1239,10 +1234,7 @@ impl Table { Ok(Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Style \"%s\" is not defined.", - &[PhpMixed::from(name_str)], - ), + message: format!("Style \"{}\" is not defined.", PhpMixed::from(name_str),), code: 0, }, ))) diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs index d8d8339..13ac96f 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs @@ -36,9 +36,9 @@ impl TableCell { if !diff.is_empty() { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The TableCell does not support the following options: '%s'.", - &[shirabe_php_shim::PhpMixed::String(diff.join("', '"))], + message: format!( + "The TableCell does not support the following options: '{}'.", + shirabe_php_shim::PhpMixed::String(diff.join("', '")), ), code: 0, }, diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs index 9d41c45..a738670 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs @@ -52,9 +52,9 @@ impl TableCellStyle { if !diff.is_empty() { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The TableCellStyle does not support the following options: '%s'.", - &[shirabe_php_shim::PhpMixed::String(diff.join("', '"))], + message: format!( + "The TableCellStyle does not support the following options: '{}'.", + shirabe_php_shim::PhpMixed::String(diff.join("', '")), ), code: 0, }, @@ -69,11 +69,9 @@ impl TableCellStyle { if align_map(&align).is_none() { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Wrong align value. Value must be following: '%s'.", - &[shirabe_php_shim::PhpMixed::String( - align_map_keys().join("', '"), - )], + message: format!( + "Wrong align value. Value must be following: '{}'.", + shirabe_php_shim::PhpMixed::String(align_map_keys().join("', '"),), ), code: 0, }, |
