Skip to content

Commit 8823ff8

Browse files
committed
🔧 fix: updated the arg.testValue func to work correctly
1 parent 1a7fa48 commit 8823ff8

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

‎args.go‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ func (a *Argument) Required(val bool) *Argument {
115115
return a
116116
}
117117

118+
func (a *Argument) Type(val argumentType) *Argument {
119+
a.argType = val
120+
return a
121+
}
122+
118123
// Configures the valid values for an argument
119124
func (a *Argument) ValidateWith(vals []string) *Argument {
120125
a.validValues = vals
@@ -184,20 +189,28 @@ func (a *Argument) addValidatorFns() {
184189
}
185190

186191
func (a *Argument) testValue(val string) bool {
192+
valueMatch := false
193+
matchCount := 0
194+
195+
if len(a.validValues) == 0 {
196+
valueMatch = true
197+
}
198+
187199
for _, v := range a.validValues {
188200
if strings.EqualFold(v, val) {
189-
return true
201+
valueMatch = true
202+
break
190203
}
191204
}
192205

193206
for _, fn := range a.validatorFns {
194207
err := fn(val)
195208
if err == nil {
196-
return true
209+
matchCount++
197210
}
198211
}
199212

200-
return false
213+
return valueMatch && matchCount == len(a.validatorFns)
201214
}
202215

203216
func (a *Argument) hasDefaultValue() bool {

0 commit comments

Comments
 (0)