|
250 | 250 |
|
251 | 251 | # If we have an interpreter for that language |
252 | 252 | if ($matchingPipeScriptLanguage.Interpreter -or $matchingPipeScriptLanguage.Runner) { |
| 253 | + # we'll want to run it. |
253 | 254 |
|
254 | | - # Figure out what command or script block we will run instead |
255 | | - $interpreterCommand = $null |
256 | | - $InterpreterOrRunner = if ($matchingPipeScriptLanguage.Interpreter) { |
257 | | - $matchingPipeScriptLanguage.Interpreter |
258 | | - } else { |
259 | | - $matchingPipeScriptLanguage.Runner |
260 | | - } |
261 | | - $interpreterArguments = @( |
262 | | - # and what other arguments we pass positionally |
263 | | - switch ($InterpreterOrRunner) { |
264 | | - { $_ -is [Management.Automation.CommandInfo] -and -not $interpreterCommand} { $interpreterCommand = $_ } |
265 | | - { $_ -is [scriptblock] -and -not $interpreterCommand} { $interpreterCommand = $_ } |
266 | | - default { |
267 | | - # (any other results in a language's Interpreter will be counted as positional arguments) |
268 | | - if (-not $interpreterCommand -and $_ -is [string]) { |
269 | | - $interpreterCommand = $_ |
270 | | - } else { |
271 | | - $_ |
272 | | - } |
273 | | - } |
274 | | - } |
275 | | - ) |
276 | | - |
277 | | - # If we found an interpreter |
278 | | - if ($interpreterCommand) { |
279 | | - # rearrange the arguments |
280 | | - $ArgumentList = |
281 | | - @( |
282 | | - if ($matchingPipeScriptLanguage.Interpreter -isnot [ScriptBlock]) { |
283 | | - $ArgumentList | |
284 | | - . { process { |
285 | | - if ($_ -isnot [string]) { |
286 | | - ConvertTo-Json -InputObject $_ -Depth 100 |
287 | | - } else { |
288 | | - $_ |
289 | | - } |
290 | | - } } |
291 | | - } else { |
292 | | - $ArgumentList | . { process { $_ } } |
293 | | - }) |
294 | | - $ArgumentList = @($interpreterArguments) + $( |
295 | | - if ($matchingPipeScriptLanguage.Interpreter) { |
296 | | - $command.Source |
297 | | - }) + $ArgumentList |
298 | | - # and change the command we're calling. |
299 | | - $command = $interpreterCommand |
300 | | - } |
| 255 | + # Rather than duplicate a lot of code, the easiest way to do this is simply to alias the full path |
| 256 | + Set-Alias $command.Source Invoke-Interpreter |
| 257 | + # and reset the value of $Command |
| 258 | + $command = $ExecutionContext.SessionState.InvokeCommand.GetCommand($command.Source, 'Alias') |
| 259 | + # (the alias will only exist locally, and not exist when Invoke-PipeScript returns) |
301 | 260 | } |
302 | 261 |
|
303 | 262 | $CommandStart = [DateTime]::now |
|
0 commit comments