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:
parent
a064d9082c
commit
addd467e5b
@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user