From 28ebed8021b56d0a81fdbf82c5260b01a6857e08 Mon Sep 17 00:00:00 2001 From: Konstantin Heil Date: Fri, 4 Jan 2019 10:33:55 +0100 Subject: [PATCH 1/7] Read Multiple Values for Common Key into Array --- PSIni/Functions/Get-IniContent.ps1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/PSIni/Functions/Get-IniContent.ps1 b/PSIni/Functions/Get-IniContent.ps1 index 6c7edcf..60db942 100644 --- a/PSIni/Functions/Get-IniContent.ps1 +++ b/PSIni/Functions/Get-IniContent.ps1 @@ -141,7 +141,15 @@ Function Get-IniContent { } $name, $value = $matches[1..2] Write-Verbose "$($MyInvocation.MyCommand.Name):: Adding key $name with value: $value" - $ini[$section][$name] = $value + if ($ini[$section][$name] -is [string]) { + $ini[$section][$name] = $ini[$section][$name], $value + } else { + if($ini[$section][$name] -is [array]) { + $ini[$section][$name] += $value + } else { + $ini[$section][$name] = $value + } + } continue } } From bee81d7e4f12a83ee11cf1b44b0614c4e1e878db Mon Sep 17 00:00:00 2001 From: Konstantin Heil Date: Fri, 4 Jan 2019 11:20:14 +0100 Subject: [PATCH 2/7] Write Array Entries in Multiple Lines --- PSIni/Functions/Out-IniFile.ps1 | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/PSIni/Functions/Out-IniFile.ps1 b/PSIni/Functions/Out-IniFile.ps1 index 9059054..9e4c6b1 100644 --- a/PSIni/Functions/Out-IniFile.ps1 +++ b/PSIni/Functions/Out-IniFile.ps1 @@ -153,7 +153,13 @@ Function Out-IniFile { } else { Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing key: $key" - Add-Content -Value "$key$delimiter$($InputObject[$key])" -Encoding $Encoding -Path $Path + if ($InputObject[$key] -is [string]) { + Add-Content -Value "$key$delimiter$($InputObject[$key])" -Encoding $Encoding -Path $Path + } else { + Foreach ($value in $InputObject[$key]) { + Add-Content -Value "$key$delimiter$($value)" -Encoding $Encoding -Path $Path + } + } } } } @@ -194,13 +200,13 @@ Function Out-IniFile { Add-Content -Value "$i$delimiter$($InputObject[$i])" @parameters } - elseif ($i -eq $script:NoSection) { - #Key value pair of NoSection - Out-Keys $InputObject[$i] ` - @parameters ` - -Delimiter $delimiter ` - -MyInvocation $MyInvocation - } +# elseif ($i -eq $script:NoSection) { +# #Key value pair of NoSection +# Out-Keys $InputObject[$i] ` +# @parameters ` +# -Delimiter $delimiter ` +# -MyInvocation $MyInvocation +# } else { #Sections Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing Section: [$i]" From ab1cb5c8a999bb32b71d1f711c36ce4bc09ad127 Mon Sep 17 00:00:00 2001 From: Konstantin Heil Date: Fri, 4 Jan 2019 11:45:48 +0100 Subject: [PATCH 3/7] Remove Comment from Debug --- PSIni/Functions/Out-IniFile.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/PSIni/Functions/Out-IniFile.ps1 b/PSIni/Functions/Out-IniFile.ps1 index 9e4c6b1..4a69f99 100644 --- a/PSIni/Functions/Out-IniFile.ps1 +++ b/PSIni/Functions/Out-IniFile.ps1 @@ -200,13 +200,13 @@ Function Out-IniFile { Add-Content -Value "$i$delimiter$($InputObject[$i])" @parameters } -# elseif ($i -eq $script:NoSection) { -# #Key value pair of NoSection -# Out-Keys $InputObject[$i] ` -# @parameters ` -# -Delimiter $delimiter ` -# -MyInvocation $MyInvocation -# } + elseif ($i -eq $script:NoSection) { + #Key value pair of NoSection + Out-Keys $InputObject[$i] ` + @parameters ` + -Delimiter $delimiter ` + -MyInvocation $MyInvocation + } else { #Sections Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing Section: [$i]" From 890f74e71e456d0d5ef888a1595b4f4f69e18147 Mon Sep 17 00:00:00 2001 From: Konstantin Heil Date: Fri, 4 Jan 2019 14:18:36 +0100 Subject: [PATCH 4/7] Incorporate Feedback from PR 43 --- PSIni/Functions/Get-IniContent.ps1 | 8 ++------ PSIni/Functions/Out-IniFile.ps1 | 10 +++------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/PSIni/Functions/Get-IniContent.ps1 b/PSIni/Functions/Get-IniContent.ps1 index 60db942..e321840 100644 --- a/PSIni/Functions/Get-IniContent.ps1 +++ b/PSIni/Functions/Get-IniContent.ps1 @@ -141,14 +141,10 @@ Function Get-IniContent { } $name, $value = $matches[1..2] Write-Verbose "$($MyInvocation.MyCommand.Name):: Adding key $name with value: $value" - if ($ini[$section][$name] -is [string]) { - $ini[$section][$name] = $ini[$section][$name], $value + if (-not $ini[$section][$name]) { + $ini[$section][$name] = @($value) } else { - if($ini[$section][$name] -is [array]) { $ini[$section][$name] += $value - } else { - $ini[$section][$name] = $value - } } continue } diff --git a/PSIni/Functions/Out-IniFile.ps1 b/PSIni/Functions/Out-IniFile.ps1 index 4a69f99..d018b71 100644 --- a/PSIni/Functions/Out-IniFile.ps1 +++ b/PSIni/Functions/Out-IniFile.ps1 @@ -153,13 +153,9 @@ Function Out-IniFile { } else { Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing key: $key" - if ($InputObject[$key] -is [string]) { - Add-Content -Value "$key$delimiter$($InputObject[$key])" -Encoding $Encoding -Path $Path - } else { - Foreach ($value in $InputObject[$key]) { - Add-Content -Value "$key$delimiter$($value)" -Encoding $Encoding -Path $Path - } - } + $InputObject[$key] | + ForEach-Object { "$key$delimiter$_)" } | + Add-Content -Encoding $Encoding -Path $Path } } } From 23c84f9c1ce7ba86a881f30573683ea04749f73e Mon Sep 17 00:00:00 2001 From: Konstantin Heil Date: Fri, 4 Jan 2019 14:22:27 +0100 Subject: [PATCH 5/7] Correct Typo --- PSIni/Functions/Out-IniFile.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSIni/Functions/Out-IniFile.ps1 b/PSIni/Functions/Out-IniFile.ps1 index d018b71..b6e6653 100644 --- a/PSIni/Functions/Out-IniFile.ps1 +++ b/PSIni/Functions/Out-IniFile.ps1 @@ -154,7 +154,7 @@ Function Out-IniFile { else { Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing key: $key" $InputObject[$key] | - ForEach-Object { "$key$delimiter$_)" } | + ForEach-Object { "$key$delimiter$_" } | Add-Content -Encoding $Encoding -Path $Path } } From f9bd5ccba6e63d273fe20ed0e77c3f30534cec3b Mon Sep 17 00:00:00 2001 From: Konstantin Heil Date: Fri, 4 Jan 2019 14:36:49 +0100 Subject: [PATCH 6/7] Check Array Entries in Test --- Tests/PsIni.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/PsIni.Tests.ps1 b/Tests/PsIni.Tests.ps1 index c392710..4c17a0e 100644 --- a/Tests/PsIni.Tests.ps1 +++ b/Tests/PsIni.Tests.ps1 @@ -40,7 +40,7 @@ Describe "PsIni functionality" { $dictIn["Category1"]["Key1"] = "Value1" $dictIn["Category1"]["Key2"] = "Value2" $dictIn["Category2"] = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase) - $dictIn["Category2"]["Key3"] = "Value3" + $dictIn["Category2"]["Key3"] = @("Value3.1", "Value3.2") $dictIn["Category2"]["Key4"] = "Value4" Context "Load Module" { @@ -69,7 +69,7 @@ Describe "PsIni functionality" { # assert It "content matches expected value" { - $content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n[Category2]`r`nKey3=Value3`r`nKey4=Value4`r`n" + $content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n[Category2]`r`nKey3=Value3.1`r`nKey3=Value3.2`r`nKey4=Value4`r`n" Get-Content $iniFile -Raw | Should Be $content @@ -91,7 +91,7 @@ Describe "PsIni functionality" { # assert It "content matches expected value" { - $content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n`r`n[Category2]`r`nKey3=Value3`r`nKey4=Value4`r`n" + $content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n`r`n[Category2]`r`nKey3=Value3.1`r`nKey3=Value3.2`r`nKey4=Value4`r`n" Get-Content $iniFile -Raw | Should Be $content From 273e2c5e366aa8fce023fb903f406063fda153e9 Mon Sep 17 00:00:00 2001 From: Konstantin Heil Date: Fri, 4 Jan 2019 18:07:04 +0100 Subject: [PATCH 7/7] Assure that Array is Flat with Test --- Tests/PsIni.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/PsIni.Tests.ps1 b/Tests/PsIni.Tests.ps1 index 4c17a0e..0853d3c 100644 --- a/Tests/PsIni.Tests.ps1 +++ b/Tests/PsIni.Tests.ps1 @@ -40,7 +40,7 @@ Describe "PsIni functionality" { $dictIn["Category1"]["Key1"] = "Value1" $dictIn["Category1"]["Key2"] = "Value2" $dictIn["Category2"] = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase) - $dictIn["Category2"]["Key3"] = @("Value3.1", "Value3.2") + $dictIn["Category2"]["Key3"] = @("Value3.1", "Value3.2", "Value3.3") $dictIn["Category2"]["Key4"] = "Value4" Context "Load Module" { @@ -69,7 +69,7 @@ Describe "PsIni functionality" { # assert It "content matches expected value" { - $content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n[Category2]`r`nKey3=Value3.1`r`nKey3=Value3.2`r`nKey4=Value4`r`n" + $content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n[Category2]`r`nKey3=Value3.1`r`nKey3=Value3.2`r`nKey3=Value3.3`r`nKey4=Value4`r`n" Get-Content $iniFile -Raw | Should Be $content @@ -91,7 +91,7 @@ Describe "PsIni functionality" { # assert It "content matches expected value" { - $content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n`r`n[Category2]`r`nKey3=Value3.1`r`nKey3=Value3.2`r`nKey4=Value4`r`n" + $content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n`r`n[Category2]`r`nKey3=Value3.1`r`nKey3=Value3.2`r`nKey3=Value3.3`r`nKey4=Value4`r`n" Get-Content $iniFile -Raw | Should Be $content