Skip to content

Conversation

suwakei
Copy link

@suwakei suwakei commented Jul 14, 2025

Problem

Both the ValidateFlagGroups and enforceFlagGroupsForCompletion functions currently contain duplicated logic for determining which flags have been set in each flag group.

Fix

This redundancy has been eliminated by extracting the shared logic into a helper function named getFlagGroupStatuses, improving maintainability and making future changes easier.

@CLAassistant
Copy link

CLAassistant commented Jul 14, 2025

CLA assistant check
All committers have signed the CLA.

@suwakei
Copy link
Author

suwakei commented Jul 16, 2025

Hi! Just following up to see if there's anything I can improve in this PR 🙇

@suwakei
Copy link
Author

suwakei commented Jul 29, 2025

Hi maintainers 👋
Just following up on this PR — happy to make any changes if needed. Please let me know if there's anything blocking review. Thanks!

flag_groups.go Outdated
processFlagForGroupAnnotation(flags, pflag, oneRequiredAnnotation, oneRequiredGroupStatus)
processFlagForGroupAnnotation(flags, pflag, mutuallyExclusiveAnnotation, mutuallyExclusiveGroupStatus)
})
required, oneRequired, mutuallyExclusive := c.getFlagGroupStatuses()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually when I see a function returning 3 values, I tend to recommend returning a struct with 3 fields. It often helps because more values can be returned easily, also you don't always need all values depending on where you call the function

@suwakei
Copy link
Author

suwakei commented Jul 29, 2025

Thank you for your feedback! I’ve updated the function to return a struct in order to make it clearer and more extensible.

  • Introduced FlagGroupStatuses struct
  • Updated getFlagGroupStatuses to return struct
  • Updated enforceFlagGroupsForCompletion accordingly

@suwakei
Copy link
Author

suwakei commented Aug 1, 2025

Thank you for your feedback!
Eliminated redundancies in flag_group.go

Copy link
Collaborator

@jharshman jharshman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍
If you wanted to add a test for the new method that would also be cool. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants