Use ValidateSet with the contents loaded from a CSV file

前端 未结 2 850
北荒
北荒 2021-02-02 17:54

I really like the way that ValidateSet works. It proposes the options as a list while you type your Cmdlet in the PowerShell ISE.

I would like to know if i

2条回答
  •  星月不相逢
    2021-02-02 18:15

    I prefer TabExpansion++ module though this doesn't technically validate, it has some nice functionality...

    Here's an example of an msbuild overloaded command to add some intellisense for projects

    Register-ArgumentCompleter -CommandName "msbuild" -ParameterName "target" -ScriptBlock {
        param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
    
        $projectName = $fakeBoundParameter['project']
        $projectFile = Join-Path (Get-Location) $projectName
        $projectXml = [xml](Get-Content $projectFile)
    
        $targets = $projectXml.Project.Target | Where-Object { $_.Name.ToString().StartsWith($wordToComplete) }
        foreach($target in $projectXml.Project.Target)
        {
            New-CompletionResult -CompletionText "$($target.Name)"
        }
    }
    

提交回复
热议问题