Skip to content

Elimination of duplication through common logic #2293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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

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.

3 participants