1

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

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

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

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

4

1 回答 1

1

你可以使用验证集:

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"
    }
}
于 2015-06-21T22:57:23.547 回答