mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2026-08-28 17:17:02 +00:00
testing re-parsing for stubs when invoked with &
This commit is contained in:
+8
-2
@@ -73,8 +73,14 @@ function stub($path) {
|
||||
}
|
||||
|
||||
function exec_stub($path, $inv) {
|
||||
$len = $inv.positionmessage.split("`n")[2] | sls '~+' | % { $_.matches[0].value.length }
|
||||
$cmd = $inv.line.substring($inv.offsetinline-1,$len)
|
||||
# re-parse the command line to work out which part of it to pass to the bin
|
||||
# needs to handle brackets, pipes and `& 'cmd'`
|
||||
$cmdName = $inv.InvocationName
|
||||
$ast = [System.Management.Automation.Language.Parser]::ParseInput($inv.line, [ref]$null, [ref]$null)
|
||||
|
||||
$cmd = $ast.find({
|
||||
($args[0].gettype().name -eq 'commandast') -and ($args.getcommandname() -eq $cmdName)
|
||||
}, $true)
|
||||
|
||||
$rawargs = $cmd -replace "^\s*&?\s*(('?[^']*')|([^\s]*))\s*", ""
|
||||
|
||||
|
||||
+10
-5
@@ -1,13 +1,18 @@
|
||||
|
||||
$inv = $myinvocation
|
||||
#$inv
|
||||
|
||||
$name = $inv.InvocationName
|
||||
|
||||
[System.Management.Automation.Language.Token[]]$tokens = $null
|
||||
[System.Management.Automation.Language.ScriptBlockAst]$ast =
|
||||
[System.Management.Automation.Language.Parser]::ParseInput($inv.line, [ref]$tokens, [ref]$null)
|
||||
$tokens = $null
|
||||
|
||||
#$tokens | % { $_ }
|
||||
$ast = [System.Management.Automation.Language.Parser]::ParseInput($inv.line, [ref]$tokens, [ref]$null)
|
||||
|
||||
$commands = $ast.FindAll({ ($args[0] -is [System.Management.Automation.Language.CommandAst]) -and ($args.getcommandname() -eq $name)}, $true)
|
||||
|
||||
$commands = $ast.FindAll({ ($args[0].gettype().name -eq 'commandast') -and ($args[0].invocationoperator -eq 'Ampersand')}, $true)
|
||||
|
||||
#$ast
|
||||
|
||||
#$tokens | where { $_.text -eq '&' } | % { $_.gettype() }
|
||||
|
||||
$commands | % { $_.extent.text }
|
||||
|
||||
Reference in New Issue
Block a user