Skip to content

Add dynamic validateset to tasklist in bootstrapper file #14

@motowilliams

Description

@motowilliams

Something like

$psakeBootstrap = ".\run.ps1"
$buildscript = ".\default.ps1"

function Set-Tasks() {
    $tasks = (Select-String -Path $buildscript -Pattern "task \w+(\-)?\w+").matches | ForEach-Object { $_.Value.Split(" ")[1] } | Sort-Object
    $taskListString = [string]::Join("','",$tasks)
    $content = get-content $psakeBootstrap | ForEach-Object { $_ -replace "\[ValidateSet.*\]", "[ValidateSet('$taskListString')]" }
    $content | Out-File -FilePath $psakeBootstrap -Encoding ascii
}

Export-ModuleMember -Function Set-Tasks

and in 'run.ps1'

Remove-Module [S]et-Tasks
Import-Module ".\Set-Tasks.psm1"
Set-Tasks

which will just overwrite the [ValidateSet( line on itself

super hacky but just an idea

Using Psake's built-in Get-PSakeScriptTasks | Select-Object { $_.name } is probably a better idea

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions