Skip to content

Commit

Permalink
feat: Import-TypeView -Namespace ( Fixes #224 )
Browse files Browse the repository at this point in the history
  • Loading branch information
StartAutomating committed Jul 7, 2024
1 parent cf8fa92 commit 8f39d2b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Commands/Types.PS1XML/Import-TypeView.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@
$FilePath,

# If set, will generate an identical typeview for the deserialized form of each typename.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]$Deserialized,

# The namespace to use for all imported types.
# This will be prepended to the type name, and followed by a period.
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Prefix')]
[string]$Namespace,

# Any file paths to exclude.
[Parameter(ValueFromPipelineByPropertyName)]
[SupportsWildcards()]
Expand Down Expand Up @@ -129,9 +136,10 @@

:nextMember foreach ($mt in $membersByType.GetEnumerator() | Sort-Object Key) { # Walk thru the members by type
$WriteTypeViewSplat = @{ # and create a hashtable to splat.
TypeName = $mt.Key
TypeName = if ($Namespace) { "$Namespace.$($mt.Key)"} else {$mt.Key}
Deserialized = $Deserialized
}
$OriginalParameterCount = $WriteTypeViewSplat.Count
# Then, sort the values by name and by if it comes from this directory.
$sortedValues = $mt.Value | Sort-Object Name, { $_.Directory.Name -ne $mt.Key }

Expand Down Expand Up @@ -484,7 +492,8 @@ $stream.Dispose()
$WriteTypeViewSplat.EventName = $eventNames
}

if ($WriteTypeViewSplat.Count -gt 1) {
# If we have added any parameters to splat, we will write the type view.
if ($WriteTypeViewSplat.Count -gt $OriginalParameterCount) {
$WriteTypeViewSplat.HideProperty = $hideProperty
Write-TypeView @WriteTypeViewSplat
}
Expand Down

0 comments on commit 8f39d2b

Please sign in to comment.