aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console')
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/array_input.rs118
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs2
2 files changed, 58 insertions, 62 deletions
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 1ae7069d..9a19b839 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
@@ -130,67 +130,7 @@ impl ArrayInput {
default
}
-}
-
-/// Returns a stringified representation of the args passed to the command.
-impl std::fmt::Display for ArrayInput {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- let mut params: Vec<String> = vec![];
- for (param, val) in &self.parameters {
- // $param && \is_string($param) && '-' === $param[0]
- let is_option_key =
- matches!(param, PhpMixed::String(s) if !s.is_empty() && s.as_bytes()[0] == b'-');
- if is_option_key {
- let param = param.as_string().unwrap();
- let glue = if param.as_bytes().get(1) == Some(&b'-') {
- "="
- } else {
- " "
- };
- if let PhpMixed::List(list) = val {
- for v in list {
- let v = shirabe_php_shim::php_to_string(v);
- params.push(format!(
- "{}{}",
- param,
- if !v.is_empty() {
- format!("{}{}", glue, self.inner.escape_token(&v))
- } else {
- String::new()
- }
- ));
- }
- } else {
- let val = shirabe_php_shim::php_to_string(val);
- params.push(format!(
- "{}{}",
- param,
- if !val.is_empty() {
- format!("{}{}", glue, self.inner.escape_token(&val))
- } else {
- String::new()
- }
- ));
- }
- } else if let PhpMixed::List(list) = val {
- let escaped: Vec<String> = list
- .iter()
- .map(|v| self.inner.escape_token(&shirabe_php_shim::php_to_string(v)))
- .collect();
- params.push(shirabe_php_shim::implode(" ", &escaped));
- } else {
- params.push(
- self.inner
- .escape_token(&shirabe_php_shim::php_to_string(val)),
- );
- }
- }
-
- write!(f, "{}", shirabe_php_shim::implode(" ", &params))
- }
-}
-impl ArrayInput {
fn parse(&mut self) -> anyhow::Result<()> {
// Clone to avoid borrowing self while mutating; PHP iterates over a copy semantically.
let parameters = self.parameters.clone();
@@ -296,6 +236,64 @@ impl ArrayInput {
}
}
+/// Returns a stringified representation of the args passed to the command.
+impl std::fmt::Display for ArrayInput {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let mut params: Vec<String> = vec![];
+ for (param, val) in &self.parameters {
+ // $param && \is_string($param) && '-' === $param[0]
+ let is_option_key =
+ matches!(param, PhpMixed::String(s) if !s.is_empty() && s.as_bytes()[0] == b'-');
+ if is_option_key {
+ let param = param.as_string().unwrap();
+ let glue = if param.as_bytes().get(1) == Some(&b'-') {
+ "="
+ } else {
+ " "
+ };
+ if let PhpMixed::List(list) = val {
+ for v in list {
+ let v = shirabe_php_shim::php_to_string(v);
+ params.push(format!(
+ "{}{}",
+ param,
+ if !v.is_empty() {
+ format!("{}{}", glue, self.inner.escape_token(&v))
+ } else {
+ String::new()
+ }
+ ));
+ }
+ } else {
+ let val = shirabe_php_shim::php_to_string(val);
+ params.push(format!(
+ "{}{}",
+ param,
+ if !val.is_empty() {
+ format!("{}{}", glue, self.inner.escape_token(&val))
+ } else {
+ String::new()
+ }
+ ));
+ }
+ } else if let PhpMixed::List(list) = val {
+ let escaped: Vec<String> = list
+ .iter()
+ .map(|v| self.inner.escape_token(&shirabe_php_shim::php_to_string(v)))
+ .collect();
+ params.push(shirabe_php_shim::implode(" ", &escaped));
+ } else {
+ params.push(
+ self.inner
+ .escape_token(&shirabe_php_shim::php_to_string(val)),
+ );
+ }
+ }
+
+ write!(f, "{}", shirabe_php_shim::implode(" ", &params))
+ }
+}
+
impl InputInterface for ArrayInput {
fn dup(&self) -> std::rc::Rc<std::cell::RefCell<dyn InputInterface>> {
std::rc::Rc::new(std::cell::RefCell::new(self.clone()))
diff --git a/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs b/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs
index 9097faff..b62c2565 100644
--- a/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs
@@ -479,9 +479,7 @@ impl SymfonyStyle {
as Box<dyn Fn(Option<PhpMixed>) -> Result<PhpMixed, InvalidArgumentException>>
})
}
-}
-impl SymfonyStyle {
/// {@inheritdoc}
pub fn writeln(&mut self, messages: PhpMixed, r#type: i64) {
let messages: Vec<PhpMixed> = if !shirabe_php_shim::is_iterable(&messages) {