summaryrefslogtreecommitdiff
path: root/src/integration/command.rs
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-06-25 20:50:13 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-06-25 20:50:13 +0300
commit12cce7deeb2d27f7b11daece75881fcfd88ea607 (patch)
tree843769b293a2e3cd9ad8c752637307741f6a702e /src/integration/command.rs
parent3c7327c267a352023797c8a13fd0b7f4a7a40591 (diff)
refactor: split integration module
Diffstat (limited to 'src/integration/command.rs')
-rw-r--r--src/integration/command.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/integration/command.rs b/src/integration/command.rs
new file mode 100644
index 00000000..a5d58f0c
--- /dev/null
+++ b/src/integration/command.rs
@@ -0,0 +1,48 @@
+use std::path::Path;
+
+pub(crate) fn shell_single_quote(value: &str) -> String {
+ format!("'{}'", value.replace('\'', "'\"'\"'"))
+}
+
+pub(crate) fn hook_command(hook_path: &Path, action: Option<&str>) -> String {
+ let path = hook_path.display().to_string();
+ #[cfg(windows)]
+ {
+ let mut command = format!(
+ "powershell -NoProfile -ExecutionPolicy Bypass -File {}",
+ windows_command_quote(&path)
+ );
+ if let Some(action) = action {
+ command.push(' ');
+ command.push_str(action);
+ }
+ command
+ }
+
+ #[cfg(not(windows))]
+ {
+ let mut command = format!("bash {}", shell_single_quote(&path));
+ if let Some(action) = action {
+ command.push(' ');
+ command.push_str(action);
+ }
+ command
+ }
+}
+
+pub(crate) fn legacy_bash_hook_command(hook_path: &Path, action: Option<&str>) -> String {
+ let mut command = format!(
+ "bash {}",
+ shell_single_quote(&hook_path.display().to_string())
+ );
+ if let Some(action) = action {
+ command.push(' ');
+ command.push_str(action);
+ }
+ command
+}
+
+#[cfg(windows)]
+fn windows_command_quote(value: &str) -> String {
+ format!("\"{}\"", value.replace('"', "\\\""))
+}