Complete recipes names in PowerShell completion script (#651)

This commit is contained in:
Chris Nantau
2020-10-05 23:12:48 -03:00
committed by GitHub
parent a8361012d6
commit fbda8dd2c7
2 changed files with 53 additions and 1 deletions

View File

@@ -60,6 +60,26 @@ Register-ArgumentCompleter -Native -CommandName 'just' -ScriptBlock {
}
})
function Get-JustFileRecipes([string[]]$CommandElements) {
$justFileIndex = $commandElements.IndexOf("--justfile");
if ($justFileIndex -ne -1 && $justFileIndex + 1 -le $commandElements.Length) {
$justFileLocation = $commandElements[$justFileIndex + 1]
}
$justArgs = @("--summary")
if (Test-Path $justFileLocation) {
$justArgs += @("--justfile", $justFileLocation)
}
$recipes = $(just @justArgs) -split ' '
return $recipes | ForEach-Object { [CompletionResult]::new($_) }
}
$elementValues = $commandElements | Select-Object -ExpandProperty Value
$recipes = Get-JustFileRecipes -CommandElements $elementValues
$completions += $recipes
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
Sort-Object -Property ListItemText
}