Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Plaster/Plaster.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,25 @@ $MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
Remove-Variable -Name 'ParameterDefaultValueStoreRootPath' -Scope Script -ErrorAction SilentlyContinue
}

# Register argument completers
Register-ArgumentCompleter -CommandName Invoke-Plaster -ParameterName TemplateName -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)

# Trim single, or double quotes from the start/end of the word to complete.
if ($wordToComplete -match '^[''"]') {
$wordToComplete = $wordToComplete.Trim($Matches.Values[0])
}

# Get all unique names starting with the characters provided, if any.
Get-PlasterTemplate -Name "$wordToComplete*" | Select-Object Name -Unique | ForEach-Object {
# Wrap the completion in single quotes if it contains any whitespace.
if ($_.Name -match '\s') {
"'{0}'" -f $_.Name
} else {
$_.Name
}
}
}

# Module initialization complete
Write-PlasterLog -Level Information -Message "Plaster v$PlasterVersion module loaded successfully (PowerShell $($PSVersionTable.PSVersion))"
14 changes: 13 additions & 1 deletion Plaster/Public/Invoke-Plaster.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ function Invoke-Plaster {
[string]
$TemplateDefinition,

[Parameter(Position = 0, Mandatory = $true, ParameterSetName = 'TemplateName')]
[ValidateNotNullOrEmpty()]
[string]
$TemplateName,

[Parameter(Position = 1, Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]
Expand Down Expand Up @@ -70,6 +75,10 @@ function Invoke-Plaster {
EvaluateAttributeValue since we are only grabbing the parameter's
value which is static.#>

if ($PSCmdlet.ParameterSetName -eq 'TemplateName') {
$TemplatePath = (Get-PlasterTemplate -Name $TemplateName).TemplatePath
}

$templateAbsolutePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($TemplatePath)

# Load manifest file using culture lookup - try both JSON and XML formats
Expand Down Expand Up @@ -194,7 +203,10 @@ function Invoke-Plaster {
#endregion Script Scope Variables

# Determine template source and type
if ($PSCmdlet.ParameterSetName -eq 'TemplatePath') {
if ($PSCmdlet.ParameterSetName -eq 'TemplateName') {
$TemplatePath = (Get-PlasterTemplate -Name $TemplateName).TemplatePath
}
if ($PSCmdlet.ParameterSetName -in @('TemplatePath', 'TemplateName')) {
$templateAbsolutePath = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($TemplatePath)
if (!(Test-Path -LiteralPath $templateAbsolutePath -PathType Container)) {
throw ($LocalizedData.ErrorTemplatePathIsInvalid_F1 -f $templateAbsolutePath)
Expand Down
Loading
Loading