Last active
December 9, 2019 11:57
-
-
Save pitermarx/747c4b41e7dcc895e46aed86fe7290a7 to your computer and use it in GitHub Desktop.
Cake task autocomplete in powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
Param( | |
[string]$Script = "build.cake", | |
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] | |
[string]$Verbosity = "Normal", | |
[Parameter(Position = 0, Mandatory = $false, ValueFromRemainingArguments = $true)] | |
[string[]]$ScriptArgs | |
) | |
dynamicparam { | |
# user defined files where to search for tasks | |
$files = Get-ChildItem .\BuildScripts\*.cake -Recurse | |
$files += (Get-ChildItem build.cake) | |
# Regex to get the task names | |
$values = $files | Select-String '^.*Task\("(.*)"\).*$' | % { $_.Matches[0].Groups[1].Value } | |
# create validate set attribute | |
$ValidateSet = new-object System.Management.Automation.ValidateSetAttribute($values) | |
$attributes = new-object System.Management.Automation.ParameterAttribute | |
$attributes.ParameterSetName = "__AllParameterSets" | |
$attributes.Mandatory = $true | |
$attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute] | |
$attributeCollection.Add($attributes) | |
$attributeCollection.Add($ValidateSet) | |
$dynParam1 = new-object -Type System.Management.Automation.RuntimeDefinedParameter("Target", [string], $attributeCollection) | |
$paramDictionary = new-object -Type System.Management.Automation.RuntimeDefinedParameterDictionary | |
$paramDictionary.Add("Target", $dynParam1) | |
return $paramDictionary | |
} | |
process { | |
# The actual bootstraping file here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment