-
Notifications
You must be signed in to change notification settings - Fork 3k
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
base: main
Are you sure you want to change the base?
Conversation
Hi! Just following up to see if there's anything I can improve in this PR 🙇 |
Hi maintainers 👋 |
flag_groups.go
Outdated
processFlagForGroupAnnotation(flags, pflag, oneRequiredAnnotation, oneRequiredGroupStatus) | ||
processFlagForGroupAnnotation(flags, pflag, mutuallyExclusiveAnnotation, mutuallyExclusiveGroupStatus) | ||
}) | ||
required, oneRequired, mutuallyExclusive := c.getFlagGroupStatuses() |
There was a problem hiding this comment.
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
Thank you for your feedback! I’ve updated the function to return a struct in order to make it clearer and more extensible.
|
Thank you for your feedback! |
Problem
Both the
ValidateFlagGroups
andenforceFlagGroupsForCompletion
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.