functions/other/Set-PSUPrompt.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function Set-PSUPrompt
{
<#
    .SYNOPSIS
        Applies one of the pre-defined prompts.
     
    .DESCRIPTION
        Applies one of the pre-defined prompts.
     
    .PARAMETER Prompt
        The prompt to apply
     
    .PARAMETER EnableException
        This parameters disables user-friendly warnings and enables the throwing of exceptions.
        This is less user friendly, but allows catching exceptions in calling scripts.
     
    .EXAMPLE
        PS C:\> Set-PSUPrompt -Prompt fred
     
        Applies the prompt fred uses.
#>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string]
        $Prompt,
        
        [switch]
        $EnableException
    )
    
    process
    {
        if (-not (Test-Path "$script:ModuleRoot\internal\prompts\$Prompt.prompt.ps1"))
        {
            Stop-PSFFunction -Message "Failed to find prompt: $Prompt" -Target $Prompt -EnableException $EnableException -Category ObjectNotFound
            return
        }
        & "$script:ModuleRoot\internal\prompts\$Prompt.prompt.ps1"
    }
}