第一次选择后,数组的标签完成不显示

时间:2015-06-21 12:42:59

标签: visual-studio powershell nuget tabexpansion

这是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"
    }
}

在软件包管理器控制台中当我尝试使用此命令运行脚本时,我可以使用tab从TabExpansion中选择选项,然后选择每个选项的值:

Add-Shape -Shape Circle -Colors Red,...

问题是在为数组选项选择第一个值后,选项卡再次永远不再显示以选择其他值。

1 个答案:

答案 0 :(得分:1)

您可以使用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"
    }
}