aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/io
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/io')
-rw-r--r--crates/shirabe/src/io/base_io.rs27
-rw-r--r--crates/shirabe/src/io/buffer_io.rs21
-rw-r--r--crates/shirabe/src/io/console_io.rs53
-rw-r--r--crates/shirabe/src/io/io_interface.rs29
-rw-r--r--crates/shirabe/src/io/mod.rs5
-rw-r--r--crates/shirabe/src/io/null_io.rs37
6 files changed, 114 insertions, 58 deletions
diff --git a/crates/shirabe/src/io/base_io.rs b/crates/shirabe/src/io/base_io.rs
index f1cff3c..58d1e40 100644
--- a/crates/shirabe/src/io/base_io.rs
+++ b/crates/shirabe/src/io/base_io.rs
@@ -1,16 +1,16 @@
//! ref: composer/src/Composer/IO/BaseIO.php
+use crate::config::Config;
+use crate::io::io_interface::IOInterface;
+use crate::util::process_executor::ProcessExecutor;
+use crate::util::silencer::Silencer;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::preg::Preg;
use shirabe_external_packages::psr::log::log_level::LogLevel;
use shirabe_php_shim::{
- array_merge, in_array, json_encode_ex, PhpMixed, UnexpectedValueException,
- JSON_INVALID_UTF8_IGNORE, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE,
+ JSON_INVALID_UTF8_IGNORE, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, PhpMixed,
+ UnexpectedValueException, array_merge, in_array, json_encode_ex,
};
-use crate::config::Config;
-use crate::io::io_interface::IOInterface;
-use crate::util::process_executor::ProcessExecutor;
-use crate::util::silencer::Silencer;
#[derive(Debug)]
pub struct BaseIO {
@@ -344,20 +344,15 @@ impl BaseIO {
let mut ssl_options: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
if let Some(cert) = local_cert {
- ssl_options.insert(
- "local_cert".to_string(),
- Box::new(PhpMixed::String(cert)),
- );
+ ssl_options
+ .insert("local_cert".to_string(), Box::new(PhpMixed::String(cert)));
}
if let Some(pk) = local_pk {
- ssl_options
- .insert("local_pk".to_string(), Box::new(PhpMixed::String(pk)));
+ ssl_options.insert("local_pk".to_string(), Box::new(PhpMixed::String(pk)));
}
if let Some(pass) = passphrase {
- ssl_options.insert(
- "passphrase".to_string(),
- Box::new(PhpMixed::String(pass)),
- );
+ ssl_options
+ .insert("passphrase".to_string(), Box::new(PhpMixed::String(pass)));
}
if !ssl_options.contains_key("local_cert") {
diff --git a/crates/shirabe/src/io/buffer_io.rs b/crates/shirabe/src/io/buffer_io.rs
index 30e2aeb..aa1d970 100644
--- a/crates/shirabe/src/io/buffer_io.rs
+++ b/crates/shirabe/src/io/buffer_io.rs
@@ -1,5 +1,6 @@
//! ref: composer/src/Composer/IO/BufferIO.php
+use crate::io::console_io::ConsoleIO;
use anyhow::Result;
use shirabe_external_packages::composer::pcre::preg::Preg;
use shirabe_external_packages::symfony::console::formatter::output_formatter_interface::OutputFormatterInterface;
@@ -8,8 +9,10 @@ use shirabe_external_packages::symfony::console::helper::question_helper::Questi
use shirabe_external_packages::symfony::console::input::streamable_input_interface::StreamableInputInterface;
use shirabe_external_packages::symfony::console::input::string_input::StringInput;
use shirabe_external_packages::symfony::console::output::stream_output::StreamOutput;
-use shirabe_php_shim::{fopen, fseek, fwrite, rewind, stream_get_contents, strip_tags, PhpMixed, RuntimeException, PHP_EOL};
-use crate::io::console_io::ConsoleIO;
+use shirabe_php_shim::{
+ PHP_EOL, PhpMixed, RuntimeException, fopen, fseek, fwrite, rewind, stream_get_contents,
+ strip_tags,
+};
#[derive(Debug)]
pub struct BufferIO {
@@ -17,7 +20,11 @@ pub struct BufferIO {
}
impl BufferIO {
- pub fn new(input: String, verbosity: i64, formatter: Option<Box<dyn OutputFormatterInterface>>) -> Result<Self> {
+ pub fn new(
+ input: String,
+ verbosity: i64,
+ formatter: Option<Box<dyn OutputFormatterInterface>>,
+ ) -> Result<Self> {
let mut input_obj = StringInput::new(input);
input_obj.set_interactive(false);
@@ -66,7 +73,13 @@ impl BufferIO {
}
pub fn set_user_inputs(&mut self, inputs: Vec<String>) -> Result<()> {
- if self.inner.input.as_any().downcast_ref::<dyn StreamableInputInterface>().is_none() {
+ if self
+ .inner
+ .input
+ .as_any()
+ .downcast_ref::<dyn StreamableInputInterface>()
+ .is_none()
+ {
return Err(RuntimeException {
message: "Setting the user inputs requires at least the version 3.2 of the symfony/console component.".to_string(),
code: 0,
diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs
index 8dd9f0b..0794ca5 100644
--- a/crates/shirabe/src/io/console_io.rs
+++ b/crates/shirabe/src/io/console_io.rs
@@ -11,9 +11,9 @@ use shirabe_external_packages::symfony::component::console::output::output_inter
use shirabe_external_packages::symfony::component::console::question::choice_question::ChoiceQuestion;
use shirabe_external_packages::symfony::component::console::question::question::Question;
use shirabe_php_shim::{
- array_filter, array_keys, array_search, count, function_exists, implode, in_array, is_array,
- is_string, mb_check_encoding, mb_convert_encoding, microtime, sprintf, str_repeat, strip_tags,
- strlen, PhpMixed,
+ PhpMixed, array_filter, array_keys, array_search, count, function_exists, implode, in_array,
+ is_array, is_string, mb_check_encoding, mb_convert_encoding, microtime, sprintf, str_repeat,
+ strip_tags, strlen,
};
use crate::io::base_io::BaseIO;
@@ -158,7 +158,12 @@ impl ConsoleIO {
)
})
.collect();
- PhpMixed::List(mapped.into_iter().map(|s| Box::new(PhpMixed::String(s))).collect())
+ PhpMixed::List(
+ mapped
+ .into_iter()
+ .map(|s| Box::new(PhpMixed::String(s)))
+ .collect(),
+ )
} else {
messages
};
@@ -396,8 +401,8 @@ impl ConsoleIO {
PhpMixed::List(_) => vec![],
_ => vec![],
};
- let is_assoc = !choice_keys.is_empty()
- && choice_keys.iter().any(|k| !k.parse::<i64>().is_ok());
+ let is_assoc =
+ !choice_keys.is_empty() && choice_keys.iter().any(|k| !k.parse::<i64>().is_ok());
if is_assoc {
return result;
}
@@ -410,9 +415,7 @@ impl ConsoleIO {
PhpMixed::List(l) => l
.iter()
.enumerate()
- .filter_map(|(i, v)| {
- v.as_string().map(|s| (i.to_string(), s.to_string()))
- })
+ .filter_map(|(i, v)| v.as_string().map(|s| (i.to_string(), s.to_string())))
.collect(),
_ => IndexMap::new(),
};
@@ -431,11 +434,7 @@ impl ConsoleIO {
_ => vec![],
};
for (index, choice) in &choice_list {
- if in_array(
- choice.clone(),
- &PhpMixed::List(result_list.clone()),
- true,
- ) {
+ if in_array(choice.clone(), &PhpMixed::List(result_list.clone()), true) {
results.push(index.clone());
}
}
@@ -455,7 +454,9 @@ impl ConsoleIO {
fn get_error_output(&self) -> &dyn OutputInterface {
if self.output.is_console_output_interface() {
// TODO(phase-b): downcast Box<dyn OutputInterface> to ConsoleOutputInterface
- return todo!("downcast self.output to ConsoleOutputInterface and call get_error_output()");
+ return todo!(
+ "downcast self.output to ConsoleOutputInterface and call get_error_output()"
+ );
}
&*self.output
@@ -480,7 +481,10 @@ impl ConsoleIO {
let escape_pattern =
r"\x1B\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\x1B\].*?(?:\x1B\\|\x07)|\x1B.";
let pattern = if allow_newlines {
- format!("{{{}|[\\x01-\\x09\\x0B\\x0C\\x0E-\\x1A]|\\r(?!\\n)}}u", escape_pattern)
+ format!(
+ "{{{}|[\\x01-\\x09\\x0B\\x0C\\x0E-\\x1A]|\\r(?!\\n)}}u",
+ escape_pattern
+ )
} else {
format!("{{{}|[\\x01-\\x1A]}}u", escape_pattern)
};
@@ -495,15 +499,19 @@ impl ConsoleIO {
PhpMixed::List(l) => {
for (key, message) in l.iter().enumerate() {
let s = Self::ensure_valid_utf8(message.as_string().unwrap_or(""));
- sanitized
- .insert(key.to_string(), PhpMixed::String(Preg::replace(&pattern, "", &s)));
+ sanitized.insert(
+ key.to_string(),
+ PhpMixed::String(Preg::replace(&pattern, "", &s)),
+ );
}
}
PhpMixed::Array(a) => {
for (key, message) in a {
let s = Self::ensure_valid_utf8(message.as_string().unwrap_or(""));
- sanitized
- .insert(key.clone(), PhpMixed::String(Preg::replace(&pattern, "", &s)));
+ sanitized.insert(
+ key.clone(),
+ PhpMixed::String(Preg::replace(&pattern, "", &s)),
+ );
}
}
_ => {}
@@ -532,9 +540,8 @@ impl ConsoleIO {
// Fallback to iconv if mbstring unavailable
if function_exists("iconv") {
- let cleaned = Silencer::call(|| {
- Ok(shirabe_php_shim::iconv("UTF-8", "UTF-8//TRANSLIT", string))
- });
+ let cleaned =
+ Silencer::call(|| Ok(shirabe_php_shim::iconv("UTF-8", "UTF-8//TRANSLIT", string)));
if let Ok(Some(c)) = cleaned {
return c;
}
diff --git a/crates/shirabe/src/io/io_interface.rs b/crates/shirabe/src/io/io_interface.rs
index 1a6eb3f..446f47c 100644
--- a/crates/shirabe/src/io/io_interface.rs
+++ b/crates/shirabe/src/io/io_interface.rs
@@ -1,9 +1,9 @@
//! ref: composer/src/Composer/IO/IOInterface.php
+use crate::config::Config;
use indexmap::IndexMap;
-use shirabe_php_shim::PhpMixed;
use shirabe_external_packages::psr::log::logger_interface::LoggerInterface;
-use crate::config::Config;
+use shirabe_php_shim::PhpMixed;
pub trait IOInterface: LoggerInterface {
const QUIET: i64 = 1;
@@ -38,11 +38,25 @@ pub trait IOInterface: LoggerInterface {
fn ask_confirmation(&self, question: String, default: bool) -> bool;
- fn ask_and_validate(&self, question: String, validator: Box<dyn Fn(PhpMixed) -> PhpMixed>, attempts: Option<i64>, default: PhpMixed) -> PhpMixed;
+ fn ask_and_validate(
+ &self,
+ question: String,
+ validator: Box<dyn Fn(PhpMixed) -> PhpMixed>,
+ attempts: Option<i64>,
+ default: PhpMixed,
+ ) -> PhpMixed;
fn ask_and_hide_answer(&self, question: String) -> Option<String>;
- fn select(&self, question: String, choices: Vec<String>, default: PhpMixed, attempts: PhpMixed, error_message: String, multiselect: bool) -> PhpMixed;
+ fn select(
+ &self,
+ question: String,
+ choices: Vec<String>,
+ default: PhpMixed,
+ attempts: PhpMixed,
+ error_message: String,
+ multiselect: bool,
+ ) -> PhpMixed;
fn get_authentications(&self) -> IndexMap<String, IndexMap<String, Option<String>>>;
@@ -50,7 +64,12 @@ pub trait IOInterface: LoggerInterface {
fn get_authentication(&self, repository_name: &str) -> IndexMap<String, Option<String>>;
- fn set_authentication(&self, repository_name: String, username: String, password: Option<String>);
+ fn set_authentication(
+ &self,
+ repository_name: String,
+ username: String,
+ password: Option<String>,
+ );
fn load_configuration(&self, config: &Config);
}
diff --git a/crates/shirabe/src/io/mod.rs b/crates/shirabe/src/io/mod.rs
new file mode 100644
index 0000000..a75d459
--- /dev/null
+++ b/crates/shirabe/src/io/mod.rs
@@ -0,0 +1,5 @@
+pub mod base_io;
+pub mod buffer_io;
+pub mod console_io;
+pub mod io_interface;
+pub mod null_io;
diff --git a/crates/shirabe/src/io/null_io.rs b/crates/shirabe/src/io/null_io.rs
index ad41746..4218398 100644
--- a/crates/shirabe/src/io/null_io.rs
+++ b/crates/shirabe/src/io/null_io.rs
@@ -1,8 +1,8 @@
//! ref: composer/src/Composer/IO/NullIO.php
-use shirabe_php_shim::PhpMixed;
use crate::io::base_io::BaseIO;
use crate::io::io_interface::IOInterface;
+use shirabe_php_shim::PhpMixed;
#[derive(Debug)]
pub struct NullIO {
@@ -30,16 +30,19 @@ impl IOInterface for NullIO {
false
}
- fn write(&self, _messages: PhpMixed, _newline: bool, _verbosity: i64) {
- }
+ fn write(&self, _messages: PhpMixed, _newline: bool, _verbosity: i64) {}
- fn write_error(&self, _messages: PhpMixed, _newline: bool, _verbosity: i64) {
- }
+ fn write_error(&self, _messages: PhpMixed, _newline: bool, _verbosity: i64) {}
- fn overwrite(&self, _messages: PhpMixed, _newline: bool, _size: Option<i64>, _verbosity: i64) {
- }
+ fn overwrite(&self, _messages: PhpMixed, _newline: bool, _size: Option<i64>, _verbosity: i64) {}
- fn overwrite_error(&self, _messages: PhpMixed, _newline: bool, _size: Option<i64>, _verbosity: i64) {
+ fn overwrite_error(
+ &self,
+ _messages: PhpMixed,
+ _newline: bool,
+ _size: Option<i64>,
+ _verbosity: i64,
+ ) {
}
fn ask(&self, _question: String, default: PhpMixed) -> PhpMixed {
@@ -50,7 +53,13 @@ impl IOInterface for NullIO {
default
}
- fn ask_and_validate(&self, _question: String, _validator: Box<dyn Fn(PhpMixed) -> PhpMixed>, _attempts: Option<i64>, default: PhpMixed) -> PhpMixed {
+ fn ask_and_validate(
+ &self,
+ _question: String,
+ _validator: Box<dyn Fn(PhpMixed) -> PhpMixed>,
+ _attempts: Option<i64>,
+ default: PhpMixed,
+ ) -> PhpMixed {
default
}
@@ -58,7 +67,15 @@ impl IOInterface for NullIO {
None
}
- fn select(&self, _question: String, _choices: Vec<String>, default: PhpMixed, _attempts: PhpMixed, _error_message: String, _multiselect: bool) -> PhpMixed {
+ fn select(
+ &self,
+ _question: String,
+ _choices: Vec<String>,
+ default: PhpMixed,
+ _attempts: PhpMixed,
+ _error_message: String,
+ _multiselect: bool,
+ ) -> PhpMixed {
default
}
}