Skip to content

Commit bc1cc0e

Browse files
StartAutomatingStartAutomating
StartAutomating
authored and
StartAutomating
committed
feat: Invoke-Interpreter Improvement ( Fixes #895 )
Fixing leading args and improving inner docs
1 parent 08347e4 commit bc1cc0e

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Commands/Interpreters/Invoke-Interpreter.ps1

+20-9
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ function Invoke-Interpreter {
2828
:NextInterpreter foreach ($interpreterForFile in $interpreterForFiles) {
2929
$interpreterCommand, $leadingArgs = $interpreterForFile.Interpreter
3030
# If there was no interpreter command, return.
31-
if (-not $interpreterCommand) { continue }
32-
33-
$leadingArgs = @($leadingArgs)
34-
31+
if (-not $interpreterCommand) { continue }
32+
3533
# Now things get a little more complicated.
3634

3735
# Since many things that will interpret our arguments will _not_ be PowerShell, we want to conver them
@@ -53,11 +51,24 @@ function Invoke-Interpreter {
5351
}
5452
} }
5553
})
54+
55+
# We want to use splatting for both sets of arguments,
56+
# so force leading args into an array
57+
$leadingArgs = @($leadingArgs)
5658

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+
}
5867

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.
6172
if ($ParsersForCommand) {
6273
if ($MyInvocation.ExpectingInput) {
6374
$input |
@@ -73,7 +84,7 @@ function Invoke-Interpreter {
7384
} else {
7485
& $interpreterCommand @leadingArgs @convertedArguments
7586
}
76-
}
77-
}
87+
}
88+
}
7889

7990
}

0 commit comments

Comments
 (0)