scripts/Build-FromYaml.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function Build-FromYaml {
    [CmdletBinding()]
    param (
        [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
        [string]$path
    )
    process {
        $ErrorActionPreference = "Stop"

        try {
            $path = Resolve-Path $path
            return Get-Content $path -Raw | ConvertFrom-Yaml
        }
        catch [YamlDotNet.Core.YamlException] {
            throw "File '$path' is corrupted: $($_.Exception.InnerException.ToString().Split("`n")[0])"
        }
    }
}