-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparam.go
More file actions
50 lines (42 loc) · 1.39 KB
/
param.go
File metadata and controls
50 lines (42 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package parameter
import (
"fmt"
"github.com/charmbracelet/huh"
"github.com/shipengqi/golib/strutil"
"github.com/shipengqi/commitizen/internal/errorsx"
)
type Interface interface {
huh.Field
GetGroup() string
Render()
Validate() []error
}
type Parameter struct {
huh.Field `mapstructure:"-"`
Name string `yaml:"name" json:"name" mapstructure:"name"`
Group string `yaml:"group" json:"group" mapstructure:"group"`
Label string `yaml:"label" json:"label" mapstructure:"label"`
Description string `yaml:"description" json:"description" mapstructure:"description"`
Type string `yaml:"type" json:"type" mapstructure:"type"`
DependsOn DependsOn `yaml:"depends_on" json:"depends_on" mapstructure:"depends_on"`
}
func (p *Parameter) GetGroup() string {
return p.Group
}
func (p *Parameter) Render() {}
func (p *Parameter) Validate() []error {
var errs []error
if strutil.IsEmpty(p.Name) {
errs = append(errs, errorsx.NewMissingErr("parameter.name"))
}
if !regexName.MatchString(p.Name) {
errs = append(errs, fmt.Errorf("parameter.name '%s' must match the regex: ^[a-zA-Z0-9-_]{1,62}$", p.Name))
}
if strutil.IsEmpty(p.Label) {
errs = append(errs, errorsx.NewMissingErr("label", p.Name))
}
if strutil.IsEmpty(p.Type) {
errs = append(errs, errorsx.NewMissingErr("type", p.Name))
}
return errs
}