Types/OpenPackage.Part/ReadYaml.ps1
|
<# .SYNOPSIS Reads Part Content as Yaml .DESCRIPTION Reads Package Part Content as Yaml .LINK https://yaml.org/ .LINK https://github.com/jborean93/PowerShell-Yayaml #> [Reflection.AssemblyMetadata( # This should automatically apply to .yaml files 'FilePattern', '\.ya?ml$' )] param( # An optional input object # If provided, content will be read from this object. # If not provided, content will be read from this part. [Alias('Input')] [PSObject]$InputObject = $null, # Any options used to read the data. [Alias('Options')] [Collections.IDictionary]$Option = [Ordered]@{} ) if (-not $this.ReadText) { return } $convertFromYamlCommand = $ExecutionContext.SessionState.InvokeCommand.GetCommand('ConvertFrom-Yaml', 'Cmdlet,Function') $partString = $this.ReadText($InputObject, $Option) if (-not $convertFromYamlCommand -or -not $convertFromYamlCommand.Parameters.InputObject) { Write-Warning "Convert-FromYaml not found, please install YaYaml" $partString } else { try { $partString | & $convertFromYamlCommand -ErrorAction Stop } catch { Write-Warning "'$($thisPart.Uri)' was not valid yaml: $_" } } |