scripts/Load-Resources.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
function Load-Resources {
    [CmdletBinding()]
    param (
        [Parameter(Position = 0, Mandatory = $false, ValueFromPipeline = $true)]
        [hashtable]$config = (Coalesce (Peek-Config), @{})
    )
    process {
        if (-not $config.resources) { return $config }

        $verbosity = $config.attributes.pwshake_verbosity
        try {
            if ((Peek-Verbosity) -gt [PWSHAKE.VerbosityLevel](${global:pwshake-context}.options.resources_verbosity)) {
                $config.attributes.pwshake_verbosity = ${global:pwshake-context}.options.resources_verbosity
            }
            'PWSHAKE resources:' | f-log-lvl -level ${global:pwshake-context}.options.resources_verbosity
            foreach ($step in $config.resources) {
                $step | Invoke-Step
            }
        }
        finally {
            $config.attributes.pwshake_verbosity = $verbosity
        }

        return $config
    }
}