Skip to content

Commit cc2b0a6

Browse files
committed
fix(secret): reset validators of secret
1 parent d3914f0 commit cc2b0a6

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

internal/config/default.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
const DefaultCommitTemplate = `---
4-
version: v2
54
name: default
65
default: true
76
items:

internal/errors/missing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func (e MissingErr) Error() string {
1111
if e.name == "" {
1212
return fmt.Sprintf("missing required field `%s`", e.field)
1313
}
14-
return fmt.Sprintf("'%s' missing required field: %s", e.name, e.field)
14+
return fmt.Sprintf("item '%s' missing required field: %s", e.name, e.field)
1515
}
1616

1717
func NewMissingErr(field string, name ...string) error {

internal/parameter/secret/secret.go

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

33
import (
44
"github.com/charmbracelet/huh"
5+
"github.com/shipengqi/commitizen/internal/parameter/validators"
56

67
"github.com/shipengqi/commitizen/internal/parameter/str"
78
)
@@ -11,7 +12,26 @@ type Param struct {
1112
}
1213

1314
func (p Param) Render() huh.Field {
14-
input := p.Param.RenderInput()
15-
input.Password(true)
16-
return input
15+
param := p.Param.RenderInput()
16+
param.Password(true)
17+
18+
// reset validators of the secret
19+
var group []validators.Validator[string]
20+
if p.Required {
21+
group = append(group, validators.Required(p.Name, p.Trim))
22+
}
23+
if p.MinLength != nil {
24+
group = append(group, validators.MinLength(*p.MinLength))
25+
}
26+
if p.MaxLength != nil {
27+
group = append(group, validators.MaxLength(*p.MaxLength))
28+
}
29+
if p.Regex != "" {
30+
group = append(group, validators.RegexValidator(p.Regex, p.RegexMessage))
31+
}
32+
if len(group) > 0 {
33+
param.Validate(validators.Group(group...))
34+
}
35+
36+
return param
1737
}

internal/parameter/str/str.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Param struct {
1313
Required bool `yaml:"required" json:"required" mapstructure:"required"`
1414
FQDN bool `yaml:"fqdn" json:"fqdn" mapstructure:"fqdn"`
1515
IP bool `yaml:"ip" json:"ip" mapstructure:"ip"`
16-
Trim bool `yaml:"trim" json:"trim" mapstructure:"trim"`
16+
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"`
1919
RegexMessage string `yaml:"regex_message" json:"regex_message" mapstructure:"regex_message"`

0 commit comments

Comments
 (0)