dmarkham / enumer

A Go tool to auto generate methods for your enums
Other
410 stars 66 forks source link

Enable interoperability with ent #50

Closed mvrahden closed 2 years ago

mvrahden commented 2 years ago

Hi, to improve interoperability with ent and support its enum type-safety, I'd propose to add the Values() []string method (from the EnumValues interface) to the generated enum types, next to String() string. This feature should likely be opt-in, so it would be beneficial to add a flag for it. I'd propose -values (or -valuesFunc) flag.

I've seen, there is already a generated ***Strings() []string-func, which would just need to be wrapped by the Values() []string method in question.

@dmarkham Would you be open for a PR for this?

An Example:

func (Pill) Values() []string {
  return PillStrings()
}

P.S.: I understand there's a potential for confusion, due to the pre-existing PillValues() []Pill function. But to have typesafety with enums in ent, this proposal is the only way to go from what I see.

mvrahden commented 2 years ago

Hi @dmarkham, would be nice to hear your opinion on this. Thanks :)

dmarkham commented 2 years ago

I think a new flag to add this method would be just fine.

mvrahden commented 2 years ago

great! I'll prepare a PR

On Thu, Oct 21, 2021 at 2:39 AM Dan Markham @.***> wrote:

I think a new flag yo add this method would be just fine.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dmarkham/enumer/issues/50#issuecomment-948139183, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGMIMCRBJPHMVN745QZTBJ3UH5OKXANCNFSM5GEW67FA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

mvrahden commented 2 years ago

@dmarkham please have a look at #51 thanks

mvrahden commented 2 years ago

@dmarkham Thanks for merging! Would you mind bumping the patch version?

mvrahden commented 2 years ago

@dmarkham pls bump version, so that the changes make it into the release. Thanks!