|
27 | 27 | [Alias('Prefix')]
|
28 | 28 | [string]$Namespace,
|
29 | 29 |
|
| 30 | + # Any number of commands to import. |
| 31 | + # These commands will converted into ScriptMethods. |
| 32 | + # Each ScriptMethod will it's original command name, within the typename `Commands`. |
| 33 | + # (if -Namespace is provided, the namespace will be prepended to the typename) |
| 34 | + # (only functions are currently supported) |
| 35 | + [Parameter(ValueFromPipelineByPropertyName)] |
| 36 | + [Alias('Commands')] |
| 37 | + [PSObject[]] |
| 38 | + $Command, |
| 39 | + |
30 | 40 | # Any file paths to exclude.
|
31 | 41 | [Parameter(ValueFromPipelineByPropertyName)]
|
32 | 42 | [SupportsWildcards()]
|
|
43 | 53 |
|
44 | 54 | process {
|
45 | 55 |
|
| 56 | + # Commands are converted into ScriptMethods first. |
| 57 | + if ($Command) { |
| 58 | + $writeTypeViewSplat = @{ |
| 59 | + TypeName = if ($Namespace) { "$Namespace.Commands" } else { 'Commands' } |
| 60 | + ScriptMethod = [Ordered]@{} |
| 61 | + } |
| 62 | + foreach ($cmd in $command) { |
| 63 | + if ($cmd -is [Management.Automation.FunctionInfo]) { |
| 64 | + $writeTypeViewSplat.ScriptMethod[$cmd.Name] = $cmd.ScriptBlock |
| 65 | + } |
| 66 | + } |
| 67 | + Write-TypeView @writeTypeViewSplat |
| 68 | + } |
| 69 | + |
| 70 | + |
46 | 71 | <#
|
47 | 72 | In order to make something like inheritance work,
|
48 | 73 | we want to be able to define properties and methods a few places:
|
|
132 | 157 | }
|
133 | 158 | }
|
134 | 159 | $membersByType.Remove('*') # then remove it (so we don't do it twice).
|
135 |
| - } |
136 |
| - |
| 160 | + } |
137 | 161 | :nextMember foreach ($mt in $membersByType.GetEnumerator() | Sort-Object Key) { # Walk thru the members by type
|
138 | 162 | $WriteTypeViewSplat = @{ # and create a hashtable to splat.
|
139 | 163 | TypeName = if ($Namespace) { "$Namespace.$($mt.Key)"} else {$mt.Key}
|
|
156 | 180 |
|
157 | 181 | Starting a file with . will hide the property.
|
158 | 182 |
|
159 |
| - It should be noted that hidden ScriptMethods are not "private" Methods |
| 183 | + It should be noted that hidden ScriptMethods are not "private" Methods, they are just hidden. |
160 | 184 | (though neither are C# private Methods, if you use Reflection).
|
161 | 185 |
|
162 | 186 | #>
|
|
0 commit comments