aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/script_alias_command.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-17 02:53:53 +0900
committernsfisis <nsfisis@gmail.com>2026-05-17 02:53:53 +0900
commita1c7e6908a26e10f6e1f23a51721664b5e2d838d (patch)
treec575c76f1b43359ed74913da4c6a2636643f1ba0 /crates/shirabe/src/command/script_alias_command.rs
parent7f606f36fef0c0467c3c0db3d0da33af486dae8a (diff)
downloadphp-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.tar.gz
php-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.tar.zst
php-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.zip
chore(style): cargo fmt
Diffstat (limited to 'crates/shirabe/src/command/script_alias_command.rs')
-rw-r--r--crates/shirabe/src/command/script_alias_command.rs81
1 files changed, 63 insertions, 18 deletions
diff --git a/crates/shirabe/src/command/script_alias_command.rs b/crates/shirabe/src/command/script_alias_command.rs
index ad26cd7..c5bacc4 100644
--- a/crates/shirabe/src/command/script_alias_command.rs
+++ b/crates/shirabe/src/command/script_alias_command.rs
@@ -1,14 +1,14 @@
//! ref: composer/src/Composer/Command/ScriptAliasCommand.php
-use anyhow::Result;
-use shirabe_external_packages::composer::pcre::preg::Preg;
-use shirabe_external_packages::symfony::console::input::input_interface::InputInterface;
-use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface;
-use shirabe_php_shim::{is_string, InvalidArgumentException, LogicException, PhpMixed};
use crate::command::base_command::BaseCommand;
use crate::console::input::input_argument::InputArgument;
use crate::console::input::input_option::InputOption;
use crate::util::platform::Platform;
+use anyhow::Result;
+use shirabe_external_packages::composer::pcre::preg::Preg;
+use shirabe_external_packages::symfony::console::input::input_interface::InputInterface;
+use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface;
+use shirabe_php_shim::{InvalidArgumentException, LogicException, PhpMixed, is_string};
pub struct ScriptAliasCommand {
inner: BaseCommand,
@@ -19,21 +19,30 @@ pub struct ScriptAliasCommand {
impl ScriptAliasCommand {
pub fn new(script: String, description: Option<String>, aliases: Vec<String>) -> Result<Self> {
- let description = description.unwrap_or_else(|| format!("Runs the {} script as defined in composer.json", script));
+ let description = description
+ .unwrap_or_else(|| format!("Runs the {} script as defined in composer.json", script));
for alias in &aliases {
if !is_string(&PhpMixed::String(alias.clone())) {
return Err(InvalidArgumentException {
- message: r#""scripts-aliases" element array values should contain only strings"#.to_string(),
+ message:
+ r#""scripts-aliases" element array values should contain only strings"#
+ .to_string(),
code: 0,
- }.into());
+ }
+ .into());
}
}
let mut inner = BaseCommand::new();
inner.ignore_validation_errors();
- Ok(Self { inner, script, description, aliases })
+ Ok(Self {
+ inner,
+ script,
+ description,
+ aliases,
+ })
}
pub fn configure(&mut self) {
@@ -42,18 +51,42 @@ impl ScriptAliasCommand {
.set_description(&self.description)
.set_aliases(self.aliases.clone())
.set_definition(vec![
- InputOption::new("dev", None, Some(InputOption::VALUE_NONE), "Sets the dev mode.", None, vec![]),
- InputOption::new("no-dev", None, Some(InputOption::VALUE_NONE), "Disables the dev mode.", None, vec![]),
- InputArgument::new("args", Some(InputArgument::IS_ARRAY | InputArgument::OPTIONAL), "", None, vec![]),
+ InputOption::new(
+ "dev",
+ None,
+ Some(InputOption::VALUE_NONE),
+ "Sets the dev mode.",
+ None,
+ vec![],
+ ),
+ InputOption::new(
+ "no-dev",
+ None,
+ Some(InputOption::VALUE_NONE),
+ "Disables the dev mode.",
+ None,
+ vec![],
+ ),
+ InputArgument::new(
+ "args",
+ Some(InputArgument::IS_ARRAY | InputArgument::OPTIONAL),
+ "",
+ None,
+ vec![],
+ ),
])
.set_help(
"The <info>run-script</info> command runs scripts defined in composer.json:\n\n\
<info>php composer.phar run-script post-update-cmd</info>\n\n\
- Read more at https://getcomposer.org/doc/03-cli.md#run-script-run"
+ Read more at https://getcomposer.org/doc/03-cli.md#run-script-run",
);
}
- pub fn execute(&mut self, input: &dyn InputInterface, _output: &dyn OutputInterface) -> Result<i64> {
+ pub fn execute(
+ &mut self,
+ input: &dyn InputInterface,
+ _output: &dyn OutputInterface,
+ ) -> Result<i64> {
let composer = self.inner.require_composer()?;
let args = input.get_arguments();
@@ -61,9 +94,13 @@ impl ScriptAliasCommand {
// TODO remove for Symfony 6+ as it is then in the interface
if !input.has_to_string() {
return Err(LogicException {
- message: format!("Expected an Input instance that is stringable, got {}", input.get_class_name()),
+ message: format!(
+ "Expected an Input instance that is stringable, got {}",
+ input.get_class_name()
+ ),
code: 0,
- }.into());
+ }
+ .into());
}
let dev_mode = input.get_option("dev").as_bool().unwrap_or(false)
@@ -73,10 +110,18 @@ impl ScriptAliasCommand {
let script_alias_input = Preg::replace_limit(r"^\S+ ?", "", &input.to_string(), 1);
let mut flags = indexmap::IndexMap::new();
- flags.insert("script-alias-input".to_string(), PhpMixed::String(script_alias_input));
+ flags.insert(
+ "script-alias-input".to_string(),
+ PhpMixed::String(script_alias_input),
+ );
let args_value = args.get("args").cloned().unwrap_or(PhpMixed::Null);
- Ok(composer.get_event_dispatcher().dispatch_script(&self.script, dev_mode, args_value, flags)?)
+ Ok(composer.get_event_dispatcher().dispatch_script(
+ &self.script,
+ dev_mode,
+ args_value,
+ flags,
+ )?)
}
}