update checkRequiredFlags function to check RequiredFlagsErr field and return map of missing flag names with matching bool for RequiredFlagsErr value

This commit is contained in:
Aaron Berns 2019-08-20 10:03:29 -04:00
parent a064d9082c
commit addd467e5b

View File

@ -310,12 +310,16 @@ func (e *errRequiredFlags) getMissingFlags() []string {
} }
func checkRequiredFlags(flags []Flag, context *Context) requiredFlagsErr { func checkRequiredFlags(flags []Flag, context *Context) requiredFlagsErr {
var missingFlags []string missingFlags := make(map[string]bool)
for _, f := range flags { for _, f := range flags {
if rf, ok := f.(RequiredFlag); ok && rf.IsRequired() { if rf, ok := f.(RequiredFlag); ok && rf.IsRequired() {
key := strings.Split(f.GetName(), ",")[0] key := strings.Split(f.GetName(), ",")[0]
if !context.IsSet(key) { if !context.IsSet(key) {
missingFlags = append(missingFlags, key) if re, ok := f.(RequiredFlagsErr); ok && re.FlagsErrRequired() {
missingFlags[key] = true
} else {
missingFlags[key] = false
}
} }
} }
} }