add ability to combine multiple error strings to Error() function
This commit is contained in:
parent
ed4ac1876d
commit
fffdd82c00
12
context.go
12
context.go
@ -308,12 +308,18 @@ func (e *errRequiredFlags) Error() string {
|
||||
}
|
||||
}
|
||||
|
||||
var allErrors []string
|
||||
numberOfMissingFlags := len(missingFlagNames)
|
||||
if numberOfMissingFlags == 1 {
|
||||
return fmt.Sprintf("Required flag %q not set", missingFlagNames[0])
|
||||
}
|
||||
allErrors = append(allErrors, fmt.Sprintf("Required flag %q not set", missingFlagNames[0]))
|
||||
} else {
|
||||
joinedMissingFlags := strings.Join(missingFlagNames, ", ")
|
||||
return fmt.Sprintf("Required flags %q not set", joinedMissingFlags)
|
||||
allErrors = append(allErrors, fmt.Sprintf("Required flags %q not set", joinedMissingFlags))
|
||||
}
|
||||
|
||||
// handle user defined errors and append
|
||||
|
||||
return strings.Join(allErrors, "\n")
|
||||
}
|
||||
|
||||
func (e *errRequiredFlags) getMissingFlags() map[string]bool {
|
||||
|
Loading…
Reference in New Issue
Block a user