aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/exec_command.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/command/exec_command.rs')
-rw-r--r--crates/shirabe/src/command/exec_command.rs80
1 files changed, 63 insertions, 17 deletions
diff --git a/crates/shirabe/src/command/exec_command.rs b/crates/shirabe/src/command/exec_command.rs
index 432e3a0..5602e85 100644
--- a/crates/shirabe/src/command/exec_command.rs
+++ b/crates/shirabe/src/command/exec_command.rs
@@ -3,7 +3,7 @@
use anyhow::Result;
use shirabe_external_packages::symfony::console::input::input_interface::InputInterface;
use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface;
-use shirabe_php_shim::{basename, chdir, getcwd, glob, PhpMixed, RuntimeException};
+use shirabe_php_shim::{PhpMixed, RuntimeException, basename, chdir, getcwd, glob};
use crate::command::base_command::BaseCommand;
use crate::console::input::input_argument::InputArgument;
@@ -43,13 +43,19 @@ impl ExecCommand {
);
}
- pub fn interact(&self, input: &mut dyn InputInterface, _output: &dyn OutputInterface) -> Result<()> {
+ pub fn interact(
+ &self,
+ input: &mut dyn InputInterface,
+ _output: &dyn OutputInterface,
+ ) -> Result<()> {
let binaries = self.get_binaries(false)?;
if binaries.is_empty() {
return Ok(());
}
- if input.get_argument("binary").as_string_opt().is_some() || input.get_option("list").as_bool().unwrap_or(false) {
+ if input.get_argument("binary").as_string_opt().is_some()
+ || input.get_option("list").as_bool().unwrap_or(false)
+ {
return Ok(());
}
@@ -70,45 +76,77 @@ impl ExecCommand {
Ok(())
}
- pub fn execute(&self, input: &dyn InputInterface, _output: &dyn OutputInterface) -> Result<i64> {
+ pub fn execute(
+ &self,
+ input: &dyn InputInterface,
+ _output: &dyn OutputInterface,
+ ) -> Result<i64> {
let composer = self.inner.require_composer()?;
- if input.get_option("list").as_bool().unwrap_or(false) || input.get_argument("binary").as_string_opt().is_none() {
+ if input.get_option("list").as_bool().unwrap_or(false)
+ || input.get_argument("binary").as_string_opt().is_none()
+ {
let bins = self.get_binaries(true)?;
if bins.is_empty() {
- let bin_dir = composer.get_config().get("bin-dir").as_string().unwrap_or("").to_string();
+ let bin_dir = composer
+ .get_config()
+ .get("bin-dir")
+ .as_string()
+ .unwrap_or("")
+ .to_string();
return Err(RuntimeException {
- message: format!("No binaries found in composer.json or in bin-dir ({})", bin_dir),
+ message: format!(
+ "No binaries found in composer.json or in bin-dir ({})",
+ bin_dir
+ ),
code: 0,
}
.into());
}
- self.inner.get_io().write("<comment>Available binaries:</comment>");
+ self.inner
+ .get_io()
+ .write("<comment>Available binaries:</comment>");
for bin in &bins {
- self.inner.get_io().write(&format!("<info>- {}</info>", bin));
+ self.inner
+ .get_io()
+ .write(&format!("<info>- {}</info>", bin));
}
return Ok(0);
}
- let binary = input.get_argument("binary").as_string().unwrap_or("").to_string();
+ let binary = input
+ .get_argument("binary")
+ .as_string()
+ .unwrap_or("")
+ .to_string();
let dispatcher = composer.get_event_dispatcher();
dispatcher.add_listener("__exec_command", &binary);
- let initial_working_directory = self.inner.get_application().get_initial_working_directory();
+ let initial_working_directory =
+ self.inner.get_application().get_initial_working_directory();
if let Some(ref iwd) = initial_working_directory {
if getcwd().as_deref() != Some(iwd.as_str()) {
- chdir(iwd).map_err(|e| {
- RuntimeException { message: format!("Could not switch back to working directory \"{}\"", iwd.display()), code: 0 }
+ chdir(iwd).map_err(|e| RuntimeException {
+ message: format!(
+ "Could not switch back to working directory \"{}\"",
+ iwd.display()
+ ),
+ code: 0,
})?;
}
}
- let args = input.get_argument("args")
+ let args = input
+ .get_argument("args")
.as_list()
- .map(|l| l.iter().filter_map(|v| v.as_string().map(|s| s.to_string())).collect::<Vec<_>>())
+ .map(|l| {
+ l.iter()
+ .filter_map(|v| v.as_string().map(|s| s.to_string()))
+ .collect::<Vec<_>>()
+ })
.unwrap_or_default();
Ok(dispatcher.dispatch_script("__exec_command", true, args)?)
@@ -116,11 +154,19 @@ impl ExecCommand {
fn get_binaries(&self, for_display: bool) -> Result<Vec<String>> {
let composer = self.inner.require_composer()?;
- let bin_dir = composer.get_config().get("bin-dir").as_string().unwrap_or("").to_string();
+ let bin_dir = composer
+ .get_config()
+ .get("bin-dir")
+ .as_string()
+ .unwrap_or("")
+ .to_string();
let bins = glob(&format!("{}/*", bin_dir));
let local_bins_raw: Vec<String> = composer.get_package().get_binaries();
let local_bins: Vec<String> = if for_display {
- local_bins_raw.into_iter().map(|e| format!("{} (local)", e)).collect()
+ local_bins_raw
+ .into_iter()
+ .map(|e| format!("{} (local)", e))
+ .collect()
} else {
local_bins_raw
};