第一次选择后不显示数组的制表符完成
Tab completion for array not shows after first selection
这是 VS PowerShell 的脚本。
function global:Add-Shape { param([string]$Shape, [string[]]$Colors)
Write-Host "Shape Name:$Shape"
foreach ($i in $Colors) {
Write-Host "Color Name:$i"
}
}
Register-TabExpansion 'Add-Shape' @{
'Shape' = {
"Circle",
"Square",
"Triangle"
}
'Colors' = {
"Brown",
"Red",
"Blue"
}
}
在程序包管理器控制台中,当我尝试将此命令 运行 脚本时,我可以使用选项卡 select 选项,然后使用 TabExpansion 中的每个选项的值:
Add-Shape -Shape Circle -Colors Red,...
问题是在 select 完成数组选项选项卡的第一个值之后再也不会显示给 select 附加。
您可以使用 ValidateSet:
function global:Add-Shape {
param(
[ValidateSet("Circle","Square","Triangle")]
[string]$Shape,
[ValidateSet("Brown","Red","Blue")]
[string[]]$Colors
)
Write-Host "Shape Name:$Shape"
foreach ($i in $Colors) {
Write-Host "Color Name:$i"
}
}
这是 VS PowerShell 的脚本。
function global:Add-Shape { param([string]$Shape, [string[]]$Colors)
Write-Host "Shape Name:$Shape"
foreach ($i in $Colors) {
Write-Host "Color Name:$i"
}
}
Register-TabExpansion 'Add-Shape' @{
'Shape' = {
"Circle",
"Square",
"Triangle"
}
'Colors' = {
"Brown",
"Red",
"Blue"
}
}
在程序包管理器控制台中,当我尝试将此命令 运行 脚本时,我可以使用选项卡 select 选项,然后使用 TabExpansion 中的每个选项的值:
Add-Shape -Shape Circle -Colors Red,...
问题是在 select 完成数组选项选项卡的第一个值之后再也不会显示给 select 附加。
您可以使用 ValidateSet:
function global:Add-Shape {
param(
[ValidateSet("Circle","Square","Triangle")]
[string]$Shape,
[ValidateSet("Brown","Red","Blue")]
[string[]]$Colors
)
Write-Host "Shape Name:$Shape"
foreach ($i in $Colors) {
Write-Host "Color Name:$i"
}
}