alvaroloes / enumer

A Go tool to auto generate methods for your enums
Other
478 stars 111 forks source link

Add transform to MACRO_CASE and phrase #51

Open abemedia opened 5 years ago

abemedia commented 5 years ago

Added support for transforming to MACRO_CASE and phrase.

1. phrase

We have a concrete use-case for phrase, which is using enumer to generate errors:

//go:generate enumer -type=ErrorCode -transform=phrase --trimprefix=Err

type ErrorCode int

func (e ErrorCode) Error() string {
    return e.String()
}

const (
    ErrInsufficientBalance ErrorCode = iota
    ErrInvalidNumberOfArguments
)

This means we can directly use these error constants as a normal error i.e.

ErrInvalidNumberOfArguments.Error() == "invalid number of arguments"

2. macro

MACRO_CASE as it's the most wide-spread form of defining constants (JS/Node, Ruby, Python, Bash) and makes sense for us as this is how we define them on our React front-end.

abemedia commented 5 years ago

Shameless bump

chickenandpork commented 3 years ago

Shameless re-bump

chickenandpork commented 3 years ago

Is this met for you by @niktri's fork, Enumerx, release v1.1.5 ?

https://github.com/niktri/enumerx/commit/712e0f2655c1d8b4ba84712606e4cf74ad641c50

(transform=snake_upper)

abemedia commented 3 years ago

To be honest I've been using my own fork that this PR is coming from: https://github.com/abeMedia/enumer Would love to get this merged though!