Skip to content

Commit

Permalink
storage: use defer
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Sep 16, 2023
1 parent f3f8d72 commit fbb1cac
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fbb1cac

Please sign in to comment.