# api: multitool
# title: dangerous action confirmation
# description: prompt prior executing irreversible scripts
# type: init 
# category: plugin
# state: beta
# priority: standard
# version: 0.1
# confirm: 1
# config: -
#
# Brings up a warning for scripts qualified with any of the meta flags:
#
#   # danger: 1
#   # confirm: 1
#   # cagegory: server
#
# Cancels the according script prior exection by overriding $e.command
#


#-- register as plugin before script start
$plugins.before += {
    if (($e.danger, $e.confirm, $e.dangerous, $e.category) -match "1|true|yes|server|danger") {
        $title = $e.title +  " / " + $e.description
        $OK = [System.Windows.MessageBox]::Show("Proceed with '$title'?", "Danger, Will Robinson!", "OKCancel", "Warning")
        if ($OK -ne "OK") {
            $e = @{
                command = 'Write-Host -f Red "Cancelled."'
            }
        }
    }
}
