Skip to content

Commit 1f012be

Browse files
author
James Brundage
committed
Use-PipeScript: Supporting Get-Command -Syntax (Fixes #177)
1 parent 7e392dd commit 1f012be

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

Use-PipeScript.ps1

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
<#
44
.Synopsis
5-
Uses PipeScript Transpilers
5+
Uses PipeScript Transpilers
66
.Description
77
Runs an individual PipeScript Transpiler.
88
This command must be used by it's smart aliases (for example ```.>PipeScript```).
@@ -35,19 +35,37 @@
3535
{
3636
$matches.Name
3737
}
38-
else
38+
elseif ($MyInv.InvocationName)
3939
{
4040
$myInv.InvocationName -replace $NameRegex, '${Name}'
4141
}
42+
else {
43+
$callstackPeek = @(Get-PSCallStack)[-1]
44+
$callerCommand = $callstackPeek.InvocationInfo.MyCommand.ToString()
45+
$CallerName =
46+
if ($callerCommand -match "-Name\s{0,1}(?<Name>\S+)") {
47+
$matches.Name
48+
} elseif ($callerCommand -match '(?>gcm|Get-Command)\s{0,1}(?<Name>\S+)') {
49+
$matches.Name
50+
}
51+
52+
if ($callerName) {
53+
$callerName -replace $NameRegex, '${Name}'
54+
}
55+
}
56+
57+
if (-not $mySafeName) { return }
4258

4359
# Find the Converter in the library.
44-
$converter = Get-Transpiler | Where-Object DisplayName -eq $mySafeName
45-
$converter.GetDynamicParameters()
46-
# return $Converter.GetDynamicParameters()
60+
$converter = Get-Transpiler | Where-Object DisplayName -eq $mySafeName
61+
if ($converter) {
62+
$converter.GetDynamicParameters()
63+
}
64+
4765
}
4866

4967
begin {
50-
$steppablePipelines =
68+
$steppablePipelines =
5169
@(if (-not $mySafeName -and $psBoundParameters['Name']) {
5270
$names = $psBoundParameters['Name']
5371
$null = $psBoundParameters.Remove('Name')
@@ -61,10 +79,10 @@
6179
}
6280

6381
process {
64-
if (-not $mySafeName -and -not $steppablePipelines) {
82+
if (-not $mySafeName -and -not $steppablePipelines) {
6583
Write-Error "Must call Use-Pipescript with one of it's aliases."
6684
return
67-
}
85+
}
6886
elseif ($steppablePipelines) {
6987
$in = $_
7088
foreach ($sp in $steppablePipelines) {

0 commit comments

Comments
 (0)