From ce0a00ee26de6afe3e6de2dff01e782eda687a4a Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 30 Jul 2024 18:34:19 +0200 Subject: [PATCH] Add a function for executing hooks --- scripts/Windows/Scripts/Hooks.ps1 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 scripts/Windows/Scripts/Hooks.ps1 diff --git a/scripts/Windows/Scripts/Hooks.ps1 b/scripts/Windows/Scripts/Hooks.ps1 new file mode 100644 index 00000000..78843f83 --- /dev/null +++ b/scripts/Windows/Scripts/Hooks.ps1 @@ -0,0 +1,26 @@ +function Invoke-Hook() { + param( + [string] $Name, + [System.Action] $Fallback + ) + + if ($Fallback) { + $scriptBlock = { $Fallback.Invoke(); }; + } else { + $scriptBlock = { }; + } + + if (Get-Command "$Name" -ErrorAction SilentlyContinue) { + $parameters = { + fallback = $scriptBlock + }; + + Write-Host "Running Hook ``$Name``"; + & "$Name" @parameters; + } elseif ($Fallback) { + Write-Host "Running Default of Hook ``$Name``"; + & $scriptBlock; + } else { + Write-Host "Hook ``$Name``"; + } +}