Skip to content

Commit e3b77be

Browse files
committed
feat(parameter): remove regex message
1 parent 002a6cf commit e3b77be

File tree

4 files changed

+5
-8
lines changed

4 files changed

+5
-8
lines changed

internal/parameter/secret/secret.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (p Param) Render() huh.Field {
2828
group = append(group, validators.MaxLength(*p.MaxLength))
2929
}
3030
if p.Regex != "" {
31-
group = append(group, validators.RegexValidator(p.Regex, p.RegexMessage))
31+
group = append(group, validators.RegexValidator(p.Regex))
3232
}
3333
if len(group) > 0 {
3434
param.Validate(validators.Group(group...))

internal/parameter/str/str.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ type Param struct {
1616
Trim bool `yaml:"trim" json:"trim" mapstructure:"trim"` // Todo implement trim??
1717
DefaultValue string `yaml:"default_value" json:"default_value" mapstructure:"default_value"`
1818
Regex string `yaml:"regex" json:"regex" mapstructure:"regex"`
19-
RegexMessage string `yaml:"regex_message" json:"regex_message" mapstructure:"regex_message"`
2019
MinLength *int `yaml:"min_length" json:"min_length" mapstructure:"min_length"`
2120
MaxLength *int `yaml:"max_length" json:"max_length" mapstructure:"max_length"`
2221
}
@@ -53,7 +52,7 @@ func (p Param) RenderInput() *huh.Input {
5352
group = append(group, validators.FQDNValidator())
5453
}
5554
if p.Regex != "" {
56-
group = append(group, validators.RegexValidator(p.Regex, p.RegexMessage))
55+
group = append(group, validators.RegexValidator(p.Regex))
5756
}
5857

5958
if len(group) > 0 {

internal/parameter/text/text.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ type Param struct {
1313
Required bool `yaml:"required" json:"required" mapstructure:"required"`
1414
DefaultValue string `yaml:"default_value" json:"default_value" mapstructure:"default_value"`
1515
Regex string `yaml:"regex" json:"regex" mapstructure:"regex"`
16-
RegexMessage string `yaml:"regex_message" json:"regex_message" mapstructure:"regex_message"`
1716
MinLength *int `yaml:"min_length" json:"min_length" mapstructure:"min_length"`
1817
MaxLength *int `yaml:"max_length" json:"max_length" mapstructure:"max_length"`
1918
Height *int `yaml:"height" json:"height" mapstructure:"height"`
@@ -45,7 +44,7 @@ func (p Param) Render() huh.Field {
4544
group = append(group, validators.MaxLength(*p.MaxLength))
4645
}
4746
if p.Regex != "" {
48-
group = append(group, validators.RegexValidator(p.Regex, p.RegexMessage))
47+
group = append(group, validators.RegexValidator(p.Regex))
4948
}
5049

5150
if len(group) > 0 {

internal/parameter/validators/str.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package validators
22

33
import (
4-
"errors"
54
"fmt"
65
"net"
76
"regexp"
@@ -29,11 +28,11 @@ func MinLength(min int) func(string) error {
2928
}
3029
}
3130

32-
func RegexValidator(regex, message string) func(string) error {
31+
func RegexValidator(regex string) func(string) error {
3332
return func(str string) error {
3433
re := regexp.MustCompile(regex)
3534
if !re.MatchString(str) {
36-
return errors.New(message)
35+
return fmt.Errorf("contents must match the regex: %s", regex)
3736
}
3837
return nil
3938
}

0 commit comments

Comments
 (0)