diff --git a/Plaster/InvokePlaster.ps1 b/Plaster/InvokePlaster.ps1
index 7b0644d..ca38dbb 100644
--- a/Plaster/InvokePlaster.ps1
+++ b/Plaster/InvokePlaster.ps1
@@ -538,13 +538,26 @@ function Invoke-Plaster {
}
}
- function PromptForInput($prompt, $default) {
+ function PromptForInput($prompt, $default, $pattern) {
+ if (!$pattern) {
+ $patternMatch = $true
+ }
+
do {
$value = Read-Host -Prompt $prompt
if (!$value -and $default) {
$value = $default
+ $patternMatch = $true
+ }
+ elseif ($value -and $pattern) {
+ if ($value -match $pattern) {
+ $patternMatch = $true
+ }
+ else {
+ $PSCmdlet.WriteDebug("Value '$value' did not match the pattern '$pattern'")
+ }
}
- } while (!$value)
+ } while (!$value -or !$patternMatch)
$value
}
@@ -625,6 +638,8 @@ function Invoke-Plaster {
$type = $Node.type
$store = $Node.store
+ $pattern = $Node.pattern
+
$condition = $Node.condition
$default = InterpolateAttributeValue $Node.default (GetErrorLocationParameterAttrVal $name default)
@@ -675,6 +690,12 @@ function Invoke-Plaster {
# Some default values might not come from the template e.g. some are harvested from .gitconfig if it exists.
$defaultNotFromTemplate = $false
+ $splat = @{}
+
+ if ($null -ne $pattern) {
+ $splat.Add('pattern', $pattern)
+ }
+
# Now prompt user for parameter value based on the parameter type.
switch -regex ($type) {
'text' {
@@ -689,7 +710,7 @@ function Invoke-Plaster {
}
}
# Prompt the user for text input.
- $value = PromptForInput $prompt $default
+ $value = PromptForInput $prompt $default @splat
$valueToStore = $value
}
'user-fullname' {
@@ -710,7 +731,7 @@ function Invoke-Plaster {
}
# Prompt the user for text input.
- $value = PromptForInput $prompt $default
+ $value = PromptForInput $prompt $default @splat
$valueToStore = $value
}
'user-email' {
@@ -731,7 +752,7 @@ function Invoke-Plaster {
}
# Prompt the user for text input.
- $value = PromptForInput $prompt $default
+ $value = PromptForInput $prompt $default @splat
$valueToStore = $value
}
'choice|multichoice' {
diff --git a/Plaster/Schema/PlasterManifest-v1.xsd b/Plaster/Schema/PlasterManifest-v1.xsd
index fc0ca7a..9084743 100644
--- a/Plaster/Schema/PlasterManifest-v1.xsd
+++ b/Plaster/Schema/PlasterManifest-v1.xsd
@@ -212,6 +212,11 @@
The default value for the parameter which the user will be able to accept or change.
+
+
+ Used for parameter input validation. If the value matches the pattern, the value is accepted. Otherwise it is not.
+
+
diff --git a/examples/plasterManifest-validatePattern.xml b/examples/plasterManifest-validatePattern.xml
new file mode 100644
index 0000000..a579a61
--- /dev/null
+++ b/examples/plasterManifest-validatePattern.xml
@@ -0,0 +1,191 @@
+
+
+
+
+ ac9f688f-503d-48c9-833a-f0d767d92f47
+ NewPowerShellModule
+
+ New PowerShell Module
+
+ Plaster template for creating the files for a PowerShell module.
+ 0.2.0
+ Module, ModuleManifest, Build
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Scaffold a PowerShell Module with the files required to run Pester tests, build with PSake and publish to the PSGallery.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ (?s)^(.*)
+ // Author: $PLASTER_PARAM_FullName`r`n`$1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `n`nYour new PowerShell module project $PLASTER_PARAM_ModuleName
+ with Git version control
+ has been created.
+
+
+You can build your project by executing the 'build' task by pressing Ctrl+P, then type 'task build'.
+You can publish your project to the PSGallery by pressing Ctrl+P, then type 'task publish'.
+
+
+
+
+A Pester test has been created to validate the module's manifest file. Add additional test to the Tests directory.
+You can run the Pester tests in your project by executing the 'test' task by pressing Ctrl+P, then type 'task test'.
+
+
+
+
+You can generate help and additional documentation using platyPS by running the 'docs' task by pressing Ctrl+P,
+then type 'task docs'. Add additional documentation written in platyPS markdown to the docs directory. You can
+update the docs by running the 'docs' task again.
+
+
+
+