diff --git a/storage.go b/storage.go index 36a17f2cd..082d986bf 100644 --- a/storage.go +++ b/storage.go @@ -140,13 +140,16 @@ func (s _storage) getPositional(cmd *cobra.Command, index int) Action { func (s _storage) check() []string { errors := make([]string, 0) for cmd, entry := range s { - entry.flagMutex.RLock() - for name := range entry.flag { - if flag := cmd.LocalFlags().Lookup(name); flag == nil { - errors = append(errors, fmt.Sprintf("unknown flag for %s: %s\n", uid.Command(cmd), name)) + func() { + entry.flagMutex.RLock() + defer entry.flagMutex.RUnlock() + + for name := range entry.flag { + if flag := cmd.LocalFlags().Lookup(name); flag == nil { + errors = append(errors, fmt.Sprintf("unknown flag for %s: %s\n", uid.Command(cmd), name)) + } } - } - entry.flagMutex.RUnlock() + }() } return errors }