Types/OpenPackage.Part/WriteYaml.ps1
|
<# .SYNOPSIS Writes Part Content as Yaml .DESCRIPTION Writes Open Package Part Content as Yaml .LINK https://github.com/jborean93/YaYaml .LINK https://www.powershellgallery.com/packages/YaYaml/ #> [Reflection.AssemblyMetadata( # This should automatically apply to .yaml files 'FilePattern', '\.ya?ml$' )] param( # The object to write. [Alias('Input','Content','Text')] [PSObject] $InputObject, <# Any options used to write the object Supported Options: |Option|Description| |-|-| |Depth|The serialization depth| |Encoding|The text encoding| |Stream|Optional destination stream| #> [Collections.IDictionary] $Option = [Ordered]@{} ) # If this object does not have a write text method, return. if (-not $this.WriteText) { throw 'No `.WriteText()`'; return } # If no depth was set, if (-not $option.Depth) { # use double the format enumeration limit (by default, 8) $option.Depth = $FormatEnumerationLimit * 2 } $ConvertToYaml = $executionContext.SessionState.InvokeCommand.GetCommand('ConvertTo-Yaml', 'Cmdlet,Function') if (-not $ConvertToYaml) { Write-Error "ConvertTo-Yaml not found, please install YaYaml" return } # If we have a .Package and .PartUri property if ($inputObject.Package -is [IO.Packaging.Package] -and $inputObject.PartUri -is [uri]) { # avoid putting them in the object $text = & $ConvertToYaml -InputObject ( $inputObject | Select-Object -Property * -ExcludeProperty 'Package', 'PartUri' ) -Depth $Option.Depth } else { # Convert any other objects to json. $text = & $ConvertToYaml -InputObject $inputObject -Depth $Option.Depth } if (-not $text) { return } $this.WriteText($text, $Option) |