11package str
22
33import (
4+ "strings"
5+
46 "github.com/charmbracelet/huh"
57
68 "github.com/shipengqi/commitizen/internal/parameter"
@@ -13,18 +15,29 @@ type Param struct {
1315 Required bool `yaml:"required" json:"required" mapstructure:"required"`
1416 FQDN bool `yaml:"fqdn" json:"fqdn" mapstructure:"fqdn"`
1517 IP bool `yaml:"ip" json:"ip" mapstructure:"ip"`
16- Trim bool `yaml:"trim" json:"trim" mapstructure:"trim"` // Todo implement trim??
18+ Trim bool `yaml:"trim" json:"trim" mapstructure:"trim"`
1719 DefaultValue string `yaml:"default_value" json:"default_value" mapstructure:"default_value"`
1820 Regex string `yaml:"regex" json:"regex" mapstructure:"regex"`
1921 MinLength * int `yaml:"min_length" json:"min_length" mapstructure:"min_length"`
2022 MaxLength * int `yaml:"max_length" json:"max_length" mapstructure:"max_length"`
2123}
2224
23- func (p Param ) Render () huh.Field {
24- return p .RenderInput ()
25+ func (p * Param ) Render () {
26+ p .Field = p .RenderInput ()
27+ }
28+
29+ func (p * Param ) GetValue () any {
30+ if ! p .Trim {
31+ return p .Field .GetValue ()
32+ }
33+ val := p .Field .GetValue ()
34+ if str , ok := val .(string ); ok {
35+ return strings .TrimSpace (str )
36+ }
37+ return p .Field .GetValue ()
2538}
2639
27- func (p Param ) RenderInput () * huh.Input {
40+ func (p * Param ) RenderInput () * huh.Input {
2841 param := huh .NewInput ().Key (p .Name ).
2942 Title (p .Label )
3043
0 commit comments