Skip to content

Instantly share code, notes, and snippets.

@DexterPOSH
Created November 28, 2016 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DexterPOSH/d62aa77ed0c4b81d901c17272451ef10 to your computer and use it in GitHub Desktop.
Save DexterPOSH/d62aa77ed0c4b81d901c17272451ef10 to your computer and use it in GitHub Desktop.
Try to create tab completion for the PSDeploy DSL.
Function PSDeployCompletion
{
param( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
$CommandTree = Get-CompletionPrivateData -Key PSDeployCompletionCommandTree
if ($null -eq $CommandTree) {
$CommandTree = & {
New-CommandTree -Completion FromSource -ToolTip 'Source' -Argument
New-CommandTree -Completion To -ToolTip 'Destination' -Argument
New-CommandTree -Completion Tagged -ToolTip 'Tags to use for the deployment' -Argument
New-CommandTree -Completion WithOptions -ToolTip 'options for the deployment' -SubCommands {
New-CommandTree -Completion Test -tooltip 'test'
}
}
Set-CompletionPrivateData -Key PSDeployCompletionCommandTree -Value $commandTree
}
Get-CommandTreeCompletion $wordToComplete $commandAst $commandTree
}
Register-ArgumentCompleter `
-Command 'By' `
-ParameterName 'ScriptBlock' `
-Description 'Complete arguments to a Deployment' `
-ScriptBlock $function:PSDeployCompletion
@DexterPOSH
Copy link
Author

Below is an example of the PSDeploy DSL

Deploy CopyFilestoVM {

    By CopyVMFile InstallScript {
        FromSource 'InstallScript.ps1'
        To 'C:\PSDeployTo'
        Tagged Dev
        WithOptions @{
            Name = 'WDS'
            FileSource = 'Host'
            CreateFullPath = $true
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment