File tree Expand file tree Collapse file tree 4 files changed +25
-6
lines changed
Expand file tree Collapse file tree 4 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 11package config
22
33const DefaultCommitTemplate = `---
4- version: v2
54name: default
65default: true
76items:
Original file line number Diff line number Diff 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
1717func NewMissingErr (field string , name ... string ) error {
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package secret
22
33import (
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
1314func (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}
Original file line number Diff line number Diff 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"`
You can’t perform that action at this time.
0 commit comments