Skip to content

Commit 8d79515

Browse files
Merge pull request #22 from StartAutomating/PropertySetSupport
Property set support
2 parents 687401e + 0e6ded0 commit 8d79515

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

EZOut.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
ModuleToProcess = 'EZOut.psm1'
3-
ModuleVersion = '1.8.4'
3+
ModuleVersion = '1.8.5'
44
GUID = 'cef786f0-8a0b-4a5d-a2c6-b433095354cd'
55
Author = 'James Brundage'
66
CompanyName = 'Start-Automating'

EZOut.tests.ps1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,4 +1101,48 @@ describe 'Import-FormatView' {
11011101
Pop-Location
11021102
}
11031103
}
1104+
}
1105+
1106+
describe 'Import-TypeView' {
1107+
it 'Can create type files out of directories' {
1108+
$tmp =
1109+
if ($env:PIPELINE_WORKSPACE) { $env:PIPELINE_WORKSPACE }
1110+
elseif ($env:TEMP) { "$env:TEMP" }
1111+
else { "/$tmp" }
1112+
$tmpDir = New-Item -ItemType Directory -Path (Join-Path $tmp "$(Get-Random)")
1113+
$testTypeDir = New-Item -ItemType Directory -Path (Join-Path $tmpDir.FullName "TestType$($tmpDir.Name)")
1114+
Push-Location $testTypeDir.FullName
1115+
Set-Content get_Foo.txt Foo
1116+
Set-Content Alias.psd1 '@{Foo2="Foo"}'
1117+
Set-Content DefaultDisplay.txt RandomNumber
1118+
Set-Content get_RandomNumber.ps1 {Get-Random}
1119+
Set-Content set_RandomNumber.ps1 {$args}
1120+
Set-Content .HiddenProperty.txt Value
1121+
Set-Content XmlProperty.xml '<Message language="en-us">hello</Message>'
1122+
Set-Content DefaultDisplay.txt RandomNumber
1123+
'Foo', 'RandomNumber' -join [Environment]::NewLine |
1124+
Set-Content Example.PropertySet.txt
1125+
1126+
$typesXml =
1127+
[xml](Import-TypeView -FilePath $tmpDir.FullName | Out-TypeData)
1128+
1129+
$typesXml | Add-TypeData
1130+
$o = [PSCustomObject]@{PSTypeName=$testTypeDir.Name;N=1}
1131+
$o.RandomNumber | Should -BeGreaterThan 1
1132+
$o.HiddenProperty | Should -Be Value
1133+
Pop-Location
1134+
Remove-Item -Recurse -Force $tmpDir
1135+
Clear-TypeData
1136+
}
1137+
context 'Fault Tolerance' {
1138+
it 'Will error if the file does not exist' {
1139+
Get-Module EZOut |
1140+
Split-Path |
1141+
Join-Path -ChildPath Formatting |
1142+
Push-Location
1143+
1144+
{ Import-TypeView .\ThisFileDoesNotExist.types.xml -ErrorAction Stop } | should -Throw
1145+
Pop-Location
1146+
}
1147+
}
11041148
}

Import-TypeView.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
$eventNames = @()
109109
$scriptPropertyGet = [Ordered]@{}
110110
$scriptPropertySet = [Ordered]@{}
111+
$propertySets = [Ordered]@{}
111112
$aliasProperty = [Ordered]@{}
112113
$noteProperty = [Ordered]@{}
113114
$hideProperty = [Collections.Generic.List[string]]::new()
@@ -158,7 +159,7 @@
158159
$scriptPropertySet[$propertyName] = $scriptBlock
159160
}
160161
}
161-
elseif ($isScript -and # If this is a script and it's an event
162+
elseif ($isScript -and # If this is a script and it's an event
162163
($itemName -match '^@' -or # (prefaced with @ -or ending with .event.ps1)
163164
$itemName -match '\.event\.ps1$'
164165
)
@@ -200,6 +201,11 @@
200201
$WriteTypeViewSplat.DefaultDisplay =
201202
$fileText -split '(?>\r\n|\n)' -ne ''
202203
}
204+
205+
elseif ($itemName -like '*.propertySet') { # If it's a property set file (.propertyset.txt)
206+
$propertySets[$itemName -replace '\.propertySet$'] = # Create a property set with the file name.
207+
$fileText -split '(?>\r\n|\n)' -ne '' # Each line will be treated as a name of a property.
208+
}
203209
elseif ($itemName -match '^@') {
204210
$eventNames += $itemName.Substring(1)
205211
}
@@ -330,6 +336,9 @@ $stream.Dispose()
330336
if ($aliasProperty.Count) {
331337
$WriteTypeViewSplat.AliasProperty = $aliasProperty
332338
}
339+
if ($propertySets.Count) {
340+
$WriteTypeViewSplat.PropertySet = $propertySets
341+
}
333342
if ($scriptPropertyGet.Count -or $scriptPropertySet.Count) {
334343
$scriptProperties = [Ordered]@{}
335344
foreach ($k in $scriptPropertyGet.Keys) {

0 commit comments

Comments
 (0)