Skip to content

Commit 1345881

Browse files
committed
Added first attempt at validatePattern functionality for text, user-email and user-fullname
1 parent 7b2d40b commit 1345881

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

Plaster/InvokePlaster.ps1

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,23 @@ function Invoke-Plaster {
538538
}
539539
}
540540

541-
function PromptForInput($prompt, $default) {
541+
function PromptForInput($prompt, $default, $pattern) {
542+
if (!$pattern) {
543+
$patternMatch = $true
544+
}
545+
542546
do {
543547
$value = Read-Host -Prompt $prompt
544548
if (!$value -and $default) {
545549
$value = $default
546550
}
547-
} while (!$value)
551+
552+
if ($pattern) {
553+
if ($value -match $pattern) {
554+
$patternMatch = $true
555+
}
556+
}
557+
} while (!$value -or !$patternMatch)
548558

549559
$value
550560
}
@@ -625,6 +635,8 @@ function Invoke-Plaster {
625635
$type = $Node.type
626636
$store = $Node.store
627637

638+
$pattern = $Node.pattern
639+
628640
$condition = $Node.condition
629641

630642
$default = InterpolateAttributeValue $Node.default (GetErrorLocationParameterAttrVal $name default)
@@ -675,6 +687,12 @@ function Invoke-Plaster {
675687
# Some default values might not come from the template e.g. some are harvested from .gitconfig if it exists.
676688
$defaultNotFromTemplate = $false
677689

690+
$splat = @{}
691+
692+
if ($null -ne $pattern) {
693+
$splat.Add('pattern', $pattern)
694+
}
695+
678696
# Now prompt user for parameter value based on the parameter type.
679697
switch -regex ($type) {
680698
'text' {
@@ -689,7 +707,7 @@ function Invoke-Plaster {
689707
}
690708
}
691709
# Prompt the user for text input.
692-
$value = PromptForInput $prompt $default
710+
$value = PromptForInput $prompt $default @splat
693711
$valueToStore = $value
694712
}
695713
'user-fullname' {
@@ -710,7 +728,7 @@ function Invoke-Plaster {
710728
}
711729

712730
# Prompt the user for text input.
713-
$value = PromptForInput $prompt $default
731+
$value = PromptForInput $prompt $default @splat
714732
$valueToStore = $value
715733
}
716734
'user-email' {
@@ -731,7 +749,7 @@ function Invoke-Plaster {
731749
}
732750

733751
# Prompt the user for text input.
734-
$value = PromptForInput $prompt $default
752+
$value = PromptForInput $prompt $default @splat
735753
$valueToStore = $value
736754
}
737755
'choice|multichoice' {

0 commit comments

Comments
 (0)