Add a function for executing hooks
This commit is contained in:
parent
855124c726
commit
ce0a00ee26
26
scripts/Windows/Scripts/Hooks.ps1
Normal file
26
scripts/Windows/Scripts/Hooks.ps1
Normal 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``";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue