Skip to content

Commit 0ae6b73

Browse files
🩹 [Patch]: Improve input filtering logic in initialization script (#23)
## Description This pull request introduces a new filter function and makes some improvements to existing logging and input handling in PowerShell scripts. ### New filter function * Added `Show-Input` filter to `scripts/Helpers.psm1` to format and display hashtable inputs in a structured output. ### Improvements to logging and input handling * Updated `scripts/init.ps1` to use `Out-String` with `Format-List` for better logging output. * Replaced inline formatting with `Show-Input` filter for input handling in `scripts/init.ps1`. ### Configuration changes * Set `$PSStyle.OutputRendering` to 'Ansi' in `scripts/main.ps1` to ensure consistent output rendering style. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 98d5714 commit 0ae6b73

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

scripts/Helpers.psm1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,3 +900,40 @@ filter Set-PesterReportRunSummary {
900900
}
901901
}
902902
}
903+
904+
filter Show-Input {
905+
<#
906+
.SYNOPSIS
907+
Displays a formatted representation of a hashtable.
908+
909+
.DESCRIPTION
910+
This function takes a hashtable as input and formats it into a structured output.
911+
912+
.EXAMPLE
913+
Show-Input -Inputs @{ Key1 = 'Value1'; Key2 = 'Value2' }
914+
915+
.OUTPUTS
916+
string
917+
918+
.NOTES
919+
Returns a formatted string representation of the input hashtable.
920+
#>
921+
[outputType([string])]
922+
[CmdletBinding()]
923+
param(
924+
[Parameter(Mandatory, ValueFromPipeline)]
925+
[hashtable] $Inputs
926+
)
927+
928+
$new = [pscustomobject]@{}
929+
$Inputs.GetEnumerator() | Where-Object { -not [string]::IsNullOrEmpty($_.Value) } | ForEach-Object {
930+
$name = $_.Key
931+
$value = $_.Value
932+
if ($value -is [string]) {
933+
$new | Add-Member -MemberType NoteProperty -Name $name -Value $value
934+
} elseif ($value -is [array]) {
935+
$new | Add-Member -MemberType NoteProperty -Name $name -Value ($value -join ', ')
936+
}
937+
}
938+
[pscustomobject]$new | Format-List | Out-String
939+
}

scripts/init.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LogGroup 'Init - Get test kit versions' {
1515
[PSCustomObject]@{
1616
PowerShell = $PSVersionTable.PSVersion.ToString()
1717
Pester = $pesterModule.Version
18-
} | Format-List
18+
} | Format-List | Out-String
1919
}
2020

2121
LogGroup 'Init - Load inputs' {
@@ -84,7 +84,7 @@ LogGroup 'Init - Load inputs' {
8484
TestRegistry_Enabled = $env:PSMODULE_INVOKE_PESTER_INPUT_TestRegistry_Enabled
8585
}
8686

87-
[pscustomobject]($inputs.GetEnumerator() | Where-Object { -not [string]::IsNullOrEmpty($_.Value) }) | Format-List | Out-String
87+
Show-Input -Inputs $inputs
8888
}
8989

9090
LogGroup 'Init - Load configuration - Defaults' {

scripts/main.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[CmdletBinding()]
22
param()
33

4+
$PSStyle.OutputRendering = 'Ansi'
5+
46
'::group::Exec - Setup prerequisites'
57
'Pester' | ForEach-Object {
68
Install-PSResource -Name $_ -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery

0 commit comments

Comments
 (0)