| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Expands an object into a formatted string for display. |
| | 4 | | .DESCRIPTION |
| | 5 | | This function takes an object and formats it for display in the console. It includes the type name and the objec |
| | 6 | | If a label is provided, it prefixes the output with the label. |
| | 7 | | .PARAMETER InputObject |
| | 8 | | The object to expand and display. This can be any PowerShell object, including complex types. |
| | 9 | | .PARAMETER ForegroundColor |
| | 10 | | The color to use for the output text in the console. If not specified, defaults to the console's current foregro |
| | 11 | | .PARAMETER Label |
| | 12 | | An optional label to prefix the output. This can be used to provide context or a name for the object being displ |
| | 13 | | .EXAMPLE |
| | 14 | | Expand-KrObject -InputObject $myObject -ForegroundColor Cyan -Label "My Object" |
| | 15 | | Displays the $myObject with a cyan foreground color and prefixes it with "My Object". |
| | 16 | | .NOTES |
| | 17 | | This function is designed to be used in the context of Kestrun for debugging or logging purposes. |
| | 18 | | #> |
| | 19 | | function Expand-KrObject { |
| | 20 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')] |
| | 21 | | [KestrunRuntimeApi('Everywhere')] |
| | 22 | | [CmdletBinding()] |
| | 23 | | param( |
| | 24 | | [Parameter(Position = 0, ValueFromPipeline = $true)] |
| | 25 | | [object] $InputObject, |
| | 26 | | [Parameter()] |
| | 27 | | [System.ConsoleColor] $ForegroundColor, |
| | 28 | | [Parameter()] |
| | 29 | | [string] $Label |
| | 30 | | ) |
| | 31 | |
|
| | 32 | | process { |
| | 33 | |
|
| 0 | 34 | | if ($null -eq $InputObject) { |
| 0 | 35 | | $InputObject = "`tNull Value" |
| | 36 | | } else { |
| 0 | 37 | | $type = $InputObject.gettype().FullName |
| 0 | 38 | | $InputObject = $InputObject | Out-String |
| 0 | 39 | | $InputObject = "`tTypeName: $type`n$InputObject" |
| | 40 | | } |
| 0 | 41 | | if ($Label) { |
| 0 | 42 | | $InputObject = "`tName: $Label $InputObject" |
| | 43 | | } |
| | 44 | |
|
| 0 | 45 | | if ($ForegroundColor) { |
| 0 | 46 | | if ($pipelineValue.Count -gt 1) { |
| 0 | 47 | | $InputObject | Write-Host -ForegroundColor $ForegroundColor |
| | 48 | | } else { |
| 0 | 49 | | Write-Host -Object $InputObject -ForegroundColor $ForegroundColor |
| | 50 | | } |
| | 51 | | } else { |
| 0 | 52 | | if ($pipelineValue.Count -gt 1) { |
| 0 | 53 | | $InputObject | Write-Host |
| | 54 | | } else { |
| 0 | 55 | | Write-Host -Object $InputObject |
| | 56 | | } |
| | 57 | | } |
| | 58 | | } |
| | 59 | | } |
| | 60 | |
|