ps/Modules/Alkami.PowerShell.Common/Public/Test-ShouldContinue.ps1
2023-05-30 22:51:22 -07:00

81 lines
2.9 KiB
PowerShell

function Test-ShouldContinue {
<#
.SYNOPSIS
A wrapper for PSCmdlet.ShouldContinue to enable Pester testing.
.DESCRIPTION
A wrapper for PSCmdlet.ShouldContinue to enable Pester testing.
.PARAMETER Query
Textual query of whether the action should be performed, usually in the form of a question.
.PARAMETER Caption
Caption of the window which may be displayed when the user is prompted whether or not to perform the action. It may be displayed by some hosts, but not all.
.PARAMETER HasSecurityImpact
true if the operation being confirmed has a security impact. If specified, the default option selected in the selection menu is 'No'.
.PARAMETER YesToAll
true if user selects YesToAll. If this is already true, ShouldContinue will bypass the prompt and return true.
.PARAMETER NoToAll
true if user selects NoToAll. If this is already true, ShouldContinue will bypass the prompt and return false.
.PARAMETER Force
When specified, always returns true. Added based on recommendations in the official documentation to support this option
.LINK
https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.cmdlet.shouldcontinue?view=powershellsdk-1.1.0
#>
[CmdletBinding(DefaultParameterSetName = 'SimpleSet')]
[OutputType([System.Boolean])]
param (
[Parameter(ParameterSetName = 'SimpleSet', Mandatory = $true)]
[Parameter(ParameterSetName = 'ToAllSet', Mandatory = $true)]
[Parameter(ParameterSetName = 'SecurityImpactSet', Mandatory = $true)]
[string]$Query,
[Parameter(ParameterSetName = 'SimpleSet', Mandatory = $true)]
[Parameter(ParameterSetName = 'ToAllSet', Mandatory = $true)]
[Parameter(ParameterSetName = 'SecurityImpactSet', Mandatory = $true)]
[string]$Caption,
[Parameter(ParameterSetName = 'SecurityImpactSet', Mandatory = $true)]
[bool]$HasSecurityImpact,
[Parameter(ParameterSetName = 'ToAllSet', Mandatory = $true)]
[Parameter(ParameterSetName = 'SecurityImpactSet', Mandatory = $true)]
[ref]$YesToAll,
[Parameter(ParameterSetName = 'ToAllSet', Mandatory = $true)]
[Parameter(ParameterSetName = 'SecurityImpactSet', Mandatory = $true)]
[ref]$NoToAll,
[Parameter(ParameterSetName = '__AllParameterSets', Mandatory = $false)]
[switch]$Force
)
if ($Force.IsPresent) {
return $true
}
$parameterSet = $PSCmdlet.ParameterSetName
if ($parameterSet -eq "SimpleSet") {
return $PSCmdlet.ShouldContinue($Query, $Caption)
}
if ($parameterSet -eq "ToAllSet") {
return $PSCmdlet.ShouldContinue($Query, $Caption, $YesToAll, $NoToAll)
}
if ($parameterSet -eq "SecurityImpactSet") {
return $PSCmdlet.ShouldContinue($Query, $Caption, $HasSecurityImpact, $YesToAll, $NoToAll)
}
}