Skip to content

Commit 5c571dd

Browse files
committed
Make function a varadic
1 parent b1094fc commit 5c571dd

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

cli/clibase/values.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@ type Validator[T pflag.Value] struct {
2424
validate func(T) error
2525
}
2626

27-
func Validate[T pflag.Value](opt T, validate func(value T) error) *Validator[T] {
28-
return &Validator[T]{Value: opt, validate: validate}
27+
func Validate[T pflag.Value](opt T, validate ...func(value T) error) *Validator[T] {
28+
return &Validator[T]{Value: opt, validate: func(value T) error {
29+
// Run all validate functions
30+
for _, v := range validate {
31+
err := v(value)
32+
if err != nil {
33+
return err
34+
}
35+
}
36+
return nil
37+
}}
2938
}
3039

3140
func (i *Validator[T]) String() string {

enterprise/cli/workspaceproxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (r *RootCmd) createProxy() *clibase.Cmd {
236236
formatter = newUpdateProxyResponseFormatter()
237237
)
238238
validateIcon := func(s *clibase.String) error {
239-
if !(strings.HasPrefix(s.Value(), "/emojis/") || strings.HasPrefix(s, "http")) {
239+
if !(strings.HasPrefix(s.Value(), "/emojis/") || strings.HasPrefix(s.Value(), "http")) {
240240
return xerrors.New("icon must be a relative path to an emoji or a publicly hosted image URL")
241241
}
242242
return nil

0 commit comments

Comments
 (0)