@@ -28,10 +28,8 @@ function Invoke-Interpreter {
28
28
:NextInterpreter foreach ($interpreterForFile in $interpreterForFiles ) {
29
29
$interpreterCommand , $leadingArgs = $interpreterForFile.Interpreter
30
30
# If there was no interpreter command, return.
31
- if (-not $interpreterCommand ) { continue }
32
-
33
- $leadingArgs = @ ($leadingArgs )
34
-
31
+ if (-not $interpreterCommand ) { continue }
32
+
35
33
# Now things get a little more complicated.
36
34
37
35
# Since many things that will interpret our arguments will _not_ be PowerShell, we want to conver them
@@ -53,11 +51,24 @@ function Invoke-Interpreter {
53
51
}
54
52
} }
55
53
})
54
+
55
+ # We want to use splatting for both sets of arguments,
56
+ # so force leading args into an array
57
+ $leadingArgs = @ ($leadingArgs )
56
58
57
- $ParsersForCommand = $PSParser.ForCommand ($invocationName )
59
+ # If there were leading args
60
+ if ($leadingArgs ) {
61
+ # append the invocation name to the array
62
+ $leadingArgs += @ ($invocationName )
63
+ } else {
64
+ # otherwise, the invocation name is the only leading argument (and we do not want blanks)
65
+ $leadingArgs = @ ($invocationName )
66
+ }
58
67
59
-
60
- $leadingArgs += @ ($invocationName )
68
+ # Just before we run, see if we have any parsers for the command
69
+ $ParsersForCommand = $PSParser.ForCommand ($invocationName )
70
+
71
+ # If we do, we'll pipe to Out-Parser.
61
72
if ($ParsersForCommand ) {
62
73
if ($MyInvocation.ExpectingInput ) {
63
74
$input |
@@ -73,7 +84,7 @@ function Invoke-Interpreter {
73
84
} else {
74
85
& $interpreterCommand @leadingArgs @convertedArguments
75
86
}
76
- }
77
- }
87
+ }
88
+ }
78
89
79
90
}
0 commit comments