Add a function for executing hooks

This commit is contained in:
Manuel Thalmann 2024-07-30 18:34:19 +02:00
parent 855124c726
commit ce0a00ee26

View file

@ -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``";
}
}