Skip to content

Commit 1a66490

Browse files
StartAutomatingStartAutomating
authored andcommitted
New-PipeScript: Writing help (Fixes #195) and functions (fixes #196)
1 parent 818daa6 commit 1a66490

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

Get-Transpiler.ps1

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Piecemeal [ 0.3.3 ] : Easy Extensible Plugins for PowerShell
1+
#region Piecemeal [ 0.3.4 ] : Easy Extensible Plugins for PowerShell
22
# Install-Module Piecemeal -Scope CurrentUser
33
# Import-Module Piecemeal -Force
44
# Install-Piecemeal -ExtensionNoun 'Transpiler' -ExtensionPattern '\.psx\.ps1$' -ExtensionTypeName 'PipeScript.Transpiler' -OutputPath '.\Get-Transpiler.ps1'
@@ -230,7 +230,7 @@ function Get-Transpiler
230230
}
231231

232232
$extCmd.PSObject.Methods.Add([psscriptmethod]::new('GetExtendedCommands', {
233-
233+
param([Management.Automation.CommandInfo[]]$CommandList)
234234
$extendedCommandNames = @(
235235
foreach ($attr in $this.ScriptBlock.Attributes) {
236236
if ($attr -isnot [Management.Automation.CmdletAttribute]) { continue }
@@ -244,13 +244,16 @@ function Get-Transpiler
244244
$this | Add-Member NoteProperty ExtensionCommands @() -Force
245245
return
246246
}
247-
$allLoadedCmds = $ExecutionContext.SessionState.InvokeCommand.GetCommands('*','All', $true)
247+
if (-not $CommandList) {
248+
$commandList = $ExecutionContext.SessionState.InvokeCommand.GetCommands('*','Function,Alias,Cmdlet', $true)
249+
}
248250
$extends = @{}
249-
foreach ($loadedCmd in $allLoadedCmds) {
251+
:nextCommand foreach ($loadedCmd in $commandList) {
250252
foreach ($extensionCommandName in $extendedCommandNames) {
251253
if ($extensionCommandName -and $loadedCmd.Name -match $extensionCommandName) {
252254
$loadedCmd
253255
$extends[$loadedCmd.Name] = $loadedCmd
256+
continue nextCommand
254257
}
255258
}
256259
}
@@ -263,7 +266,12 @@ function Get-Transpiler
263266
$this | Add-Member NoteProperty ExtensionCommands $extends.Values -Force
264267
}))
265268

266-
$null = $extCmd.GetExtendedCommands()
269+
if (-not $script:AllCommands) {
270+
$script:AllCommands = $ExecutionContext.SessionState.InvokeCommand.GetCommands('*','Function,Alias,Cmdlet', $true)
271+
}
272+
273+
274+
$null = $extCmd.GetExtendedCommands($script:AllCommands)
267275

268276
$inheritanceLevel = [ComponentModel.InheritanceLevel]::Inherited
269277

@@ -824,9 +832,8 @@ function Get-Transpiler
824832
return $allDynamicParameters
825833
}
826834
}
827-
}
828-
#endregion Define Inner Functions
829-
835+
}
836+
#endregion Define Inner Functions
830837

831838
$extensionFullRegex =
832839
[Regex]::New($(
@@ -847,7 +854,8 @@ function Get-Transpiler
847854
$getCmd = $ExecutionContext.SessionState.InvokeCommand.GetCommand
848855

849856
if ($Force) {
850-
$script:Transpilers = $null
857+
$script:Transpilers = $null
858+
$script:AllCommands = @()
851859
}
852860
if (-not $script:Transpilers)
853861
{
@@ -917,5 +925,5 @@ function Get-Transpiler
917925
}
918926
}
919927
}
920-
#endregion Piecemeal [ 0.3.3 ] : Easy Extensible Plugins for PowerShell
928+
#endregion Piecemeal [ 0.3.4 ] : Easy Extensible Plugins for PowerShell
921929

0 commit comments

Comments
 (0)